Hi, I’m using GitLab Enterprise Edition 14.0.12-ee and I’m trying to set a tf plan pipeline across several stacks with shared dynamodb_table state lock on AWS. It looks something like:
image:
name: hashicorp/terraform:latest
entrypoint: [""]
stages:
- plan
include:
- local: terraform.gitlab-ci.yml
- local: stacks/cen/01-foo/.gitlab-ci.yml
- local: stacks/cen/02-bar/.gitlab-ci.yml
terraform.gitlab-ci.yml looks like:
.terraform:plan: &terraform_plan
stage: plan
before_script:
- cd "${TF_STACK}"
- terraform fmt
- terraform init
- terraform validate
script:
- terraform plan
only:
changes:
- "${TF_STACK}/*"
stacks/cen/{01-foo,02-bar}.gitlab-ci.yml are intended to be as minimal as possible and look very similar except for TF_STACK, something like:
variables:
TF_STACK: stacks/cen/02-bar
plan:${TF_STACK}:
extends: .terraform:plan
needs: []
-
Problem is that if the stages run at the same time, one will inevitably fail with a state lock issue! Terraform plan should not lock state files by default since it no longer writes changes to state · Issue #28130 · hashicorp/terraform · GitHub How do I make the plan in each stack run sequentially? Or better still make terraform ignore the lock?
-
It’s hard to know which plan is running, I try to name the stage with plan:${TF_STACK} but that doesn’t work. Is there another way?