Terraform: Variable references within other variable declarations

Created on 14 Jul 2015  ยท  17Comments  ยท  Source: hashicorp/terraform

This may be a duplicate, if so I apologize, I did search for some similar issue first but came up empty.

I'd like to be able to perform variable references in other variable declarations, for example:

variable "project" {}
variable "front_end_name" {}
...
project = "grid-gor-staging"
front_end_name = "${var.project}-frontend-web"

Hopefully this makes sense. I tried a few variations to get it to work, but was unsuccessful and couldn't locate any documentation that referenced any logic similar to this.

config enhancement

Most helpful comment

For me, the now several-months-old locals feature addressed this need entirely (https://www.terraform.io/docs/configuration/locals.html). Might it be time to close this issue?

All 17 comments

I'm working around this with concat() in some cases, but it's not very reliable, so would love to see interpolations in variables.

We've run into the same problem. Being unable to define variables with interpolations means lots of implicit coupling becomes hidden around our Terraform config.

Any idea when this will be addressed?

+1 for this request

+1 for this please :bow:

+1

+1

More than a year in open state, is this so difficult to implement?

+1

+1

More than a year in open state, is this so difficult to implement?

@igoratencompass If it's not so difficult, perhaps you could help by contributing a patch? That's sort of how this works...

For me, the now several-months-old locals feature addressed this need entirely (https://www.terraform.io/docs/configuration/locals.html). Might it be time to close this issue?

+1

+1

+1

Hi all! Sorry we missed this on a previous cleanup pass due to it using an outdated labeling scheme.

As @daveadams pointed out, Local Values are intended to address this use-case, separately from Input Variables which exist only to accept data from _outside_ the module.

The documentation page shows some examples of mixing variables and locals to provide default patterns that a caller can optionally override.

I don't think local values address this completely.

I want to define an input variable where the default value will use another input variable unless it is defined itself.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings