One interesting thing Stacks does with Jinja is inject a throw(msg)
filter which performs a Python raise Exception(msg)
.
This allows halting the execution of a Stacks render if the template is programmed to do so.
We can use this for input validation, for example.
# stacks/owners.tf
{% if 'owner' in var %}{{ throw('var.owner is not defined') }}{% endif %}
{% if var.owner not in var.owners %}{{ throw('var.owner not in var.owners') }}{% endif %}
# stacks/owners.tfvars
owners = [
"engineering",
"marketing",
"operations",
"sales",
]
From now on, on each stack/layer, you'll have to define a valid owner:
owner = "engineering"
Otherwise Stacks will fail to render.
This can be used for enforcing common resource tagging policies, for ownership tracking, cost analysis, etc.