Multi-Terraform Project Repo Pipeline

I have a project with multiple folders of terraform code. Each folder represents a unique application. I’d like to setup my pipeline to have one set of tasks that I can pull into the pipeline for each folder. The only unique part is changing the $TF_ROOT before running the steps.

I tried using the include: with variables, but that seems to have failed. Is there some other means of doing this?

include:
  - project: 'group/project'
    ref: main
    file: 'templates/terraform-pipeline.yml'
    variables:
      TF_ROOT: "${CI_PROJECT_DIR}/my-app-1"
  - project: 'group/project'
    ref: main
    file: 'templates/terraform-pipeline.yml'
    variables:
      TF_ROOT: "${CI_PROJECT_DIR}/my-app-2"

Hi @josiahritchie

you can define a template job in your group/project/templates/terraform-pipeline.yml and then use it to extend jobs defined in .gitlab-ci.yml

Let’s say your terraform-pipeline.yml defines a job called .my_terraform_job

include:
  - project: 'group/project'
    ref: main
    file: 'templates/terraform-pipeline.yml'

my-app-1:
  extends: ['.my_terraform_job']
  variables:
    TF_ROOT: "${CI_PROJECT_DIR}/my-app-1"

...

So, not possible for this variable to be applied to a group of jobs all at once?

Nope, what you are trying to do is not possible. There is no include.variables option.

Variables are either defined for all jobs with global variables keyword or per job.