0
votes

Using terraform, I'd like to see if there's a way — with the template rendering system — to define a template_file in a terraform module (base template) and then "extend" or "append" to the rendering in the instantiation rather than replaced.

I can currently define the template_file in either location, but would like to know if I can build upon the module's template on a per-instance basis. The specific use case is for userdata on AWS EC2s which vary slightly from instance type to instance type.

Thank you, Neurax

1

1 Answers

0
votes

This is what I ended up finding out.

In the module. Define an a template_file for the base template. Then define an output (for example named "module_template") whose value is equal to the rendered version of the template_file.

Then in the instantiation, define another template_file with a var equal to something like mod_temp = "${module.module_name.module_template}", and then in the template_file, reference that variable where necessary with ${mod_temp}.

I was thinking about trying to escape values in the "super template" so that maybe they would get interpolated during the "sub template's" rendering. Initial tests have not been successful.