Skip to content

Commit

Permalink
Add depends_on for bucket encryption (nebari-dev#2615)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
viniciusdc and pre-commit-ci[bot] authored Aug 8, 2024
1 parent a65ff53 commit 7c61dd6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
19 changes: 11 additions & 8 deletions src/_nebari/stages/infrastructure/template/aws/modules/s3/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ resource "aws_s3_bucket" "main" {
}, var.tags)
}

resource "aws_s3_bucket_public_access_block" "main" {
bucket = aws_s3_bucket.main.id
ignore_public_acls = true
block_public_acls = true
block_public_policy = true
restrict_public_buckets = true
}

resource "aws_s3_bucket_server_side_encryption_configuration" "main" {
bucket = aws_s3_bucket.main.id

Expand All @@ -26,12 +34,7 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "main" {
sse_algorithm = "aws:kms"
}
}
}

resource "aws_s3_bucket_public_access_block" "main" {
bucket = aws_s3_bucket.main.id
ignore_public_acls = true
block_public_acls = true
block_public_policy = true
restrict_public_buckets = true
// AWS may return HTTP 409 if PutBucketEncryption is called immediately after S3
// bucket creation. Adding dependency avoids concurrent requests.
depends_on = [aws_s3_bucket_public_access_block.main]
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ resource "aws_s3_bucket" "terraform-state" {
}
}

resource "aws_s3_bucket_public_access_block" "terraform-state" {
bucket = aws_s3_bucket.terraform-state.id
ignore_public_acls = true
block_public_acls = true
block_public_policy = true
restrict_public_buckets = true
}

resource "aws_s3_bucket_server_side_encryption_configuration" "terraform-state" {
bucket = aws_s3_bucket.terraform-state.id

Expand All @@ -29,14 +37,9 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "terraform-state"
sse_algorithm = "aws:kms"
}
}
}

resource "aws_s3_bucket_public_access_block" "terraform-state" {
bucket = aws_s3_bucket.terraform-state.id
ignore_public_acls = true
block_public_acls = true
block_public_policy = true
restrict_public_buckets = true
# // AWS may return HTTP 409 if PutBucketEncryption is called immediately after S3
# bucket creation. Adding dependency avoids concurrent requests.
depends_on = [aws_s3_bucket_public_access_block.terraform-state]
}

resource "aws_dynamodb_table" "terraform-state-lock" {
Expand Down

0 comments on commit 7c61dd6

Please sign in to comment.