在 Jenkins 管道中使用 Terraform 命令
Using Terraform commands in JenkinsPipeline
我对 terraform 的东西很陌生,目前正在 JenkinsPipeline 上 运行ning terraform 脚本上工作。我有每个区域的一些 .tfvars
文件,例如 tf-de-sandbox.tfvars, tf-fr-sandbox.tfvars, tf-de-prod.tfvars, tf-fr-prod.tfvars
。我正在尝试通过 JenkinsPipeline 运行 plan
和 apply
命令。无论如何,我正在寻找的是在那里我可以 运行 并行沙箱文件和并行生产文件。例如,我可以在使用 plan
命令时提供多个 tfvars 文件吗?
Terraform plan -var-file=[tf-de-sandbox.tfvars,tf-fr-sandbox.tfvars]
或类似的东西,然后使用 apply
命令?
我的 JenkinsPipeline 看起来像这样。
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'
}
}
}
是的,你可以。例如:
terraform plan --var-file=dev.tfvars --var-file=common.tfvars --out=planoutput
然后,申请:
terraform apply planoutput
我对 terraform 的东西很陌生,目前正在 JenkinsPipeline 上 运行ning terraform 脚本上工作。我有每个区域的一些 .tfvars
文件,例如 tf-de-sandbox.tfvars, tf-fr-sandbox.tfvars, tf-de-prod.tfvars, tf-fr-prod.tfvars
。我正在尝试通过 JenkinsPipeline 运行 plan
和 apply
命令。无论如何,我正在寻找的是在那里我可以 运行 并行沙箱文件和并行生产文件。例如,我可以在使用 plan
命令时提供多个 tfvars 文件吗?
Terraform plan -var-file=[tf-de-sandbox.tfvars,tf-fr-sandbox.tfvars]
或类似的东西,然后使用 apply
命令?
我的 JenkinsPipeline 看起来像这样。
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'
}
}
}
是的,你可以。例如:
terraform plan --var-file=dev.tfvars --var-file=common.tfvars --out=planoutput
然后,申请:
terraform apply planoutput