title: How to define optional variables in Terraform with default values defined in Consul
body: <p>I have a Terraform script with some variables populated from Consul. I want to use this script in two different scenarios:</p>
  
  <ul>
  <li>Scenario 1. Everything goes right using default values from Consul.</li>
  <li>Scenario 2. I need to override some variables.</li>
  </ul>
  
  <p>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:</p>
  
  <pre><code>## 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}"
  </code></pre>
  
  <p>Can somebody show me a better way to do it? <strong>How to avoid a hack with a "null" string?</strong></p>
  
  <p>Thanks</p>