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

resource/aws_cloudwatch_metric_alarm: Add period to metric_query block #29896

Merged
merged 6 commits into from
Mar 15, 2023

Conversation

gdavison
Copy link
Contributor

@gdavison gdavison commented Mar 10, 2023

Description

Adds missing period parameter to metric_query block.

Also adds validation to metric_query.metric.period.

Relations

Closes #29398.
Closes #28617.
Closes #28547.

References

Output from Acceptance Testing

$ make testacc PKG=cloudwatch TESTS=TestAccCloudWatchMetricAlarm_

--- PASS: TestAccCloudWatchMetricAlarm_missingStatistic (8.67s)
--- PASS: TestAccCloudWatchMetricAlarm_disappears (17.45s)
--- PASS: TestAccCloudWatchMetricAlarm_dataPointsToAlarm (19.02s)
--- PASS: TestAccCloudWatchMetricAlarm_basic (23.23s)
--- PASS: TestAccCloudWatchMetricAlarm_AlarmActions_swfAction (23.46s)
--- PASS: TestAccCloudWatchMetricAlarm_AlarmActions_snsTopic (23.51s)
--- PASS: TestAccCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles (30.60s)
--- PASS: TestAccCloudWatchMetricAlarm_treatMissingData (42.59s)
--- PASS: TestAccCloudWatchMetricAlarm_tags (42.77s)
--- PASS: TestAccCloudWatchMetricAlarm_metricQuery (143.82s)
--- PASS: TestAccCloudWatchMetricAlarm_AlarmActions_ec2Automate (177.82s)
--- PASS: TestAccCloudWatchMetricAlarm_extendedStatistic (270.39s)

@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added documentation Introduces or discusses updates to documentation. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/XL Managed by automation to categorize the size of a PR. and removed documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. labels Mar 10, 2023
@github-actions github-actions bot added documentation Introduces or discusses updates to documentation. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Mar 10, 2023
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

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

LGTM 🚀.

% make testacc TESTARGS='-run=TestAccCloudWatchMetricAlarm_' PKG=cloudwatch ACCTEST_PARALLELISM=3
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/cloudwatch/... -v -count 1 -parallel 3  -run=TestAccCloudWatchMetricAlarm_ -timeout 180m
=== RUN   TestAccCloudWatchMetricAlarm_basic
=== PAUSE TestAccCloudWatchMetricAlarm_basic
=== RUN   TestAccCloudWatchMetricAlarm_AlarmActions_ec2Automate
=== PAUSE TestAccCloudWatchMetricAlarm_AlarmActions_ec2Automate
=== RUN   TestAccCloudWatchMetricAlarm_AlarmActions_snsTopic
=== PAUSE TestAccCloudWatchMetricAlarm_AlarmActions_snsTopic
=== RUN   TestAccCloudWatchMetricAlarm_AlarmActions_swfAction
=== PAUSE TestAccCloudWatchMetricAlarm_AlarmActions_swfAction
=== RUN   TestAccCloudWatchMetricAlarm_dataPointsToAlarm
=== PAUSE TestAccCloudWatchMetricAlarm_dataPointsToAlarm
=== RUN   TestAccCloudWatchMetricAlarm_treatMissingData
=== PAUSE TestAccCloudWatchMetricAlarm_treatMissingData
=== RUN   TestAccCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
=== PAUSE TestAccCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
=== RUN   TestAccCloudWatchMetricAlarm_extendedStatistic
=== PAUSE TestAccCloudWatchMetricAlarm_extendedStatistic
=== RUN   TestAccCloudWatchMetricAlarm_metricQuery
=== PAUSE TestAccCloudWatchMetricAlarm_metricQuery
=== RUN   TestAccCloudWatchMetricAlarm_missingStatistic
=== PAUSE TestAccCloudWatchMetricAlarm_missingStatistic
=== RUN   TestAccCloudWatchMetricAlarm_tags
=== PAUSE TestAccCloudWatchMetricAlarm_tags
=== RUN   TestAccCloudWatchMetricAlarm_disappears
=== PAUSE TestAccCloudWatchMetricAlarm_disappears
=== CONT  TestAccCloudWatchMetricAlarm_basic
=== CONT  TestAccCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
=== CONT  TestAccCloudWatchMetricAlarm_missingStatistic
--- PASS: TestAccCloudWatchMetricAlarm_missingStatistic (6.75s)
=== CONT  TestAccCloudWatchMetricAlarm_extendedStatistic
--- PASS: TestAccCloudWatchMetricAlarm_basic (19.75s)
=== CONT  TestAccCloudWatchMetricAlarm_AlarmActions_swfAction
--- PASS: TestAccCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles (29.34s)
=== CONT  TestAccCloudWatchMetricAlarm_treatMissingData
--- PASS: TestAccCloudWatchMetricAlarm_AlarmActions_swfAction (18.73s)
=== CONT  TestAccCloudWatchMetricAlarm_dataPointsToAlarm
--- PASS: TestAccCloudWatchMetricAlarm_dataPointsToAlarm (14.79s)
=== CONT  TestAccCloudWatchMetricAlarm_disappears
--- PASS: TestAccCloudWatchMetricAlarm_disappears (14.19s)
=== CONT  TestAccCloudWatchMetricAlarm_metricQuery
--- PASS: TestAccCloudWatchMetricAlarm_treatMissingData (44.17s)
=== CONT  TestAccCloudWatchMetricAlarm_AlarmActions_snsTopic
--- PASS: TestAccCloudWatchMetricAlarm_AlarmActions_snsTopic (18.98s)
=== CONT  TestAccCloudWatchMetricAlarm_AlarmActions_ec2Automate
--- PASS: TestAccCloudWatchMetricAlarm_metricQuery (92.89s)
=== CONT  TestAccCloudWatchMetricAlarm_tags
--- PASS: TestAccCloudWatchMetricAlarm_extendedStatistic (181.75s)
--- PASS: TestAccCloudWatchMetricAlarm_tags (38.07s)
--- PASS: TestAccCloudWatchMetricAlarm_AlarmActions_ec2Automate (230.41s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/cloudwatch	328.163s

@@ -113,6 +113,10 @@ func ResourceMetricAlarm() *schema.Resource {
"period": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.Any(
validation.IntInSlice([]int{1, 5, 10, 30}),
Copy link

Choose a reason for hiding this comment

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

Documentation in https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html suggests

Valid values are 10, 30, and any multiple of 60.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @henkka,the following line

validation.IntDivisibleBy(60)

covers the multiples of 60 case. It's good to have extra eyes review things, though 🙂

Copy link

Choose a reason for hiding this comment

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

Ah right, my point was that this should actually be validation.IntInSlice([]int{10, 30}) if we'd like to comply with what AWS allows currently

Copy link
Contributor Author

@gdavison gdavison Mar 16, 2023

Choose a reason for hiding this comment

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

Ah, I see what you're saying. The top-level period, at

"period": {
Type: schema.TypeInt,
Optional: true,
ConflictsWith: []string{"metric_query"},
ValidateFunc: validation.Any(
validation.IntInSlice([]int{10, 30}),
validation.IntDivisibleBy(60),
),
},
, has valid values of 10, 30, and multiples of 60. The period of a metric_query, on the other hand, can be 1, 5, 10, 30, and multiples of 60 (https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDataQuery.html)

@mvrogowski
Copy link

mvrogowski commented Mar 14, 2023

Hey, there! Does it have some estimation on when this will be released? Thanks!

@khanhnd0408
Copy link

I also met troubles with this; my workaround is to create on the AWS console and import it to Terraform state, but I think it may raise this error again when I want to create or change other resources.

@gdavison gdavison merged commit 85954a0 into main Mar 15, 2023
@gdavison gdavison deleted the b-cloudwatch-alarm-period branch March 15, 2023 17:43
@github-actions github-actions bot added this to the v4.59.0 milestone Mar 15, 2023
github-actions bot pushed a commit that referenced this pull request Mar 15, 2023
@github-actions
Copy link

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

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
5 participants