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:GitGet 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 jobsave and apply
Go back to Jenkin Dashboard click on your pipeline project click on build now check the status