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"}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.