Answers: <p>Okay, found it.</p>
  <p>It seems the .gitlab-ci.yml hidden job needs to have a &quot;script:&quot; to solve the problem. See below:</p>
  <pre><code>.gitlab-tf-backend: &amp;gitlab-tf-backend
        script:
         - 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 &quot;Using HTTP Backend at $TF_HTTP_ADDRESS&quot;
         - terraform --version
         - terraform init
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2020-11-17T18:42:59.973Z
Answers: 2020-11-17T18:42:59.973Z
Answers: alban boitier
Body: <p>I have a huge .gitlab-ci.yml file that I am trying to turn into the &quot;main&quot; ci file by moving some parts to another files which will then be called with the use of the &quot;include&quot; keyword.</p>
  <p>.gitlab-ci.yml file:</p>
  <pre><code>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
  </code></pre>
  <p>.gitlab/ci/_common.gitlab-ci.yml file:</p>
  <pre><code>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: &amp;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 &quot;Using HTTP Backend at $TF_HTTP_ADDRESS&quot;
     - terraform --version
     - terraform init
  </code></pre>
  <p>My file is correctly found by gitlab. It seems that my hidden job &quot;.gitlab-tf-backend&quot; is not recognized and cannot be called.</p>
  <p>Full error is:</p>
  <pre><code>This GitLab CI configuration is invalid: validate: invalid base hashes in `extends` (.gitlab-tf-backend)
  </code></pre>
  <p>How could I properly call my '.gitlab-tf-backend' hidden job from my main .gitlab-ci.yml file ?</p>
  
Comments: CC BY-SA 4.0
Comments: 2020-12-02T15:40:16.410Z
Comments: You're mixing YAML anchors and extend keyword, what you do would be of if your main script was including the hidden job with `script:\n<<: &gitlab-tf-backend. Now, make yourself a favor and use the gitlab-terraform image which takes care of all that for you. See [gitlab documentation](https://docs.gitlab.com/ee/user/infrastructure/terraform_state.html#get-started-using-gitlab-ci) for more details
Comments: Tensibai
Tags: <continuous-integration><gitlab><yaml>
Title: invalid base hashes in `extends` with 'include' -- gitlab-ci
UserDisplayName: alban boitier
ThreadText: # invalid base hashes in `extends` with 'include' -- gitlab-ci
  
  (Asked by: username_0 on 2020-11-17)
  
  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 ?
  
  **Tags:** continuous-integration, gitlab, yaml
  
  > **Comments:**
  > **username_1**: You're mixing YAML anchors and extend keyword, what you do would be of if your main script was including the hidden job with `script:\n<<: &gitlab-tf-backend. Now, make yourself a favor and use the gitlab-terraform image which takes care of all that for you. See [gitlab documentation](https://docs.gitlab.com/ee/user/infrastructure/terraform_state.html#get-started-using-gitlab-ci) for more details  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-11-17. Score: 2
  
  Okay, found it.
  
  It seems the .gitlab-ci.yml hidden job needs to have a "script:" to solve the problem. See below:
  
  ```
  .gitlab-tf-backend: &gitlab-tf-backend
        script:
         - 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
  
  ```
  
  
  ---
  
  