Terraform: Interpolation in tfvars file

Created on 11 Nov 2016  ยท  4Comments  ยท  Source: hashicorp/terraform

It looks like I cannot use interpolation in .tfvars file.
Here is my tfvars for example:

access_key        = "XXX"
secret_key        = "XXX"
deploy_key_pub    = "${file("./deploy_key.pub")}"
deploy_key_secret = "${file("./deploy_key")}"

the ${file()} seems to be interpreted as a plain string. Is there a way to make interpolation work in tfvars file?

config enhancement

Most helpful comment

Another use case: namespace generation based on ${terraform.env}.

All 4 comments

Another use case: namespace generation based on ${terraform.env}.

Is there any plan to support this in v0.12 or any time soonish? Being able to read configuration from static files in the containing module for passing it to a submodule would be great.

Hi all! I'm not sure why I didn't see this issue before, but here we are... :confounded:

Quite a lot has changed since this issue was opened, so it feels to me that the use-cases that likely motivated this feature request have now been addressed with one or more other language features. For example:

  • Local values allow defining named derived values within a particular module, so it's now common to separate the static input variables from other values derived from them, with patterns like this:

    variable "deploy_key_filename" {
      type = string
    }
    
    locals {
      deploy_key = file(var.deploy_key_filename)
    }
    
    locals {
      per_workspace = {
        workspace_a = "foo"
        workspace_b = "bar"
      }
      workspace = local.per_workspace[terraform.workspace]
    }
    
  • The jsondecode, yamldecode, and csvdecode functions provide various ways of interpreting structured data saved in separate files.

Perhaps there were other use-cases in mind here, but this issue is focused on a particular technical proposal so I'd like to proceed as follows: if you are one of the folks who voted for this issue and you had a use-case in mind that the features above don't seem to meet, please open a new feature request and fill in the template to describe the underlying problem you are hoping to solve. That way we can consider possible solutions to those specific problems, which may take a different form than what was proposed here.

With that in mind, I'm going to close this. I do appreciate the discussion here, and I'm sorry that we didn't respond to this issue before. Hopefully the new features described above will address at least some of the needs that motivated this request. Thanks!

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