JenkinsTerraform

Integrate Terraform with Jenkins

In this blog, we will Integrate Terraform with Jenkins

First you need to install plugin

Go to Manage Jenkins — Install Plugin — Terraform

Now configure Terraform

Manage Jenkins ->Global Tool Configuration

To store AWS Secret Key

Manage Jenkins -> Configure System -> Set environment variable

Now create a pipeline job

pipeline {
 agent any
 
 stages {
 stage(‘checkout’) {
 steps {
 git branch: ‘develop’, url: ‘git@your url’
 
 }
 }
 stage(‘Set Terraform path’) {
 steps {
 script {
 def tfHome = tool name: ‘Terraform’
 env.PATH = “${tfHome}:${env.PATH}”
 }
 sh ‘terraform — version’
 
 
 }
 }
 
 stage(‘Provision infrastructure’) {
 
 steps {
 dir(‘dev’)
 {
 sh ‘terraform init’
 sh ‘terraform plan -out=plan’
 // sh ‘terraform destroy -auto-approve’
 sh ‘terraform apply plan’
 }
 
 
 }
 }
 
 
 
 }
}
Please follow and like us: