Skip to content

Files

Latest commit

15e2852 · Jan 16, 2025

History

History
26 lines (22 loc) · 987 Bytes
·

3.1.4. Jinja templating for variables.md

File metadata and controls

26 lines (22 loc) · 987 Bytes
·

Jinja templating for variables

Similar to how you get Jinja for templating Terraform code, you also get Jinja support to define variables themselves.

You can do so by creating any number of *.tfvars.jinja files where you would normally have *.tfvars files. These get rendered using the variables defined in the non-Jinja counterparts, and they get higher override priority than them, of course.

Here's where you can use Jinja in variables:

|-- environments/
|   `-- production/
|       `-- env.tfvars                 # not here
`-- stacks/
   |-- ec2/
   |   |-- base/
   |   |-- layers/
   |   |   `-- production/
   |   |       |-- layer.tfvars        # not here
   |   |       `-- layer.tfvars.jinja  # here
   |   |-- stack.tfvars                # not here
   |   `-- stack.tfvars.jinja          # here
   |-- globals.tfvars                  # not here
   `-- globals.tfvars.jinja            # here

Be careful not to put yourself in a cyclical dependency, however.