Terraform: Sanitize a map that may be a map of strings or map of maps or combo of both
Following the documentation a map is a collection of key/values with a constraint:

&quot;...accepts any element type as long as every element is the same type&quot; source

So the input map you have declared, is already an invalid map for Terraform 0.12 (at least)
Below the example of the error produced:
variable &quot;cidrs&quot; {
  description = &quot;&quot;
  type        = map
  default = [
    [&quot;1.1.1.1&quot;],
    [&quot;2.2.2.2&quot;, &quot;3.3.3.3&quot;],
    {
      C = [&quot;4.4.4.4&quot;]
      D = [&quot;5.5.5.5&quot;]
    }]
}

When validating an error is raised:
$&gt; terraform validate

Error: Invalid default value for variable

  on vars.tf line 65, in variable &quot;cidrs&quot;:
  65:   default = [
  66:     [&quot;1.1.1.1&quot;],
  67:     [&quot;2.2.2.2&quot;, &quot;3.3.3.3&quot;],
  68:     {
  69:       C = [&quot;4.4.4.4&quot;]
  70:       D = [&quot;5.5.5.5&quot;]
  71:     }]

This default value is not compatible with the variable's type constraint: map
of any single type required.

Been that said, if we can generalize A and B as &quot;values which are lists&quot; and Group1 as &quot;values which are maps&quot; and the input is a fixed type ordered we can use a tuple or  an object, this can be solve in a more readable (and maintainable) way. If so, let us know so we can extend this answer.