hashicorp / terraform-provider-template

Terraform template provider
https://www.terraform.io/docs/providers/template/
Mozilla Public License 2.0
131 stars 89 forks source link

Extend a module's template file at the instance level #47

Closed dstrivelli closed 5 years ago

dstrivelli commented 5 years ago

I cannot find this if it does exist. I'm looking for a way to define a template_file in a terraform module, and then "extend" / "append" to it at the instantiation level.

I've tried creating the template_file in the module, then creating an output in the module of the rendering. Then defining another template_file on the instantiation level and trying to reference the module's output as an interpolated value in the template file.

Doing so results in a unknown variable error.

Module file

data "template_file" "module_user_data_template" {
  template = "${file("${path.module}/user_data.sh.template")}"
}

output "module_template_file" {
  value = "${data.template_file.module_user_data_template.rendered}"
}

Instance main.tf

data "template_file" "user_data_template" {
  template = "${file("${path.module}/user_data.sh.template")}"
}

# Create External Proxy Server
module "my-module-instance" {
  source = "../../../../../modules/my-module"
}

Instance template file

"${module.my-module-instance.module_template_file}"

echo "Appended" > /tmp/a
dstrivelli commented 5 years ago

Added the first line in my instance file to a var and it worked as expected.