I am very new to terraform stuff and currently working on running terraform scripts on JenkinsPipeline. I have some .tfvars
file for each region for example tf-de-sandbox.tfvars, tf-fr-sandbox.tfvars, tf-de-prod.tfvars, tf-fr-prod.tfvars
. I am trying to run plan
and apply
commands through JenkinsPipeline. What I am looking for is there anyway where I can run both sandbox files in parallel and prod files in parallel. Forexample can I give multiple tfvars file while using plan
command?
Terraform plan -var-file=[tf-de-sandbox.tfvars,tf-fr-sandbox.tfvars]
or something like this and then use apply
command?
My JenkinsPipeline looks like this.
pipeline {
agent none
triggers {
cron('0 9 * * *') //schedule your build every day at 9h 00
}
stages {
stage('Pre-deploy stacks') {
agent { node { label 'deploy-python36' } }
steps {
sh 'cf sync --confirm cfn/stacks.yml'
sh 'curl https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo | tee /etc/yum.repos.d/hashicorp.repo && yum install terraform -y'
}
}
stage('TF Initialization') {
agent { node { label 'deploy-python36' } }
steps {
dir('./tf') {
sh 'terraform init'
}
}
}
stage('TF/DE planning [box]') {
agent { node { label 'deploy-python36' } }
steps {
dir('./tf') {
sh 'terraform plan -var-file=conf/tf-de-sandbox.tfvars'
}
}
}
CodePudding user response:
Yes, you can. For example:
terraform plan --var-file=dev.tfvars --var-file=common.tfvars --out=planoutput
And then, to apply:
terraform apply planoutput