CodexBloom - Programming Q&A Platform

Terraform scenarios to configure AWS CloudWatch alarms with multiple dimensions - 'InvalidParameterValue'

๐Ÿ‘€ Views: 40 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-06-06
terraform aws cloudwatch HCL

I'm following best practices but I'm having a hard time understanding I'm prototyping a solution and After trying multiple solutions online, I still can't figure this out. I'm trying to create multiple CloudWatch alarms in AWS using Terraform, but I'm working with an scenario with dimension settings. I have the following code where I define my alarms: ```hcl resource "aws_cloudwatch_metric_alarm" "cpu_high" { alarm_name = "High CPU Usage" comparison_operator = "GreaterThanThreshold" evaluation_periods = "1" metric_name = "CPUUtilization" namespace = "AWS/EC2" period = "60" statistic = "Average" threshold = "80" dimensions = { InstanceId = aws_instance.my_instance.id AutoScalingGroupName = aws_autoscaling_group.my_asg.name } alarm_actions = [aws_sns_topic.my_topic.arn] tags = { Environment = "production" } } ``` When I run `terraform apply`, I get the following behavior: ``` behavior: InvalidParameterValue status code: 400, request id: xxxxxxxx, message: The value of "AutoScalingGroupName" must be in the format of "AutoScalingGroupName=your-group-name". ``` I've checked the AWS documentation, and it seems like I'm using the correct dimension names. Iโ€™ve also tried to pass the dimensions as a list instead of a map, but that didn't help either. Iโ€™m unsure if the scenario lies with how Iโ€™m defining the dimensions or if thereโ€™s a question with my resource dependencies. I was thinking about restructuring the dimensions block or breaking down the alarm into separate resources, but Iโ€™d like to avoid unnecessary complexity. Has anyone encountered a similar question, or does anyone have suggestions on how to properly define dimensions for CloudWatch alarms in Terraform? Any help would be greatly appreciated! I'm using Hcl LTS in this project. Has anyone dealt with something similar? I'm on Ubuntu 20.04 using the latest version of Hcl. Thanks for any help you can provide! This is for a application running on Linux.