The pipeline to deploy and push to GitHub with Slack integration is all about automating your infrastructure deployment process using Terraform, ensuring your configurations are consistently and efficiently applied. Additionally, it integrates with Slack to send you notifications about the status of your deployments, keeping you updated in real-time.
Key Points:
Automation: Automatically deploys infrastructure using Terraform when changes are pushed to your GitHub repository.
Version Control: Stores your infrastructure code in GitHub, allowing you to track changes, collaborate, and maintain version history.
Notifications: Sends Slack notifications to inform you of the deployment status, helping you stay informed about the success or failure of the deployment.
This approach enhances efficiency, collaboration, and transparency in managing your cloud infrastructure.
Create a repository on github
Create a token
Follow these steps to create a token:
Go to your profile,click on settings
scroll down to Developer settings.
Click on Personal access tokens,and select Token Classic and generate.
Follow these command line on your vscode:
git init
git commit -m "azure resource-grp added"
git branch -M main
git remote add origin https://github.com/CodeWithChidinma/CodeWithChidinma.git
git push -u origin main
And now the command has been successfully deployed on Github Repository.
PREPARING AND ADDING THE PIPELINE CODE
Click on Action and select terraform for this deployment.
Go to your vscode and create a folder called “ github “ and “ workflow “
Then create a file under workflow called CICD.yml
Copy the template and paste on vscode.
Edit your template and create a variable by copying the “ TF_APT_TOKEN “
Go back to your repo and click on settings.
Click on secret and variable and choose Action.
When asked secret or variables,you select secret and create new repository secret.
And then you paste the name variable “ TF_API_TOKEN “
Go to your Terraform Cloud Account and generate a token.
And create.
Go back to your vscode and type these commands to push:
git add .
git commit -m ‘added pipeline code’
git push
Go to your repository,and click on Action to refresh.
your pipeline code is successfully deployed on github.
Click on the pipeline code to check if your terraform init and plan has been successfully initialized.
Go back to your vscode and type these commands to apply:
git add .
git commit -m ‘added terraform apply’
git push.
Go to your repository,and click on Action to refresh.
your terraform apply is successfully deployed on github
Go to Terraform Cloud Account,check the workspace you created to see if it was successful.
NEXT:
CONFIGURING NOTIFICATION—INTEGRATING SLACK.
On your browser,type ‘ github market place’
Search for slack on the search bar and select ‘slack - GitHub Actions Slack integration’
create
SLACK_WEBHOOK
.Create a channel on slack,e.g gitaction_pipeline_alert_status
Go to ‘api.slack.com’ and click on your apps
Click on create a new app from scratch aswell.
input name,e.g gitaction_slack_app and input workspace.
Click on ‘incoming webhook’ and activate..and add new webhook workspace.
Choose the channel you created so as to synchronize.
And now you can access your webhook url,copy the url.
Name:
SLACK_WEBHOOK_URL
Go to your github repository and paste the webhook url on the secret option,to create a token.
Copy the enviromental variable and paste on vscode.
Go to github market place,where we get the information for our code,copy the steps and paste on vscode,so as to notify slack.
Then follow these commands to apply:
git add .
git commit -m ‘added terraform apply’
git push.
This is an indication that the pipeline has started.
- Go to github market place and copy the command and paste on vscode,which should be at the end of the pipeline.
git add .
git commit -m ‘added terraform apply’
git push.
Successful!!
This CI/CD pipeline uses GitHub Actions to automate the deployment of infrastructure with Terraform. It includes steps to check out code, set up Terraform, run Terraform commands to plan and apply changes, and commit and push changes back to the GitHub repository. Additionally, the pipeline integrates Slack notifications to inform you of the status of the deployment, ensuring you stay updated on the progress and any issues that might arise. This streamlined process helps maintain consistency, enhance collaboration, and improve efficiency in managing your cloud infrastructure.