Skip to content

Instantly share code, notes, and snippets.

@ohakutsu
Created July 17, 2020 04:24
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 ohakutsu/2845f2b6f60bb58f27b2df0c3f0180c3 to your computer and use it in GitHub Desktop.
Save ohakutsu/2845f2b6f60bb58f27b2df0c3f0180c3 to your computer and use it in GitHub Desktop.
AWSのS3の静的サイトホスティングをTerraformでやる
variable "bucket_name" {
default = "s3-old.ohakutsu.com"
}
provider "aws" {
region = "ap-northeast-1"
}
data "aws_iam_policy_document" "s3_policy" {
statement {
actions = ["s3:GetObject"]
effect = "Allow"
principals {
type = "AWS"
identifiers = ["*"]
}
resources = ["arn:aws:s3:::${var.bucket_name}/*"]
sid = "PublicReadGetObject"
}
}
resource "aws_s3_bucket" "b" {
bucket = var.bucket_name
acl = "private"
policy = data.aws_iam_policy_document.s3_policy.json
website {
index_document = "index.html"
error_document = "error.html"
}
}
output "url" {
value = aws_s3_bucket.b.website_endpoint
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment