-
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
Error during terraform apply after importing manually created private S3 bucket using TF v1.0.11 #22271
Comments
Hey @abjavaprof 👋 Thank you for taking the time to submit this issue! So that we have all of the necessary information in order to investigate this, can you update the issue description with the rest of the information requested in the bug template, including the community note and (scrubbed as necessary) debug logs? |
@justinretzolk I have updated the bug description as per the template. Please let me know if you need more info from my end. Looking forward to hearing your response. Thank you! |
This issue is a result of the recent S3 feature to disable ACLs altogether. The |
Hey @abjavaprof, I have a workaround for this. You need to create an additional resource:
and run the terraform import command |
This fix doesn't seem to work for me (upgrading from aws provider 3 to 4.11.0) I have these blocks:
I have imported both, tried not importing both or neither, no change. I keep getting |
@hashicorp-cloud #22069 @justinretzolk
You need add this resource on your “file”.tf (s3.tf on my case)
After this, you must first go to the S3 console bucket and in the “Permissions” tab look for the “Object Ownership” feature, which by default will have the value of “Object Writer”. You should change this to “Bucket owner enforced” Now, you should use the import command: Once this import is applied, you will be able to do terraform plan and apply without any issue. The reason is because With this feature, AWS disables access control lists (ACLs). When this setting is applied at the bucket level, all objects in an S3 bucket are owned by the bucket owner, and ACLs are no longer used to grant permissions. ACLs were the original way to control access on S3. Subsequently, IAM and policies were introduced to control permissions on AWS resources. Now by enabling the S3 Object Ownership feature you can change the way S3 does access control to a bucket so that only IAM policies are used and this is exactly where using Terraform, which by the way uses IAM permissions to authenticate and take administration of our environment in AWS (either by AK / SK, Role, etc) the error mentioned at the beginning of this comment is obtained because AWS S3 by default configuration has the Object Ownership at the Object Writer level only which keeps ACLs enabled and in use to grant access to the bucket and its objects, making it impossible for terraform to take the necessary administration to apply imported changes. |
Thanks! |
@Pabloin Thanks for the tips. I did every combination of importing/deleting stuff from TF and updating things in the console trying to make TF happy last week (including setting the bucket owner in the console and them importing it) without success. It seems like there's a larger TF bug to work around here. |
@jlambert121 the solution I posted above works for aws provider v3, v4 is a whole different topic. |
Try rerunning terraform apply. It will solve the issue. |
… an already existent bucket (Details: hashicorp/terraform-provider-aws#22271)
I found better solution 😄 Adding depends_on! resource “aws_s3_bucket” “mybucket2” {
bucket = “mybucket-awsconsole-to-tf”
}
resource “aws_s3_bucket_acl” “mybucket2-acl” {
bucket = aws_s3_bucket.mybucket2.id
acl = “private”
}
resource “aws_s3_bucket_ownership_controls” “mybucket2-acl-ownership” {
bucket = aws_s3_bucket.mybucket2.id
rule {
object_ownership = “BucketOwnerEnforced”
}
# Add just this depends_on condition
depends_on = [aws_s3_bucket_acl.mybucket2-acl]
} |
Hey y'all 👋 It looks like this is resolved by the addition of the |
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. |
Hello Team,
name: Error: Error putting S3 ACL: AccessControlListNotSupported: The bucket does not allow ACLs
about: We are facing an issue when importing a manually created S3 bucket using Terraform v1.0.11 (hashicorp/aws v3.69.0).
Community Note
Terraform CLI and Terraform AWS Provider Version
TF Version - Terraform v1.0.11
Provider AWS - hashicorp/aws v3.69.0
Affected Resource(s)
Terraform Configuration Files
Debug Output
Panic Output
N/A
Expected Behavior
a. aws_cloudfront_origin_access_identity
b. aws_s3_bucket
c. aws_s3_bucket_public_access_block
d. aws_s3_bucket_policy
terraform apply
command runs successfully after importing S3 bucket resources.Actual Behavior
a. aws_s3_bucket
b. aws_s3_bucket_public_access_block
c. aws_s3_bucket_policy
terraform apply --auto-approve
gives following error:a. Error: Error putting S3 ACL: AccessControlListNotSupported: The bucket does not allow ACLs
Steps to Reproduce
terraform import aws_cloudfront_origin_access_identitycf-oai my-test-OAI
terraform import aws_s3_bucket_policy.cf-s3-bucket-policy my-test-bucket-82943572
terraform import aws_s3_bucket_public_access_block.cf-s3 my-test-bucket-82943572
terraform import aws_s3_bucket.cf-s3 my-test-bucket-82943572
terraform apply --auto-approve
Important Factoids
N/A
The text was updated successfully, but these errors were encountered: