Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

template_file needs the ability to use tfvars #24

Open
hashibot opened this issue Dec 11, 2017 · 1 comment
Open

template_file needs the ability to use tfvars #24

hashibot opened this issue Dec 11, 2017 · 1 comment

Comments

@hashibot
Copy link

This issue was originally opened by @digitalfiz as hashicorp/terraform#16863. It was migrated here as a result of the provider split. The original body of the issue is below.


For example right now we have a .json file for our task definitions and those task definitions have environment variables that change so we put them in the tfvars for each state.

The problem or more so the annoying thing is that we have to put the variable in the json file. Then make sure to put it in the vars for template_file and then also in the tfvars. So this exact same thing exists in 3 different places. Instead of 1 place for setting it and 1 place for using it.

It would be super useful if template_file had a flag or something to say just use whatever variables are available like all the other resources can do.

@digitalfiz
Copy link

An example of this would be like so:

myvars.tfvars

foo = "bar"

main.12.tf

locals {
  calculated_vars = {
    something = "calculated"
  }
}

resource "aws_ecs_task_definition" "service" {
  family                = "service"
  container_definitions = templatefile("mydef.json", local.calculated_vars, true)
                          # 3rd param would be "inherit variables", default: false
}

main.11.tf

locals {
  calculated_vars = {
    something = "calculated"
  }
}

data "template_file" "def" {
  template     = "${file("mydef.json")}"
  vars         = local.calculated_vars
  inherit_vars = true # default: false
}

resource "aws_ecs_task_definition" "service" {
  family                = "service"
  container_definitions = data.template_file.def.rendered
}

mydef.json (the var. prefix can be used to avoid collisions):

{
    "whatisfoo": "${var.foo}", 
    "whatiscalculated": "${something}"
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants