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

[Bug]: SecretsManager secret version does not gracefully remove deleted versions from state #36607

Closed
jar-b opened this issue Mar 27, 2024 · 5 comments · Fixed by #36609
Closed
Assignees
Labels
bug Addresses a defect in current functionality. service/secretsmanager Issues and PRs that pertain to the secretsmanager service.
Milestone

Comments

@jar-b
Copy link
Member

jar-b commented Mar 27, 2024

Terraform Core Version

1.8.0-rc1

AWS Provider Version

5.42.0

Affected Resource(s)

  • aws_secretsmanager_secret_version

Expected Behavior

When a secret version is deleted by the automated AWS cleanup process, the provider should remove the resource from state

Actual Behavior

The provider throws an error:

│ Error: error reading Secrets Manager Secret Version (arn:aws:secretsmanager:us-east-1:<redacted>:secret:example2-o0Q1tI|<redacted>): InvalidRequestException: You can't perform this operation on secret version <redacted> because it was deleted.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_secretsmanager_secret_version" "example" {
  secret_id     = aws_secretsmanager_secret.example.id
  secret_string = "example-string-to-protect"
}

Steps to Reproduce

  1. Create a new secret version.
  2. Update the secret until more than 100 new versions have been created (out of band). This should trigger AWS's automated cleanup process some time after 24 hours.

Secrets Manager removes unlabeled versions when there are more than 100, but it does not remove versions created less than 24 hours ago.

  1. Observe failure on terraform plan.

Debug Output

No response

Panic Output

No response

Important Factoids

The AWS provider includes logic like the following to catch deleted secrets and remove them from state gracefully. However, there is no handling for deleted secret versions.

errs.IsAErrorMessageContains[*types.InvalidRequestException](err, "You can’t perform this operation on the secret because it was deleted") ||

Updating this check to a shorter portion of the error message should allow for detection of both secrets and secret versions deleted out of band.

References

Would you like to implement a fix?

None

@jar-b jar-b added the bug Addresses a defect in current functionality. label Mar 27, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/secretsmanager Issues and PRs that pertain to the secretsmanager service. label Mar 27, 2024
@jar-b jar-b self-assigned this Mar 27, 2024
@terraform-aws-provider terraform-aws-provider bot added the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Mar 27, 2024
@jar-b jar-b added the upstream Addresses functionality related to the cloud provider. label Mar 27, 2024
@jar-b jar-b removed the upstream Addresses functionality related to the cloud provider. label Mar 27, 2024
@xnick123
Copy link

I can confirm this error, I struggled to understand the pattern leading to this. It happens across multiple environments on a secret where I perform secret rotation every 4 hours. It did not happen on other secrets which I don't rotate. Hence I believe that the explanation makes sense.

Copy link

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.43.0 milestone Mar 27, 2024
@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Mar 28, 2024
Copy link

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

Copy link

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 have found a problem that seems similar to this, 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 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/secretsmanager Issues and PRs that pertain to the secretsmanager service.
Projects
None yet
2 participants