0

I work for an enterprise with a number of different gitlab repositories all deploying applications using Terraform. The majority of these code bases uses a standardised module that defines certain tags for resources in our cloud provider. I am wanting to add the Gitlab project id as one of the default tags and while I know how to use pre-defined vars in Terraform by defining an env var starting with TF_VAR, I don't want to have to modify all code bases in order to set it.

What I want to do is set the project id (env var) in the module so that any codebase that consumes this module will automatically have this environment variable set for use in the gitlab pipeline.

Does anyone have any ideas how I might do this?

Thanks, Adam

user1495536
  • 93
  • 1
  • 8
  • This sounds like you are asking for keyword expansion or keyword substitution. Which git does not provide out of the box. You might want to look at git's smudge and clean filters as a way of doing what you need. And it should be able to modify the terraform code directly, no need for a TF_VAR. [This](https://stackoverflow.com/questions/16524225/how-can-i-populate-the-git-commit-id-into-a-file-when-i-commit/16529140#16529140) might help – P Burke Jan 18 '21 at 13:30
  • If you are executing within a pipeline, then this would be an instrinsic environment variable that can be appended to the base tags map. – Matthew Schuchard Jan 18 '21 at 16:45

0 Answers0