0% found this document useful (0 votes)
213 views13 pages

Terraform Running Using Jenkins CI-CD Pipeline

The document provides steps to install Terraform on a Linux server. It involves downloading the Terraform zip file from the official website, unzipping it, moving the Terraform executable to /usr/bin, and configuring it as a global tool in Jenkins. It then shows how to create a Jenkins pipeline job that uses the installed Terraform to perform operations like Git checkout, Terraform init, and Terraform apply on an infrastructure code repository.

Uploaded by

maruthi prasad
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)
213 views13 pages

Terraform Running Using Jenkins CI-CD Pipeline

The document provides steps to install Terraform on a Linux server. It involves downloading the Terraform zip file from the official website, unzipping it, moving the Terraform executable to /usr/bin, and configuring it as a global tool in Jenkins. It then shows how to create a Jenkins pipeline job that uses the installed Terraform to perform operations like Git checkout, Terraform init, and Terraform apply on an infrastructure code repository.

Uploaded by

maruthi prasad
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/ 13

Install terraform in liux server

Logon linux server and download form terraform.io/downloads.html

First we need to install git on linux server

Yum install git -y

Step1:

Run command wget https://releases.hashicorp.com/terraform/1.0.8/terraform_1.0.8_linux_amd64.zip

[root@localhost ~]# wget https://releases.hashicorp.com/terraform/1.0.8/terraform_1.0.8_linux_amd64.zip

--2021-09-30 07:13:16-- https://releases.hashicorp.com/terraform/1.0.8/terraform_1.0.8_linux_amd64.zip

Resolving releases.hashicorp.com (releases.hashicorp.com)... 199.232.253.183, 2a04:4e42:fd3::439

Connecting to releases.hashicorp.com (releases.hashicorp.com)|199.232.253.183|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 32681118 (31M) [application/zip]

Saving to: ‘terraform_1.0.8_linux_amd64.zip’

terraform_1.0.8_linux_amd64.zip 100%[======================================================>] 31.17M


28.0MB/s in 1.1s

2021-09-30 07:13:18 (28.0 MB/s) - ‘terraform_1.0.8_linux_amd64.zip’ saved [32681118/32681118]

[root@localhost ~]#

Step2:

Unzip the downloaded terraform_1.0.8_linux_amd64.zip’ saved [32681118/32681118]

Run command unzip terraform_1.0.8_linux_amd64.zip

[root@localhost ~]# unzip terraform_1.0.8_linux_amd64.zip

Archive: terraform_1.0.8_linux_amd64.zip

inflating: terraform

[root@localhost ~]#

Step3:

We got terraform excutable

We need move the terraform to usr/bin

[root@localhost ~]# mv terraform /usr/bin

[root@localhost ~]# which terraform


/usr/bin/terraform

[root@localhost ~]#

[root@localhost ~]# terraform --version

Terraform v1.0.8

on linux_amd64

Step4:

Go to jenkin console click on Manage Jenkins

Click Manage Plugins

Click on available and search button type terraform and github integration ticket click on installwithout restart
Step5:

Go back jenkin console click on manage Jenkins Global tool configuration

Goto terraform click on Add terraform


Type name as terraform then untick install automatically

Give the /usr/bin which we was installed Step 1,2 and 3 than save

Step6:

Now create Jenkin job click on New Item


Type name  click on pipeline ok

Click on pipeline

Type

pipeline{

agent any

}
Now I am adding the terraform into pipeline script click on Pipeline Syntax

Click on Declarative Directive Generator Sample Directive select the tools

Click on Add select terraform: Terraform


Click on Generator Declarative Directive and copy the pipeline script

Copy the above pipeline script and paste in pipeline. I moved the terraform 'terraform' and }

Kindly refer below screenshot


Now I am creating stages with stage for Git checkout

Open pipeline syntax from pipeline job  snippet Generator Sample Step git:GitGet github url from ur github and
paste in Repository URL-branch is main-clcik on Add Jenkins (add your github login password)click on credential it will
show your github login password select the login—click on Generate pipeline script

My github url: n https://github.com/maruthipp009/EKS


Copy the generated pipeline script and paste in your pipeline job. Refer below screenshot

Now I am going add the stage2 terraform init command. First stage then steps

Stage("Terraform Init”){

Steps{

Go to pipeline syntax in pipeline job

Click on snippet generator sample steps select sh:Shell Script it open shell script type your command is terraform init
 Generate pipeline script copy the pipeline script generate for Terraform init paste in pipeline job
I am creating another 3rs stage step for terraform apply auto approve
Click on snippet generator sample steps select sh:Shell Script it open shell script type your command is terraform
apply --auto-approve  Generate pipeline script copy the pipeline script generate for terraform apply --auto-approve
paste in pipeline jobsave and apply

Go back to Jenkin Dashboard  click on your pipeline project click on build now check the status

You might also like