title: Merge list of objects in terraform
body: <p>Is there a way to merge the following list of objects</p>
  <pre><code>variable &quot;common_variables&quot; {
    type = list(object({ var_name = string, var_value = string, workspace_name = string }))
    default = [
      {
        &quot;var_name&quot;       = &quot;location&quot;
        &quot;var_value&quot;      = &quot;West US&quot;
        &quot;workspace_name&quot; = &quot;env-1&quot;
      }
    ]
  }
  
  variable &quot;custom_variables&quot; {
    type = list(object({ var_name = string, var_value = string, workspace_name = string }))
    default = [
      {
        &quot;var_name&quot;       = &quot;location&quot;
        &quot;var_value&quot;      = &quot;West Europe&quot;
        &quot;workspace_name&quot; = &quot;env-1&quot;
      }
    ]
  }
  
  
  locals {
  
    # custom_variables should replace common_variables
    merged_variables = concat(var.common_variables, var.custom_variables)
  
  }
  
  output &quot;merged_variables&quot; {
    value = local.merged_variables
  }
  </code></pre>
  <p>Any <code>custom_variables</code> should replace <code>common_variables</code> that match on <code>workspace_name</code> &amp; <code>var_name</code>.</p>
  <p>So the output I want is:</p>
  <pre><code>merged_variables = [
    {
      &quot;var_name&quot; = &quot;location&quot;
      &quot;var_value&quot; = &quot;West Europe&quot;
      &quot;workspace_name&quot; = &quot;env-1&quot;
    }
  ]
  </code></pre>