Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRE-866 static website module tf upgrade #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 46 additions & 22 deletions static-website/bucket.tf
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
resource "aws_s3_bucket" "website" {
bucket = local.bucket_name

tags = {
Name = local.bucket_name
}
}

resource "aws_s3_bucket_versioning" "versioning" {
bucket = aws_s3_bucket.website.id
versioning_configuration {
status = var.versioning
}
}

resource "aws_s3_bucket_acl" "acl" {
bucket = aws_s3_bucket.website.id
acl = "private"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "${aws_cloudfront_origin_access_identity.website.iam_arn}"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::${local.bucket_name}/*"
}
]
}
EOF
versioning {
enabled = var.versioning

resource "aws_s3_bucket_policy" "policy" {
bucket = aws_s3_bucket.website.id
policy = data.aws_iam_policy_document.policy.json
}

data "aws_iam_policy_document" "policy" {
statement {
principals {
type = "AWS"
identifiers = [
"${aws_cloudfront_origin_access_identity.website.iam_arn}"
]
}

actions = [
"s3:GetObject"
]

resources = [
"arn:aws:s3:::${local.bucket_name}/*"
]
}
}

resource "aws_s3_bucket_website_configuration" "website" {
bucket = aws_s3_bucket.website.bucket

website {
index_document = var.index_document
error_document = var.error_document
index_document {
suffix = var.index_document
}

tags = {
Name = local.bucket_name
error_document {
key = var.error_document
}
}
}