Terraform: Variable cannot contain interpolation?

Created on 10 May 2017  ยท  4Comments  ยท  Source: hashicorp/terraform

variable "cluster_name" {
  default = "${var.environment}.${var.domain_name}"
}

Why is the above not possible and is there a workaround to compute a default variable value from other variables?

core question

Most helpful comment

Hi @andrewsav-datacom,

This is a pretty old issue. In the mean time since this discussion, there was a new feature added called Local Values that doesn't address exactly what was requested in this issue, but does serve the most common use-case presented for interpolating into defaults: factoring out repeated expressions to use in multiple places.

We aren't always able to monitor closed/old issues well due to limitations of our tooling, so if you find that your use case isn't served by this feature please feel free to open a new top-level issue referencing this one where we can discuss ways forward.

All 4 comments

Hi @olalonde,

This isn't possible at the moment because of how interpolation in implemented. The default values need to be loaded early on before there is enough context to run the interpolation. While we would like to be able to implement this along with some related functionality, there is no set timeline for this feature.

Similar functionality can be created by using a module to set variables value and return it through the output.

Similar functionality can be created by using a module to set variables value and return it through the output.

@jbardin is there an example?

Hi @andrewsav-datacom,

This is a pretty old issue. In the mean time since this discussion, there was a new feature added called Local Values that doesn't address exactly what was requested in this issue, but does serve the most common use-case presented for interpolating into defaults: factoring out repeated expressions to use in multiple places.

We aren't always able to monitor closed/old issues well due to limitations of our tooling, so if you find that your use case isn't served by this feature please feel free to open a new top-level issue referencing this one where we can discuss ways forward.

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

Related issues

ronnix picture ronnix  ยท  3Comments

shanmugakarna picture shanmugakarna  ยท  3Comments

rnowosielski picture rnowosielski  ยท  3Comments

darron picture darron  ยท  3Comments

rkulagowski picture rkulagowski  ยท  3Comments