CloudWatch Metric Alarm (XYZ): ValidationError: Invalid metrics list

We are having issues using dynamic blocks to create a dry module for cloudwatch metric alarm. We are passing a json decoded file with the object, terraform plan oks it, but when we apply we get error:

Blockquote

Error: failed creating CloudWatch Metric Alarm (XYZ): ValidationError: Invalid metrics list
│       status code: 400, request id: d95222b7-7c49-4fb1-a6f7-abaed47e2670
│ 
│   with module.alarm.aws_cloudwatch_metric_alarm.lambda_tag,
│   on ../../../../modules/cloudwatch/alarm/metric.tf line 4, in resource "aws_cloudwatch_metric_alarm" "lambda_tag":
│    4: resource "aws_cloudwatch_metric_alarm" "lambda_tag" {

Blockquote

json file passed as a local decoded json.

Blockquote

[{
	"id": "XYZ",
	"expression": null,
	"label": null,
	"return_data": true,
	"metric": [{
		"metric_name": "Errors",
		"namespace": "AWS/Lambda",
		"period": 300,
		"stat": "Sum",
		"unit": null,
		"dimensions": {
			"FunctionName": "XYZ"
		}
	}]
}]

this is the dynamic block for metric alarm

Blockquote

dynamic "metric_query" {
    for_each = local.json_data #var.metric_query
    content {
      id          = metric_query.value["id"]
      expression  = metric_query.value["expression"]
      label       = metric_query.value["label"]
      return_data = metric_query.value["return_data"]
      dynamic "metric" {
        #        for_each = metric_query.value["metric"][*]
        content {
          metric_name = metric_query.value.metric_name
          namespace   = metric_query.value.namespace
          period      = metric_query.value.period
          stat        = metric_query.value.stat
          unit        = metric_query.value.unit
          dimensions  = metric_query.value["dimensions"]
        }
      }
    }
  }

Blockquote

Is possible to use dynamic blocks with this particular block(metric_query) ? We have successfully used dynamic blocks in beanstalk terraform without issues.

Perhaps you’re running into this issue: (Cloudwatch): Metrics with labels can't be used in alarms for API Gateway metrics · Issue #13434 · aws/aws-cdk · GitHub