Skip to content

Commit

Permalink
Update terraform action
Browse files Browse the repository at this point in the history
  • Loading branch information
ikambarov committed Feb 5, 2022
1 parent 24c5e7c commit b26d35c
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions Aug-2021/terraform-vpc.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
properties([
parameters([
choice(choices: ['dev', 'qa', 'prod'], description: 'Choose environment', name: 'environment')
choice(choices: ['dev', 'qa', 'prod'], description: 'Choose environment', name: 'environment'),
choice(choices: ['plan', 'apply', 'destroy'], description: 'Choose Terraform Action', name: 'terraformaction')
])
])

Expand Down Expand Up @@ -31,14 +32,24 @@ node('terraform'){
terraform init
"""
}

stage("Terraform Plan"){
sh "terraform plan -var-file ${params.environment}.tfvars"
}

if( params.terraformaction == "plan" ){
stage("Terraform Plan"){
sh "terraform plan -var-file ${params.environment}.tfvars"
}
}

stage("Terraform Apply"){
sh "terraform apply -var-file ${params.environment}.tfvars -auto-approve"
if( params.terraformaction == "apply" ){
stage("Terraform Apply"){
sh "terraform apply -var-file ${params.environment}.tfvars -auto-approve"
}
}

if( params.terraformaction == "destroy" ){
stage("Terraform Destroy"){
sh "terraform destroy -var-file ${params.environment}.tfvars -auto-approve"
}
}
}
}
Expand Down

0 comments on commit b26d35c

Please sign in to comment.