title: Terraform test for null or false value of object key
body: <p>Hopefully a relatively straightforward one. I have an object that uses the experimental optional attrs feature.</p>
  <p>This means that one of the object attributes/keys do not need to be present. I then need to test for either null or false value of said object key in object composition with for loop.</p>
  <p>When using the <code>module_variable_optional_attrs</code> experiment, it seems that if you use <code>lookup()</code> to find an object key which does not exist it'll always return null, not the default, as you might expect it to.</p>
  <p>I now am having to test with a conditional <code>(lookup(connection, &quot;auto_accept&quot;, false) == false || lookup(connection, &quot;auto_accept&quot;, false) == null)</code></p>
  <p>this doesn't seem very clean. looking for suggestions on improvements.</p>
  <p><strong>EDIT</strong></p>
  <blockquote>
  <p>main.tf</p>
  </blockquote>
  <pre><code>  terraform {
      # Optional attributes and the defaults function are
      # both experimental, so we must opt in to the experiment.
      experiments = [module_variable_optional_attrs]
    }
  
    variable &quot;example_var&quot; {
      type = list(object({
        name                   = string
        auto_accept            = optional(bool)
      }))
      description = &quot;Some variable&quot;
      default = [{
        name                   = &quot;example-name&quot;
      }]
    }
  </code></pre>
  <p>Below commands are run from <code>terraform console</code></p>
  <pre><code>&gt; lookup(var.example_var[0], &quot;auto_accept&quot;)
  false
  # now lets make the key undefined
  &gt; lookup(var.example_var[0], &quot;auto_accept&quot;)
  tobool(null)
  &gt; lookup(var.example_var[0], &quot;auto_accept&quot;, false)
  tobool(null)
  &gt; tobool(null)
  null
  </code></pre>