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.