Terraform plan shows no drift when aws_s3_bucket ACL conflicts with aws_s3_bucket_public_access_block
0 reputation · 21 Jun 2023, 12:47 UTC
0 reputation · 21 Jun 2023, 12:47 UTC
When an aws_s3_bucket resource is created with acl="public-read" and an aws_s3_bucket_public_access_block resource sets block_public_acls=true, Terraform plan reports both resources as in-sync after the initial apply. The AWS provider documentation states that public access block settings do not modify existing policies or ACLs, yet no drift is surfaced during subsequent plans.
The AWS API evaluates public access block settings after bucket policies and ACLs are applied. This means a bucket can show "Public access blocked" in the console while its ACL still grants READ to the AllUsers group. Terraform's state comparison does not detect this effective public access because both resources individually match their configured arguments.
Terraform 1.5 introduced ephemeral values and preconditions that can validate the bucket ACL before applying the public access block, but these cannot enforce ordering across separate resources managed in different modules. Custom pre-commit checks or AWS Config rules remain the only reliable detection methods.
Questions:
acl and public_access_block settings during plan without custom validation?public_access_block is applied?35775 reputation · 21 Jun 2023, 18:03 UTC
aws_s3_bucket_public_access_block does not modify existing bucket ACLs—it only blocks future public access attempts. Both resources match their configured arguments individually, so no drift is surfaced during plan.acl and public_access_block settings during planaws s3api get-bucket-acl --bucket bucket-nameaws s3api get-public-access-block --bucket bucket-nameterraform state show aws_s3_bucket.bucket_name1. Provider-level detection: No. The AWS provider does not validate effective public access status against configured block settings.
2. Cross-module ordering: Terraform cannot enforce resource ordering across module boundaries. Use depends_on within a single module or consolidate into one module.
3. Roadmap for drift detection: Not currently planned. Effective public access status differs from configured block settings, and Terraform state tracks only the latter.
Remove acl="public-read" and use bucket policies for access control, or add explicit validation. AWS Config rules or custom pre-commit checks remain the only reliable detection methods for this configuration conflict.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.