-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
aws_secretsmanager_secret does not rebuild deleted secret #5127
Comments
Relevant Secrets Manager documentation: https://docs.aws.amazon.com/secretsmanager/latest/userguide/manage_delete-restore-secret.html Deleting a secret only marks it as deprecated and does not immediately fully delete it. We should probably add a documentation note about this in the resource documentation. We might be able to mark these deprecated secrets for recreation in the resource read function, but the creation in that scenario I believe will always fail if the secret name is the same. We'll need to check the user experience of that (e.g. it returns a helpful error when a deprecated secret already exists) or if we should return our own error about deprecated secrets instead. A workaround is to create a different secret in the deprecation period. |
If terraform checks to see if the key is scheduled for deletion before trying to create, this error would be resolved. This would be very helpful especially for people first starting out with terraform. |
I believe it also happens in case of "terraform destroy" followed by "terraform apply". Maybe appropriate action would be to use "undelete" API call instead of "create" if secret is scheduled for deletion. This logic may not necessary be default. However, having a flag on terraform secret resource (enabling automatical "undelete" behaviour) would be very nice thing to have. Otherwise, terraform runs are not 100% idempotent. (I.e. I cannot wipe my testing infrastructure in the end of the day to just recreate it next morning). |
Uh, got it. My suggestion won't work out. Terraform has no idea of secret existence because after deletion secret's ARN is no more in the terraform state. So, prior to any planning secret should be imported into the state. Any ideas to automate this process should not be considered neither suggested -- as implicit import will break the fundamental concepts of Terraform (it may lead to the situation where Alice and Bob compete for the control over same resource just because of using same name). I solved the problem with little manual overhead, fairly acceptable:
Maybe step 1 was not even necessary, but I do not have time to check it now. |
Pull request submitted with support of the new |
In version 1.33.0 of the AWS provider, likely releasing later today, the
Please note for updating existing |
This has been released in version 1.33.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
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! |
Community Note
Terraform Version
Terraform v0.11.7
Affected Resource(s)
Terraform Configuration Files
Expected Behavior
Terraform should look to see if the secret exists and create it.
Actual Behavior
Terraform sees the secret id in the state file and does not verify that the secret still exists in AWS
Steps to Reproduce
terraform apply
terraform plan
orterraform apply
Important Factoids
This only seems to happen if the secret is deleted outside of terraform.
The text was updated successfully, but these errors were encountered: