Managing multiple environments with Terraform and GitLab CI

New blog post on the GitLab blog by Noah Ing, Sophia Manicor! Check it out here:

This is an interesting article it helped me to start, but the solution described is not going to work. The root .gitlab-ci.yml includes individual environment .gitlab-ci.yml files each has the same definition of the variables. The last included file will overwrite the variables so all environments before the last will never work. I added variable definitions with if condition for an environment name into helper.yaml instead.

  • |
    if [ “$CI_ENVIRONMENT_NAME” == “dev” ]; then
    TF_ENV=“dev”
    elif [ “$CI_ENVIRONMENT_NAME” == “pprd” ]; then
    TF_ENV=“preprod”
    elif [ “$CI_ENVIRONMENT_NAME” == “prod” ]; then
    TF_ENV=“production”
    fi