title: Dynamic block with optional data
body: <p>let say we have this locals:</p>
  <pre><code>locals = {
    schemas = [
      {
        name                = &quot;is_cool&quot;
        attribute_data_type = &quot;Boolean&quot;
        mutable             = true
        required            = false
      },
      {
        name                = &quot;firstname&quot;
        attribute_data_type = &quot;String&quot;
        mutable             = true
        required            = false
        min_length          = 1
        max_length          = 256
      }
    ]
  }
  </code></pre>
  <p>What I would like to achieve is to use <code>dynamic</code> to build schemas and when the schema is a string I would like to add the <code>string_attribute_constraints</code> block.</p>
  <p>This is what I did so far but it adds an empty <code>string_attribute_constraints</code> block when the schema is Boolean</p>
  <pre><code>dynamic &quot;schema&quot; {
    for_each = var.schemas
    content {
      name                = schema.value.name
      attribute_data_type = schema.value.attribute_data_type
      mutable             = schema.value.mutable
      required            = schema.value.required
  
      string_attribute_constraints {
        min_length = lookup(schema.value, &quot;min_length&quot;, null)
        max_length = lookup(schema.value, &quot;max_length&quot;, null)
      }
    }
  }
  </code></pre>
  <p><strong>terraform plan:</strong></p>
  <pre><code>      + schema {
            + attribute_data_type = &quot;Boolean&quot;
            + mutable             = true
            + name                = &quot;is_cool&quot;
            + required            = false
  
            + string_attribute_constraints {}
          }
  </code></pre>