Skip to content

Commit

Permalink
fix: Fixed Bucket Policy chain dependency with Public Access Block (#227
Browse files Browse the repository at this point in the history
)

Co-authored-by: Vladimir Samoylov <51059484+cageyv@users.noreply.github.com>
Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
  • Loading branch information
3 people authored Apr 28, 2023
1 parent 3caf180 commit fa19074
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,16 @@ resource "aws_s3_bucket_replication_configuration" "this" {
resource "aws_s3_bucket_policy" "this" {
count = local.create_bucket && local.attach_policy ? 1 : 0

# Chain resources (s3_bucket -> s3_bucket_public_access_block -> s3_bucket_policy )
# to prevent "A conflicting conditional operation is currently in progress against this resource."
# Ref: https://github.com/hashicorp/terraform-provider-aws/issues/7628

bucket = aws_s3_bucket.this[0].id
policy = data.aws_iam_policy_document.combined[0].json

depends_on = [
aws_s3_bucket_public_access_block.this
]
}

data "aws_iam_policy_document" "combined" {
Expand Down Expand Up @@ -789,11 +797,7 @@ data "aws_iam_policy_document" "require_latest_tls" {
resource "aws_s3_bucket_public_access_block" "this" {
count = local.create_bucket && var.attach_public_policy ? 1 : 0

# Chain resources (s3_bucket -> s3_bucket_policy -> s3_bucket_public_access_block)
# to prevent "A conflicting conditional operation is currently in progress against this resource."
# Ref: https://github.com/hashicorp/terraform-provider-aws/issues/7628

bucket = local.attach_policy ? aws_s3_bucket_policy.this[0].id : aws_s3_bucket.this[0].id
bucket = aws_s3_bucket.this[0].id

block_public_acls = var.block_public_acls
block_public_policy = var.block_public_policy
Expand Down

0 comments on commit fa19074

Please sign in to comment.