-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Terraform adds aws_s3_bucket without import when bucket already exists on account #13587
Comments
Just to add my 2c, although this technically follows the letter of the API, finding yourself in a position where two distinct workspaces are now responsible for the same S3 bucket is surely unexpected. |
I had a related issue, there was only one terraform being performed. Here's the series of steps:
Looking at the S3 bucket in AWS it was created about 2 seconds after step 1 above. Indicating to me that the creation was successful from the terraform provider. However, something must have happened for the logic to determine that a retry attempt was needed. Each subsequent retry reported a 409 conflict since the creation was indeed successful. Any number of things could have caused an error in sdk client, e.g. closed connection while the resource was happily created. |
We ended up getting around this by importing the bucket before
|
I just ran into this as well. I accidently used the same bucket name in two Terraform workspaces, and Terraform didn't throw any errors. The two workspaces ended up overwriting each other's KMS key settings on the bucket, which caused lots of issues. I don't understand why the previous ticket here was closed. The close reason is because S3 added strong consistency, but that was for objects, not buckets. S3 has always had strong consistency for buckets. The issue is that Terraform is somehow automatically "importing" an existing resource instead of throwing an error because it already exists. |
Me too - (twice actually). In the most recent occurrence two different workspaces - one from an apply in mid December 2021, one from a separate erroneous set of TF scripts applied yesterday - the latter imported ("adopted") the bucket created by the first. TF 0.12.31, AWS provider 3.69.0 on the first state, 3.74.0 for the later workspace |
This functionality has been released in v4.24.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! |
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. |
Community Note
Terraform Version
0.12.26 - however this is not a version specific issue.
Affected Resource(s)
Terraform Configuration Files
Debug Output
https://gist.github.com/trjstewart/d6611512a1cfb467f78d8ac624776eef
Panic Output
n/a
Expected Behavior
When attempting to create a bucket that already exists we expect to receive a
BucketAlreadyExists
or aBucketAlreadyOwnedByYou
error.Actual Behavior
Due to documented behavior when making an API request to create a bucket that already exists in us-east-1 you receive a 200 response, rather than the expected 409. AWS documentation states that this is due to legacy compatibility. This causes Terraform to assume the resource created successfully and thus adds it to its state without having to explicitly import the existing resource.
Additionally to this, as a byproduct of the "successful" API request, the ACL on the existing bucket is reset, as per the above referenced documentation. This causes further unexpected behavior.
Steps to Reproduce
test_bucket_1591160652
terraform workspace new testing-existing-bucket
aws_s3_bucket
resource using the unique name;terraform apply
terraform workspace new testing-existing-bucket-two
aws_s3_bucket
resource using the same name as in step 3;terraform apply
Important Factoids
There is nothing atypical about our environment in this case. I was able to reproduce this on a different account.
References
The text was updated successfully, but these errors were encountered: