1.9.6
4.67.0
aws_cloudwatch_metric_alarm->metric_query
metric_query can only have a metric block or an expression field but not both. This is not specified in the documentation and not caught with terraform plan
plan does not catch a badly configured resource.
after `terraform apply`, the output is -
aws_cloudwatch_metric_alarm.complex_alarm_1: Creating...
╷
│ Error: creating CloudWatch Metric Alarm (complex-alarm-1): No metric_query may have both `expression` and a `metric` specified
sample resource configuration -
# High Resolution Alarms
# Complex Alarms with Multiple Metrics
resource "aws_cloudwatch_metric_alarm" "complex_alarm_1" {
alarm_name = "complex-alarm-1"
alarm_description = "Complex alarm with multiple metrics"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 2
threshold = 90
treat_missing_data = "missing"
metric_query {
id = "high1"
return_data = false
expression = "SELECT AVG(CPUUtilization) FROM AWS/EC2 GROUP BY InstanceId"
period = 10
metric {
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 10
stat = "Average"
}
}
}
run terraform plan for the above resource
No response
No response
No response
No response
None