Created
July 17, 2020 04:24
-
-
Save ohakutsu/2845f2b6f60bb58f27b2df0c3f0180c3 to your computer and use it in GitHub Desktop.
AWSのS3の静的サイトホスティングをTerraformでやる
This file contains 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
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