admin管理员组文章数量:1122846
I want to use terraform plan and terraform apply in different stage, so I use artifacts I build my own docker image with teraform cli.
the structure of my folder
.gitlab-ci.yaml
terraform/main.tf
terrfaorm/variable.tf
$ cat .gitlab-ci.yaml
image: docker_image:0.0
variables:
PLAN: tfplan
TF_IN_AUTOMATION: "true"
.terraform-init: &terraform-init
- terraform -chdir=terraform init -upgrade -backend-config="XX"
stages:
- validate
- plan
- apply
validate:
stage: validate
before_script:
- *terraform-init
script:
- terraform -chdir=terraform validate
plan:
stage: plan
before_script:
- *terraform-init
- terraform -chdir=terraform plan -out $PLAN
artifacts:
paths:
- $PLAN
apply:
stage: apply
before_script:
- *terraform-init
script:
- terraform -chdir=terraform apply -input=false -lock=false -auto-approve $PLAN
dependencies:
- plan
when: manual
I have got this error
Error: Failed to load "tfplan" as a plan file Error: state tfplan: no such ile or directory
I try to looking for with ls command, but I don't find it on stage apply
I want to use terraform plan and terraform apply in different stage, so I use artifacts I build my own docker image with teraform cli.
the structure of my folder
.gitlab-ci.yaml
terraform/main.tf
terrfaorm/variable.tf
$ cat .gitlab-ci.yaml
image: docker_image:0.0
variables:
PLAN: tfplan
TF_IN_AUTOMATION: "true"
.terraform-init: &terraform-init
- terraform -chdir=terraform init -upgrade -backend-config="XX"
stages:
- validate
- plan
- apply
validate:
stage: validate
before_script:
- *terraform-init
script:
- terraform -chdir=terraform validate
plan:
stage: plan
before_script:
- *terraform-init
- terraform -chdir=terraform plan -out $PLAN
artifacts:
paths:
- $PLAN
apply:
stage: apply
before_script:
- *terraform-init
script:
- terraform -chdir=terraform apply -input=false -lock=false -auto-approve $PLAN
dependencies:
- plan
when: manual
I have got this error
Error: Failed to load "tfplan" as a plan file Error: state tfplan: no such ile or directory
I try to looking for with ls command, but I don't find it on stage apply
Share Improve this question asked Nov 21, 2024 at 16:09 khaled lhalekhaled lhale 273 bronze badges1 Answer
Reset to default 0You correctly determined that the plan file needs to be preserved between stages in the containerized agent, but the parameter values are slightly incorrect due to use of the chdir
flag:
plan:
stage: plan
before_script:
- *terraform-init
- terraform -chdir=terraform plan -out $PLAN
artifacts:
paths:
- "terraform/${PLAN}"
本文标签: Gitlab CI Terraform use plan and apply in diferent stageStack Overflow
版权声明:本文标题:Gitlab CI Terraform use plan and apply in diferent stage - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309041a1933876.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论