I have a Terraform script with some variables populated from Consul. I want to use this script in two different scenarios:
- Scenario 1. Everything goes right using default values from Consul.
- Scenario 2. I need to override some variables.
I've checked Terraform documentation and noticed that I can't use a variable defined in Consul as a default value for some another variable. So I ended up with following workaround:
## vars.tf
## emulating undefined value using "null" string
variable "my_optional_variable" { default = "null" }
## main.tf
my_optional_variable = "${var.my_optional_variable == "null" ? data.consul_keys.my_optional_variable : var.my_optional_variable}"
Can somebody show me a better way to do it? How to avoid a hack with a "null" string?
Thanks