I have a template in my terraform config to which I write the values of a variable like this:
data "template_file" "config" {
template = "${file("${path.module}/templates/${var.json_config}")}"
vars {
is_enabled = "${var.is_enabled}"
}
}
Now is_enabled is a boolean string which is either set to true or false. Now based on if this is true or false I want to set another variable. In pseudocode it would look like this:
if is_enabled == true path = /one/path/ else path = /another/path
I had a look at the conditional values but it seems to be for bringing up resources. how would I use this to set a variable in a template file ?
Templates uses the same interpolation syntax as all other strings in Terraform. Documentation is available
So in your case it will look like this:
path = ${is_enabled ? "/one/path/" : "/another/path"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With