terraform - aws_cloudwatch_metric_alarm

0

I am getting a ValidationError: Invalid metrics list when trying to create cloud watch alarms via terraform. Attaching sample terraform changes. Let me know if anyone has insighton this.

resource "aws_cloudwatch_metric_alarm" "quota" { alarm_name = "terraform-service-quota" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = 1 threshold = 5 alarm_description = "Notification for Service quota" metric_query { id = "currentresourcecount" metric { metric_name = "ResourceCount" namespace = "AWS/Usage" period = "120" stat = "Maximum" dimensions = { Service = var.dimensions["Service"] Class = var.dimensions["Class"] Type = var.dimensions["Type"] Resource = var.dimensions["Resource"] } } } metric_query { id = "percentage of quota used" expression = "currentresourcecount/${data.aws_servicequotas_service_quota.pull_by_quota_code.value}*100" return_data = "true" } actions_enabled = "true" depends_on = [aws_sns_topic.cloudwatch-sns] alarm_actions = [aws_sns_topic.cloudwatch-sns.arn] }

Sanjay
asked 9 months ago457 views
2 Answers
1

The issue was with naming convension, seems like i cannot have a space in id name. Had to change the metric_query id name.

Sanjay
answered 9 months ago
0

That's correct, the id is a property of the MetricDataQuery object and the valid characters are letters, numbers, and underscore. The first character must be a lowercase letter. You cannot use a space in the id.

Did you try using a Label for the readable display?

profile pictureAWS
Jsc
answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions