-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Closed
Copy link
Labels
bugAddresses a defect in current functionality.Addresses a defect in current functionality.service/cloudwatchIssues and PRs that pertain to the cloudwatch service.Issues and PRs that pertain to the cloudwatch service.
Milestone
Description
Terraform and AWS Provider Version
`Terraform v1.11.4`
`hashicorp/aws v5.94.1`
Affected Resource(s) or Data Source(s)
aws_cloudwatch_metric_alarm
Expected Behavior
Period = 20 is supported, and able to apply without error
Actual Behavior
Error flagged on unsupported value
Relevant Error/Panic Output
Example 1
aws_cloudwatch_metric_alarm
│ Error: expected period to be one of [10 30], got 20
│
│ with aws_cloudwatch_metric_alarm.example1,
│ on main.tf line 88, in resource "aws_cloudwatch_metric_alarm" "example1":
│ 88: period = local.period
│
╵
╷
│ Error: expected period to be divisible by 60, got: 20
│
│ with aws_cloudwatch_metric_alarm.example1,
│ on main.tf line 88, in resource "aws_cloudwatch_metric_alarm" "example1":
│ 88: period = local.period
│
╵
Example 2
aws_cloudwatch_metric_alarm -> metric_query
│ Error: expected metric_query.0.period to be one of [1 5 10 30], got 20
│
│ with aws_cloudwatch_metric_alarm.example2,
│ on main.tf line 98, in resource "aws_cloudwatch_metric_alarm" "example2":
│ 98: resource "aws_cloudwatch_metric_alarm" "example2" {
│
╵
╷
│ Error: expected metric_query.0.period to be divisible by 60, got: 20
│
│ with aws_cloudwatch_metric_alarm.example2,
│ on main.tf line 98, in resource "aws_cloudwatch_metric_alarm" "example2":
│ 98: resource "aws_cloudwatch_metric_alarm" "example2" {
│
╵
Example 3
aws_cloudwatch_metric_alarm -> metric_query -> metric
Planning failed. OpenTofu encountered an error while generating this plan.
╷
│ Error: expected metric_query.0.metric.0.period to be one of [1 5 10 30], got 20
│
│ with aws_cloudwatch_metric_alarm.example3["ui-jobseekersupport"],
│ on main.tf line 117, in resource "aws_cloudwatch_metric_alarm" "example3":
│ 117: resource "aws_cloudwatch_metric_alarm" "example3" {
│
╵
╷
│ Error: expected metric_query.0.metric.0.period to be divisible by 60, got: 20
│
│ with aws_cloudwatch_metric_alarm.example3["ui-jobseekersupport"],
│ on main.tf line 117, in resource "aws_cloudwatch_metric_alarm" "example3":
│ 117: resource "aws_cloudwatch_metric_alarm" "example3" {
│
╵
Sample Terraform Configuration
Click to expand configuration
locals {
period = 20
}
resource "aws_cloudwatch_metric_alarm" "example1" {
for_each = var.endpoint_health_checks
alarm_description = "alarm for ${each.key} on healthcheck ID ${aws_route53_health_check.endpoint[each.key].id}"
alarm_name = "route53_alarm_${each.key}"
comparison_operator = "LessThanOrEqualToThreshold"
datapoints_to_alarm = 1
evaluation_periods = 2
metric_name = "HealthCheckPercentageHealthy"
namespace = "AWS/Route53"
period = local.period
statistic = "Average"
dimensions = {
HealthCheckId = aws_route53_health_check.endpoint[each.key].id
}
provider = aws.us-east-1
}
resource "aws_cloudwatch_metric_alarm" "example2" {
for_each = var.endpoint_health_checks
alarm_description = "alarm for ${each.key} on healthcheck ID ${aws_route53_health_check.endpoint[each.key].id}"
alarm_name = "route53_alarm_${each.key}"
evaluation_periods = 2
datapoints_to_alarm = 1
comparison_operator = "LessThanOrEqualToThreshold"
provider = aws.us-east-1
metric_query {
id = "e1"
period = local.period
return_data = "false"
}
}
resource "aws_cloudwatch_metric_alarm" "example3" {
for_each = var.endpoint_health_checks
alarm_description = "alarm for ${each.key} on healthcheck ID ${aws_route53_health_check.endpoint[each.key].id}"
alarm_name = "route53_alarm_${each.key}"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = 2
datapoints_to_alarm = 1
provider = aws.us-east-1
metric_query {
id = "e1"
metric {
period = local.period
stat = "Average"
metric_name = "HealthCheckPercentageHealthy"
namespace = "AWS/Route53"
dimensions = {
HealthCheckId = aws_route53_health_check.endpoint[each.key].id
}
}
return_data = "false"
}
}
Steps to Reproduce
- apply configuration with period = 20
Debug Logging
GenAI / LLM Assisted Development
n/a
Important Facts and References
As per AWS API doc for PutMetricAlarm https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html
API PutMetricAlarm, Period can support 10, 20, 30, and any multiple of 60.

As per AWS API doc MetricDataQuery https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDataQuery.html
API MetricDataQuery, Period can support 1, 5, 10, 20, 30, 60, or any multiple of 60

Would you like to implement a fix?
Yes
Metadata
Metadata
Assignees
Labels
bugAddresses a defect in current functionality.Addresses a defect in current functionality.service/cloudwatchIssues and PRs that pertain to the cloudwatch service.Issues and PRs that pertain to the cloudwatch service.