Escape bash variable reference in terraform template


I would like to use a set a variable and then reference it further down in a bash script inside a terraform template. The problem is that when I write ${variable}, terraform is going to search for its value and try to render it accordingly. But I’m sometimes interested only in the inner logic of bash.

Any ideas?

Hi @lethargosapatheia,

In Terraform’s template syntax you can write $${ (double dollar sign) in order to escape a literal ${ that would otherwise introduce a template sequence. To refer to bash variable variable you can write $${variable}, for example.

The same applies to the template directive syntax: you can generate a literal %{ by writing %%{ in the template.

1 Like