Using this pipeline and setting one runner for all jobs and a global cache to share .terraform folder across multiple envs I expected that .terrafrom folder will be shared among all jobs but I see that it first removes .terraform.lock.hcl, .terraform and plan.cache and then restores the cache, why?
image: registry.gitlab.com/gitlab-org/terraform-images/releases/1.3:latest
default:
tags:
- docker
variables:
TF_ROOT: ${CI_PROJECT_DIR}
before_script:
- terraform --version
- cd ${TF_ROOT}
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
- ${TF_ROOT}/.terraform/
stages:
- validate
- build
- apply
- destroy
.validate-base:
stage: validate
script:
- gitlab-terraform validate
.terraform:plan:
stage: build
script:
- gitlab-terraform plan -var-file ${TF_STATE_NAME}.tfvars
artifacts:
paths:
- ${TF_ROOT}/plan.cache
name: ${TF_STATE_NAME}
resource_group: ${TF_STATE_NAME}
when: manual
.terraform:apply:
stage: apply
script:
- gitlab-terraform apply
resource_group: ${TF_STATE_NAME}
when: manual
.terraform:destroy:
stage: destroy
script:
- gitlab-terraform destroy -var-file ${TF_STATE_NAME}.tfvars
resource_group: ${TF_STATE_NAME}
when: manual
.environment:sandbox:
variables:
TF_STATE_NAME: sandbox
.environment:dev:
variables:
TF_STATE_NAME: dev
.environment:production:
variables:
TF_STATE_NAME: production
only:
- tags
validate-sandbox:
extends:
- .validate-base
- .environment:sandbox
plan-sandbox:
extends:
- .terraform:plan
- .environment:sandbox
needs: [validate-sandbox]
apply-sandbox:
extends:
- .terraform:apply
- .environment:sandbox
needs: [plan-sandbox]
destroy-sandbox:
extends:
- .terraform:destroy
- .environment:sandbox
plan-dev:
extends:
- .terraform:plan
- .environment:dev
needs: [validate-sandbox]
apply-dev:
extends:
- .terraform:apply
- .environment:dev
needs: [plan-dev]
destroy-dev:
extends:
- .terraform:destroy
- .environment:dev
plan-prod:
extends:
- .terraform:plan
- .environment:production
needs: [validate-sandbox]
apply-prod:
extends:
- .terraform:apply
- .environment:production
needs: [plan-prod]
destroy-prod:
extends:
- .terraform:destroy
- .environment:production