Skip to content

cloudwatch_metric_alarm should allow datapoints_to_alarm to be 0 #45461

@onlynone

Description

@onlynone

Terraform and AWS Provider Version

Terraform v1.9.8
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v6.24.0

Your version of Terraform is out of date! The latest version
is 1.14.1. You can update by downloading from https://www.terraform.io/downloads.html

Affected Resource(s) or Data Source(s)

  • cloudwatch_metric_alarm

Expected Behavior

You should be able to specify:

  datapoints_to_alarm = 0

In order to get the default behavior of datapoints_to_alarm being the same as evaluation_periods. If you don't set a value for datapoints_to_alarm initially and then set one to some positive integer, terraform will report the change like:

  # aws_cloudwatch_metric_alarm.example will be updated in-place
  ~ resource "aws_cloudwatch_metric_alarm" "example" {
      ~ datapoints_to_alarm                   = 0 -> 1

Indicating that it did use 0 for the default value. And looking at the alarm in the AWS console, under "Conditions" -> "Datapoints to alarm", it says "N out of N" where N is whatever you have evaluation_periods set to.

Actual Behavior

You get the error Error: expected datapoints_to_alarm to be at least (1), got 0

Relevant Error/Panic Output

Sample Terraform Configuration

Click to expand configuration
resource "aws_cloudwatch_metric_alarm" "example" {
  datapoints_to_alarm = 0
}

Steps to Reproduce

  1. Specify a cloudwatch_metric_alarm resource with datapoints_to_alarm = 0
  2. Run terraform plan or terraform apply

Debug Logging

No response

GenAI / LLM Assisted Development

n/a

Important Facts and References

No response

Would you like to implement a fix?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.needs-triageWaiting for first response or review from a maintainer.service/cloudwatchIssues and PRs that pertain to the cloudwatch service.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions