0

I have a couple apps that use the same GCP project. There are dev, stage, and prod projects, but they're basically the same, apart from project IDs and project numbers. I would like to have a repo in gitlab like config where I keep these IDs, in a dev.tfvars, stage.tfvars, prod.tfvars. Currently each app's repo has a directory of config/{env}.tfvars, which is really repetitive.

Googling for importing or including terraform resources is just getting me results about terraform state, so hasn't been fruitful.

I've considered:

  1. Using a group-level Gitlab variable just as key=val env file and have my gitlab-ci yaml source the correct environment's file, then just include what I need using -var="key=value" in my plan and apply commands.

  2. Creating a terraform module that either uses TF_WORKSPACE or an input prop to return the correct variables. I think this may be possible, but I'm new to TF, so I'm not sure how to return data back from a module, or if this type of "side-effects only" solution is an abusive workaround to something there's a better way to achieve.

Is there any way to include terraform variables from another Gitlab project?

1252748
  • 14,597
  • 32
  • 109
  • 229
  • The root cause of all of this is the lack of a data source providing the necessary information for the project and environment lifecycles. If you fix that problem, then most of this technical debt will disappear. – Matthew Schuchard Jan 30 '23 at 14:02
  • Hi @MattSchuchard. I think you mean create my own [data source](https://developer.hashicorp.com/terraform/language/data-sources). Do you mean I could create on and maintain it in a separate Gitlab project? – 1252748 Jan 30 '23 at 14:10

0 Answers0