Terraform and cloudwatch widgets

I am having trouble looping through widgets for cloudwatch with terraform. I want the widgets to created for each metric per table and then move to the next one. But since I am looping through each metric is created per table. I am using locals to loop through each of these metrics.

metrc1 = [for table in var.tables :
    {
      type : "metric",
      x : 0,
      y : 0,
      width : 12,
      height : 6,
      properties : {
        view : "bar",
        stacked : false,
        metrics : [
          ["ConsumedReadCapacityUnits", table]
        ]
        region : "us-east-2",
        title : "ConsumedReadCapacityUnits"
      }
    }
  ]
  metric2 = [for table in var.tables :
    {
      type : "metric",
      x : 12,
      y : 0,
      width : 12,
      height : 6,
      properties : {
        view : "bar",
        stacked : false,
        metrics : [
          ["ConsumedWriteCapacityUnits", table]
        ]
        region : "us-east-2",
        title : "ConsumedWriteCapacityUnits"
      }

    }
  ]

I see below.


{
      type : "metric",
      x : 0,
      y : 0,
      width : 12,
      height : 6,
      properties : {
        view : "bar",
        stacked : false,
        metrics : [
          ["ConsumedReadCapacityUnits", table1]
        ]
        region : "us-east-2",
        title : "ConsumedReadCapacityUnits"
      }
,
{
      type : "metric",
      x : 0,
      y : 0,
      width : 12,
      height : 6,
      properties : {
        view : "bar",
        stacked : false,
        metrics : [
          ["ConsumedReadCapacityUnits", table2]
        ]
        region : "us-east-2",
        title : "ConsumedReadCapacityUnits"
      },
{
      type : "metric",
      x : 0,
      y : 0,
      width : 12,
      height : 6,
      properties : {
        view : "bar",
        stacked : false,
        metrics : [
          ["ConsumedwriteCapacityUnits", table1]
        ]
        region : "us-east-2",
        title : "ConsumedWriteCapacityUnits"
      },
{
      type : "metric",
      x : 0,
      y : 0,
      width : 12,
      height : 6,
      properties : {
        view : "bar",
        stacked : false,
        metrics : [
          ["ConsumedwriteCapacityUnits", table2]
        ]
        region : "us-east-2",
        title : "ConsumedWriteCapacityUnits"
      }

I want to see the widgets get created like below.


{
      type : "metric",
      x : 0,
      y : 0,
      width : 12,
      height : 6,
      properties : {
        view : "bar",
        stacked : false,
        metrics : [
          ["ConsumedReadCapacityUnits", table1]
        ]
        region : "us-east-2",
        title : "ConsumedReadCapacityUnits"
      }
,
{
      type : "metric",
      x : 0,
      y : 0,
      width : 12,
      height : 6,
      properties : {
        view : "bar",
        stacked : false,
        metrics : [
          ["ConsumedWriteCapacityUnits", table1]
        ]
        region : "us-east-2",
        title : "ConsumedWriteCapacityUnits"
      },
{
      type : "metric",
      x : 0,
      y : 0,
      width : 12,
      height : 6,
      properties : {
        view : "bar",
        stacked : false,
        metrics : [
          ["ConsumedReadCapacityUnits", table2]
        ]
        region : "us-east-2",
        title : "ConsumedReadCapacityUnits"
      },
{
      type : "metric",
      x : 0,
      y : 0,
      width : 12,
      height : 6,
      properties : {
        view : "bar",
        stacked : false,
        metrics : [
          ["ConsumedwriteCapacityUnits", table2]
        ]
        region : "us-east-2",
        title : "ConsumedWriteCapacityUnits"
      }

Hi, is var.tables just ["table1", "table2"]?
Is the code in “I see below” correct as it is only using metric1 definition?

Could you share a public git repo to understand also how the resources get deployed?