Skip to content

Commit

Permalink
ACL Fixes required after AWS S3 APR 2023 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SSKale1 committed Apr 25, 2023
1 parent 76567df commit 73c3dda
Showing 1 changed file with 83 additions and 1 deletion.
84 changes: 83 additions & 1 deletion modules/module-1/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3200,6 +3200,32 @@ resource "aws_s3_bucket" "bucket_upload" {
}
}

# ACL fixes required for AWS S3 APR 2023 updates.
resource "aws_s3_bucket_public_access_block" "bucket_upload" {
bucket = aws_s3_bucket.bucket_upload.id

block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}

resource "aws_s3_bucket_ownership_controls" "bucket_upload" {
bucket = aws_s3_bucket.bucket_upload.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}

resource "aws_s3_bucket_acl" "bucket_upload" {
depends_on = [
aws_s3_bucket_public_access_block.bucket_upload,
aws_s3_bucket_ownership_controls.bucket_upload,
]

bucket = aws_s3_bucket.bucket_upload.id
acl = "private"
}

resource "aws_s3_bucket_policy" "allow_access_for_prod" {
bucket = aws_s3_bucket.bucket_upload.id
Expand Down Expand Up @@ -3256,6 +3282,35 @@ resource "aws_s3_bucket" "dev" {
Environment = "Dev"
}
}


# ACL fixes required for AWS S3 APR 2023 updates.
resource "aws_s3_bucket_public_access_block" "dev" {
bucket = aws_s3_bucket.dev.id

block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}

resource "aws_s3_bucket_ownership_controls" "dev" {
bucket = aws_s3_bucket.dev.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}

resource "aws_s3_bucket_acl" "dev" {
depends_on = [
aws_s3_bucket_public_access_block.dev,
aws_s3_bucket_ownership_controls.dev,
]

bucket = aws_s3_bucket.dev.id
acl = "public-read"
}

resource "aws_s3_bucket_policy" "allow_access_for_dev" {
bucket = aws_s3_bucket.dev.bucket
policy = data.aws_iam_policy_document.allow_get_list_access.json
Expand Down Expand Up @@ -3299,13 +3354,40 @@ resource "aws_s3_bucket_object" "upload_folder_dev_2" {
resource "aws_s3_bucket" "bucket_temp" {
bucket = "ec2-temp-bucket-${data.aws_caller_identity.current.account_id}"
force_destroy = true
# acl = "private"

tags = {
Name = "Temporary bucket"
Environment = "Dev"
}
}

# ACL fixes required for AWS S3 APR 2023 updates.
resource "aws_s3_bucket_public_access_block" "bucket_temp" {
bucket = aws_s3_bucket.bucket_temp.id

block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}

resource "aws_s3_bucket_ownership_controls" "bucket_temp" {
bucket = aws_s3_bucket.bucket_temp.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}

resource "aws_s3_bucket_acl" "bucket_temp" {
depends_on = [
aws_s3_bucket_public_access_block.bucket_temp,
aws_s3_bucket_ownership_controls.bucket_temp,
]

bucket = aws_s3_bucket.bucket_temp.id
acl = "public-read"
}

/* Uploading all files to ec2-temp-bucket-ACCOUNT_ID bucket */
resource "aws_s3_bucket_object" "upload_temp_object" {
for_each = fileset("./resources/s3/webfiles/build/", "**")
Expand Down

0 comments on commit 73c3dda

Please sign in to comment.