Created
July 17, 2023 22:50
-
-
Save AngelChaidez/09e50fc67ebcd7228f6afbf84dc77828 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_s3_bucket" "s3_bucket" { | |
bucket = var.bucket_name | |
tags = var.tags | |
} | |
resource "aws_s3_bucket_public_access_block" "s3_bucket_public_access_block"{ | |
bucket = aws_s3_bucket.s3_bucket.id | |
block_public_acls = false | |
block_public_policy = false | |
} | |
resource "aws_s3_bucket_website_configuration" "s3_bucket" { | |
bucket = aws_s3_bucket.s3_bucket.id | |
index_document { | |
suffix = "index.html" | |
} | |
error_document { | |
key = "error.html" | |
} | |
} | |
resource "aws_s3_bucket_acl" "s3_bucket_acl" { | |
bucket = aws_s3_bucket.s3_bucket.id | |
acl = "public-read" | |
depends_on = [aws_s3_bucket_ownership_controls.s3_bucket_acl_ownership] | |
} | |
# Resource to avoid error "AccessControlListNotSupported: The bucket does not allow ACLs" | |
resource "aws_s3_bucket_ownership_controls" "s3_bucket_acl_ownership" { | |
bucket = aws_s3_bucket.s3_bucket.id | |
rule { | |
object_ownership = "ObjectWriter" | |
} | |
} | |
resource "null_resource" "delay" { | |
depends_on = [aws_s3_bucket.s3_bucket] | |
provisioner "local-exec" { | |
command = "sleep 30" # Wait for 30 seconds, adjust the duration as needed | |
} | |
} | |
resource "aws_s3_bucket_policy" "s3_bucket" { | |
bucket = aws_s3_bucket.s3_bucket.id | |
policy = jsonencode({ | |
Version = "2012-10-17" | |
Statement = [ | |
{ | |
Sid = "PublicReadGetObject" | |
Effect = "Allow" | |
Principal = "*" | |
Action = ["s3:GetObject","s3:PutBucketAcl", | |
"s3:PutBucketPolicy"] | |
Resource = [ | |
aws_s3_bucket.s3_bucket.arn, | |
"${aws_s3_bucket.s3_bucket.arn}/*", | |
] | |
}, | |
] | |
}) | |
depends_on = [null_resource.delay] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment