Skip to content

Instantly share code, notes, and snippets.

@refayathaque
Last active March 21, 2021 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refayathaque/b520a9ffa9a8b4d8f0eacdcd85aa5b64 to your computer and use it in GitHub Desktop.
Save refayathaque/b520a9ffa9a8b4d8f0eacdcd85aa5b64 to your computer and use it in GitHub Desktop.
Part of "Automate hosting a static website on AWS with Terraform" post
resource "aws_s3_bucket" "website_static_files" {
bucket = var.BUCKET_NAME
acl = "private"
policy = data.aws_iam_policy_document.bucket_website_hosting.json
website {
index_document = "index.html"
}
force_destroy = true
}
data "aws_iam_policy_document" "bucket_website_hosting" {
statement {
actions = [
"s3:GetObject",
"s3:ListBucket",
]
principals {
identifiers = [aws_cloudfront_origin_access_identity.origin_access_identity.iam_arn]
type = "AWS"
}
resources = [
"arn:aws:s3:::${var.BUCKET_NAME}",
"arn:aws:s3:::${var.BUCKET_NAME}/*",
]
}
}
resource "null_resource" "upload_static_files" {
provisioner "local-exec" {
command = "aws s3 cp index.html s3://${var.BUCKET_NAME}"
}
depends_on = [aws_s3_bucket.website_static_files]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment