Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #4350 change datapointsToAlarm attribute in aws_cloudwatch_metric_alarm #5095

Merged
merged 2 commits into from
Jul 6, 2018

Conversation

saravanan30erd
Copy link
Contributor

@saravanan30erd saravanan30erd commented Jul 5, 2018

Fixes #4350

Changes proposed in this pull request:

Output from acceptance testing:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSCloudWatchMetricAlarm_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -run=TestAccAWSCloudWatchMetricAlarm_ -timeout 120m
=== RUN   TestAccAWSCloudWatchMetricAlarm_importBasic
--- PASS: TestAccAWSCloudWatchMetricAlarm_importBasic (36.07s)
=== RUN   TestAccAWSCloudWatchMetricAlarm_basic
--- PASS: TestAccAWSCloudWatchMetricAlarm_basic (28.09s)
=== RUN   TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm
--- PASS: TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm (33.13s)
=== RUN   TestAccAWSCloudWatchMetricAlarm_treatMissingData
--- PASS: TestAccAWSCloudWatchMetricAlarm_treatMissingData (49.53s)
=== RUN   TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
--- PASS: TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles (51.51s)
=== RUN   TestAccAWSCloudWatchMetricAlarm_extendedStatistic
--- PASS: TestAccAWSCloudWatchMetricAlarm_extendedStatistic (28.78s)
=== RUN   TestAccAWSCloudWatchMetricAlarm_missingStatistic
--- PASS: TestAccAWSCloudWatchMetricAlarm_missingStatistic (8.62s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	235.760s
...

@ghost ghost added the size/XS Managed by automation to categorize the size of a PR. label Jul 5, 2018
@bflad bflad added bug Addresses a defect in current functionality. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. labels Jul 6, 2018
@bflad
Copy link
Contributor

bflad commented Jul 6, 2018

changed datapointsToAlarm to computed attribute.

I'm not sure we want to disable Terraform's drift detection for the attribute. Someone can modify the alarm outside of Terraform and re-configure it for M out of N (in Terraform terms, a different datapoints_to_alarm from evaluation_period), which Terraform should show as a difference if its not defined in their Terraform configuration. It seems more valid to ignore the difference when the API value for datapoints_to_alarm matches evaluation_period and Terraform wants to set the attribute to the schema.TypeInt zero value.

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jul 6, 2018
@saravanan30erd
Copy link
Contributor Author

saravanan30erd commented Jul 6, 2018

@bflad then its better to ignore this difference. But I think its better to add validation for minimum value as per API doc(https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html).
what do you think?

@ghost ghost added the size/XS Managed by automation to categorize the size of a PR. label Jul 6, 2018
@bflad
Copy link
Contributor

bflad commented Jul 6, 2018

We can add the validation, but it would not resolve the linked issue. I'll mark the PR to not close it.

@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. and removed bug Addresses a defect in current functionality. waiting-response Maintainers are waiting on response from community or contributor. labels Jul 6, 2018
@bflad bflad added this to the v1.27.0 milestone Jul 6, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @saravanan30erd! 🚀

7 tests passed (all tests)
=== RUN   TestAccAWSCloudWatchMetricAlarm_missingStatistic
--- PASS: TestAccAWSCloudWatchMetricAlarm_missingStatistic (2.79s)
=== RUN   TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm
--- PASS: TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm (6.66s)
=== RUN   TestAccAWSCloudWatchMetricAlarm_extendedStatistic
--- PASS: TestAccAWSCloudWatchMetricAlarm_extendedStatistic (6.81s)
=== RUN   TestAccAWSCloudWatchMetricAlarm_basic
--- PASS: TestAccAWSCloudWatchMetricAlarm_basic (6.96s)
=== RUN   TestAccAWSCloudWatchMetricAlarm_importBasic
--- PASS: TestAccAWSCloudWatchMetricAlarm_importBasic (7.29s)
=== RUN   TestAccAWSCloudWatchMetricAlarm_treatMissingData
--- PASS: TestAccAWSCloudWatchMetricAlarm_treatMissingData (11.36s)
=== RUN   TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
--- PASS: TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles (11.55s)

@bflad bflad merged commit 004db98 into hashicorp:master Jul 6, 2018
bflad added a commit that referenced this pull request Jul 6, 2018
@saravanan30erd
Copy link
Contributor Author

@bflad is there any possible solution for this issue?

@bflad
Copy link
Contributor

bflad commented Jul 9, 2018

Theoretically, it can be done via DiffSuppressFunc returning true when the old value matches d.Get("evaluation_periods").(string) and new being reset to its zero value.

The new acceptance test to cover this behavior will need to create an alarm in its first step (omitting datapoints_to_alarm), then in the second step:

  • PreConfig: simulate the console behavior of updating the alarm to set datapoints_to_alarm to match evaluation_periods
  • Config same configuration as the first step
  • PlanOnly: true to ensure no updates are expected

@bflad
Copy link
Contributor

bflad commented Jul 11, 2018

This has been released in version 1.27.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

martinb3 added a commit to rackspace-infrastructure-automation/aws-terraform-auto_recovery that referenced this pull request Aug 27, 2018
We're seeing AWS reject requests for this:
```
datapoints_to_alarm:      "0"
```

It turns out it must be >= 1, and when omitted, CloudWatch Alarms does the right thing, but Terraform wants to default this to "0" still:

hashicorp/terraform-provider-aws#4350 (problem report)
hashicorp/terraform-provider-aws#5095 (validation to 1)
martinb3 added a commit to rackspace-infrastructure-automation/aws-terraform-auto_recovery that referenced this pull request Aug 27, 2018
We're seeing AWS reject requests for this:
```
datapoints_to_alarm:      "0"
```

It turns out it must be >= 1, and when omitted, CloudWatch Alarms does the right thing, but Terraform wants to default this to "0" still:

hashicorp/terraform-provider-aws#4350 (problem report)
hashicorp/terraform-provider-aws#5095 (validation to 1)
https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html (AWS API docs)
@ghost
Copy link

ghost commented Apr 4, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. size/XS Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_cloudwatch_metric_alarm: AWS Console sets different default value for datapointsToAlarm
2 participants