I have a huge .gitlab-ci.yml file that I am trying to turn into the "main" ci file by moving some parts to another files which will then be called with the use of the "include" keyword.
.gitlab-ci.yml file:
image: golang:latest
stages:
- validate
include: /.gitlab/ci/_common.gitlab-ci.yml
validate:
stage: validate
extends: .gitlab-tf-backend
before_script:
- cd ${TF_ROOT}
- terraform init -backend=false
- mv $CI_PROJECT_DIR/deployment.zip .
script:
- terraform validate
- terraform fmt -check=true
only:
- branches
.gitlab/ci/_common.gitlab-ci.yml file:
variables:
GITLAB_API_ENDPOINT: https://gitlab.com/api/v4
TF_ROOT: ${CI_PROJECT_DIR}/terraform
PLAN: plan.tfplan
JSON_PLAN_FILE: tfplan.json
GIT_DEPTH: 10
.gitlab-tf-backend: &gitlab-tf-backend
- export TF_ADDRESS=${GITLAB_API_ENDPOINT}/projects/${CI_PROJECT_ID}/terraform/state/${STATE_NAME}
- export TF_HTTP_ADDRESS=${TF_ADDRESS}
- export TF_HTTP_LOCK_ADDRESS=${TF_ADDRESS}/lock
- export TF_HTTP_LOCK_METHOD=POST
- export TF_HTTP_UNLOCK_ADDRESS=${TF_ADDRESS}/lock
- export TF_HTTP_UNLOCK_METHOD=DELETE
- export TF_HTTP_USERNAME=${USERNAME}
- export TF_HTTP_PASSWORD=${GITLAB_TOKEN}
- export TF_HTTP_RETRY_WAIT_MIN=5
- echo "Using HTTP Backend at $TF_HTTP_ADDRESS"
- terraform --version
- terraform init
My file is correctly found by gitlab. It seems that my hidden job ".gitlab-tf-backend" is not recognized and cannot be called.
Full error is:
This GitLab CI configuration is invalid: validate: invalid base hashes in `extends` (.gitlab-tf-backend)
How could I properly call my '.gitlab-tf-backend' hidden job from my main .gitlab-ci.yml file ?