RaGe
RaGe

Reputation: 23795

Is there a way to access a root level variable in a module?

I have a root level variable, whose value is set at run time via a tfvar file. The tfvar file used and the var value can vary. Now I want to use this variable inside a module, the terraform way to do this is to set it up as a module variable and pass the root var when creating the module.

Except, I have this module used in our infrastructure several hundred times. Is repeating this variable 100s of times the only way to do this? Can the module access root namespace to grab the variable value?

I'm half tempted to use an external data script in the module to fetch the value instead, except, I wont know which tfvars file will be in effect at runtime..

Upvotes: 0

Views: 1152

Answers (1)

Chris Forbes
Chris Forbes

Reputation: 130

Unfortunately, the only Terraform supported way is to pass the value into the module as a variable. Terraform has made me a copy/paste expert.

The only other approach that comes to mind that Terraform supports is making creative use of the External Data Source.

Upvotes: 1

Related Questions