claranet / jinjaform

Terraform wrapper with Jinja2 templates
MIT License
35 stars 8 forks source link

Combine files #4

Closed raymondbutcher closed 5 years ago

raymondbutcher commented 5 years ago

Currently if there are multiple files in the directory tree with the same name, it will use the one closest to the working directory. I think it would be more intuitive for it to combine files with the same name, placing content from files at the top of the tree at the top of the combined file, and content from files closest to the working directory at the bottom of the file. Add a comments into the combined files like # jinjaform: stacks/account/terraform.tfvars so you can see the sources of combined files.

This will remove the ability to "clobber" files, e.g. place an empty or different file in a subdirectory to use instead of the file from the parent directory. Instead of doing that, we can put everything in one file and use a Jinja2 condition like {% if var.envtype == 'nonprod' %} nonprod only stuff {% endif %}.

Assumption to confirm: Terraform will use the last last value from a tfvars file if a variable appears multiple times. If there are multiple terraform.tfvars in the tree then I would expect values from the file closest to the working directory to take precedence.

raymondbutcher commented 5 years ago

The assumption about using the last value is partially wrong.

Versions before 0.12:

From 0.12 onwards: