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

r/aws_secretsmanager_secret_rotation: Fix failing schedule expression updates #31915

Merged

Conversation

szilveszter
Copy link
Contributor

@szilveszter szilveszter commented Jun 12, 2023

Description

Like many others in the linked bug report below I ran into an issue when I wanted to update rotation_rules.scheduled_expression attribute of an existing aws_secretsmanager_secret_rotation resource. For example changing the existing value of "rate(6 hours)" to "rate(10 hours)" resulted in the following error message during terraform apply:

╷
│ Error: updating Secrets Manager Secret Rotation (arn:aws:secretsmanager:us-east-1:****:secret:token-crZATx): InvalidParameterException: You cannot specify both rotation frequency and schedule expression together.
│ 
│   with module.main.aws_secretsmanager_secret_rotation.token_rotation,
│   on ../../token_rotation_lambda.tf line 68, in resource "aws_secretsmanager_secret_rotation" "token_rotation":
│   68: resource "aws_secretsmanager_secret_rotation" "token_rotation" {
│ 
╵

This happens because the AWS API returns a value for the AutomaticallyAfterDays attribute under RotationRules:

{
    ...
    "RotationRules": {
        "AutomaticallyAfterDays": 1,
        "ScheduleExpression": "rate(10 hours)"
    },
    ...
}

This is then taken by the provider resource for the update request, which fails the AWS side validation. This change removes that attribute from the state when a schedule expression is present, so that there won't be a conflict during an update. Unfortunately the existing acceptance tests were not covering this case, because for both test steps the schedule expression has the same value, so no update is performed. I tried to address this with the addition of the new test TestAccSecretsManagerSecretRotation_scheduleExpressionHours.

Relations

Closes #30540.
Relates #30425.

References

N/A

Output from Acceptance Testing

$  make testacc TESTS=TestAccSecretsManagerSecretRotation_scheduleExpressionHours PKG=secretsmanager
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/secretsmanager/... -v -count 1 -parallel 20 -run='TestAccSecretsManagerSecretRotation_scheduleExpressionHours'  -timeout 180m
=== RUN   TestAccSecretsManagerSecretRotation_scheduleExpressionHours
=== PAUSE TestAccSecretsManagerSecretRotation_scheduleExpressionHours
=== CONT  TestAccSecretsManagerSecretRotation_scheduleExpressionHours
--- PASS: TestAccSecretsManagerSecretRotation_scheduleExpressionHours (80.27s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/secretsmanager	85.346s

@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 service/secretsmanager Issues and PRs that pertain to the secretsmanager service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/M Managed by automation to categorize the size of a PR. labels Jun 12, 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=TestAccSecretsManagerSecretRotation_\|TestAccSecretsManagerSecretRotationDataSource_' PKG=secretsmanager ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/secretsmanager/... -v -count 1 -parallel 2  -run=TestAccSecretsManagerSecretRotation_\|TestAccSecretsManagerSecretRotationDataSource_ -timeout 180m
=== RUN   TestAccSecretsManagerSecretRotationDataSource_basic
=== PAUSE TestAccSecretsManagerSecretRotationDataSource_basic
=== RUN   TestAccSecretsManagerSecretRotation_basic
=== PAUSE TestAccSecretsManagerSecretRotation_basic
=== RUN   TestAccSecretsManagerSecretRotation_scheduleExpression
=== PAUSE TestAccSecretsManagerSecretRotation_scheduleExpression
=== RUN   TestAccSecretsManagerSecretRotation_scheduleExpressionHours
=== PAUSE TestAccSecretsManagerSecretRotation_scheduleExpressionHours
=== RUN   TestAccSecretsManagerSecretRotation_duration
=== PAUSE TestAccSecretsManagerSecretRotation_duration
=== CONT  TestAccSecretsManagerSecretRotationDataSource_basic
=== CONT  TestAccSecretsManagerSecretRotation_scheduleExpressionHours
--- PASS: TestAccSecretsManagerSecretRotationDataSource_basic (62.17s)
=== CONT  TestAccSecretsManagerSecretRotation_duration
--- PASS: TestAccSecretsManagerSecretRotation_scheduleExpressionHours (79.40s)
=== CONT  TestAccSecretsManagerSecretRotation_scheduleExpression
--- PASS: TestAccSecretsManagerSecretRotation_duration (56.44s)
=== CONT  TestAccSecretsManagerSecretRotation_basic
--- PASS: TestAccSecretsManagerSecretRotation_scheduleExpression (69.92s)
--- PASS: TestAccSecretsManagerSecretRotation_basic (55.50s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/secretsmanager	179.787s

@ewbankkit
Copy link
Contributor

@szilveszter Thanks for the contribution 🎉 👏.

@ewbankkit ewbankkit merged commit 929a1c0 into hashicorp:main Jul 3, 2023
39 checks passed
@github-actions github-actions bot added this to the v5.7.0 milestone Jul 3, 2023
@github-actions
Copy link

github-actions bot commented Jul 7, 2023

This functionality has been released in v5.7.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

github-actions bot commented Aug 7, 2023

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 Aug 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/secretsmanager Issues and PRs that pertain to the secretsmanager service. size/M 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
Development

Successfully merging this pull request may close these issues.

[Bug]: aws_secretsmanager_secret_rotation switch from automatically_after_days to schedule_expression failed
2 participants