Before_script not run when includes are used

Hi,

i have a .gitlab-ci.yml where i want to use inlcude to move some stuff into external files
I did that already with the before_script part, as you can see below, and everything is working fine.

But now i moved the terraform-plan and terraform-apply parts into an external file and the pipeline seems to ignore the before_script which causes the terraform stages to fail because settings/variables are missing

 variables:
      DOCKER_DRIVER: overlay
      DOCKER_HOST: tcp://localhost:2375
      KUBECONFIG: /etc/deploy/config

    image: docker:latest
    services:
    - docker:dind

    stages:
      - terraform-plan
      - terraform-apply
      - deploy

    #before_script
    include: '/environments/before_script.yml'

    # terraform_plan + apply
    terraform_plan:
      environment:
        name: $CLUSTER_ENV
      stage: terraform-plan
      resource_group: terraform
      image: ersitzt/helm-docker:latest
      script:
        - terraform plan -out=plan.tfplan
      rules:
        - if: $CI_MERGE_REQUEST_ID
          changes:
          - rancher/**/*
          when: always
        - when: never
      tags:
        - k8s-cluster-deployment

    terraform_apply:
      stage: terraform-apply
      resource_group: terraform
      image: ersitzt/helm-docker:latest
      environment:
        name: $CLUSTER_ENV
      script:
        - terraform apply -input=false plan.tfplan
      rules:
        - if: $CI_MERGE_REQUEST_ID
          changes: 
          - rancher/**/*
          when: manual
        - when: never
      tags:
        - k8s-cluster-deployment

After putting terraform in a extra file

 variables:
      DOCKER_DRIVER: overlay
      DOCKER_HOST: tcp://localhost:2375
      KUBECONFIG: /etc/deploy/config

    image: docker:latest
    services:
    - docker:dind

    stages:
      - terraform-plan
      - terraform-apply
      - deploy

    #before_script
    include: '/environments/before_script.yml'

    #terraform
    include: '/environments/terraform/terraform.yml'

How i understand the documentation all includes are evaluated before the pipeline runs… so there should be no difference between those files ???

This is the result using the both files via include
The script part is from the terraform part (the scripts i posted are thinned out to be more readable btw)

And this is the correct behavior

Its not terraform specific btw. as there are other stages in that yml which have the same problem as soon as i move the terraform stages to an external file

Have a similar problem. It seems before_script and script sections are not merged but overridden so that the last one of each is the only one that works.

What I read in their documentation is that they should be merged but that obviously isn’t working.