title: Validate complex type using terraform
body: <p>Im trying to validate a terraform complex map. The map contains a list of objects with multiple attributes. I was trying to validate each attribute and unfortunately, it seems that whatever condition I put, it is ok. It's like the validation is always true.</p>
  <p>Could anyone have a look and see what I'm doing wrong? Also, would it be possible to validate map keys?</p>
  <pre><code>variable &quot;complexmap&quot; {
    type = map(object(
      {
        reference = string 
        type = string
        count = string
      }
    ))
  
    default = {
      &quot;key1&quot; = {
        count = &quot;5&quot;
        reference = &quot;refcode1&quot;
        type = &quot;novel&quot;
      }, 
      &quot;key2&quot; = {
        count = &quot;2&quot;
        reference = &quot;REFcode2&quot;
        type = &quot;comics&quot;
      }, 
    }
  
    validation {
           condition = (
               alltrue([for v in var.complexmap : (
                   can(regex(&quot;[a-z0-9]{4,10}&quot;, v[&quot;reference&quot;])) 
                   &amp;&amp; v[&quot;count&quot;] &gt;= 2 &amp;&amp; v[&quot;count&quot;] &lt; 10
                   &amp;&amp; (v[&quot;type&quot;] == &quot;novel&quot; || v[&quot;type&quot;] == &quot;comics&quot;)
               )])
           )
           error_message = &quot;Validation of an object failed.&quot;
       }
  }
  </code></pre>