0% found this document useful (0 votes)
246 views7 pages

CICD Jenkins Terraform Automation

This document outlines the steps to set up continuous integration and continuous delivery (CI/CD) of infrastructure as code (IAC) using Jenkins, Terraform, and GitHub. The process involves: 1. Setting up a GitHub webhook in the GitHub repository to trigger Jenkins builds on commits 2. Creating a Jenkins pipeline job and configuring the GitHub webhook trigger 3. Writing a Jenkins pipeline script to check out the Git code, run Terraform init, plan, and apply steps 4. Assigning an IAM role to the Jenkins server to allow Terraform to provision AWS infrastructure.

Uploaded by

Nirajan Shrestha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
246 views7 pages

CICD Jenkins Terraform Automation

This document outlines the steps to set up continuous integration and continuous delivery (CI/CD) of infrastructure as code (IAC) using Jenkins, Terraform, and GitHub. The process involves: 1. Setting up a GitHub webhook in the GitHub repository to trigger Jenkins builds on commits 2. Creating a Jenkins pipeline job and configuring the GitHub webhook trigger 3. Writing a Jenkins pipeline script to check out the Git code, run Terraform init, plan, and apply steps 4. Assigning an IAM role to the Jenkins server to allow Terraform to provision AWS infrastructure.

Uploaded by

Nirajan Shrestha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CI/CD Jenkins Terraform Automation| Writing IAC and Jenkins groovy

3. setup webhook

step:

a. copy the Jenkins url

b. paste the Jenkins url into github project repository  webhook inside webhook click add
webhook

c. inside add webhook


paste the Jenkins url with extra line (github-webhook/)
content type : application/json
d. for secrets go to Jenkins  Dashboard userprofileconfigureAPI token add new token
and generate new token
e. click on ok , once you click on ok the following page will display

4. create a pipeline
steps
go to Jenkins New items
give any name and select pipeline and click ok
after that inside the project in built trigger select Github hook trigger for GITScm pooling

write a pipeline script as follows

 to generate the pipeline syntax go to pipeline syntax


 copy the url of the git hub repository
 search for git in sample steps, paste url of git repository into repository url and Branch :
main (only if it is in the master branch)
 right now I am using the public repo I need not to pass the credentials other wise I have to
pass credentials of git hub it was private

 now click on the cenerate pipeline script and copy it and paste it into the pipeline script
 for terraform init, plan and apply shell script go to pipeline syntax sample step:sh:shell
script, Shell script: terraform init and generate pipeline script

 now copy the shell script and paste it into the pipeline script unter terraform init, repeat this
step for terraform plan and terraform apply

 apply and save it and Built now


pipeline{
agent any
stages{
stage('git checkout')(
steps{
git branch: 'main', url:
'https://github.com/vikash-kumar01/terraform_lab.git'
}
}
stage('terraform init'){
steps{
sh 'terraform init'
}
}
stage('terraform plan'){
steps{
sh 'terraform plan'
}
}
stage('terraform apply'){
steps{
sh 'terraform apply –auto-approve'
}
}

}
 create role in your aws and give permission of administration access

 now the role has been created and you need to assign it to the Jenkins server so for this
go to ec2 instance  select the Jenkins server go to actiongo to securitymodify iam
role and select the IAM role from the drop down section
 now if you go to the vs code and make change in the terraform code and commit to the git
hub it will automatically trigger the build and automation is complete

You might also like