-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
86 lines (75 loc) · 1.71 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
variable "bucket_name" {
type = string
}
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "website" {
bucket = var.bucket_name
}
resource "aws_s3_bucket_public_access_block" "example" {
bucket = aws_s3_bucket.website.id
block_public_acls = true
block_public_policy = false
ignore_public_acls = true
restrict_public_buckets = false
}
resource "aws_s3_bucket_object" "website" {
for_each = fileset(path.root, "*.html")
bucket = aws_s3_bucket.website.bucket
key = each.value
source = "${path.root}/${each.value}"
etag = filemd5("${path.root}/${each.value}")
content_type = "text/html"
}
resource "aws_s3_bucket_policy" "public_read" {
bucket = aws_s3_bucket.website.id
policy = data.aws_iam_policy_document.allow_public_read.json
}
resource "aws_s3_bucket_website_configuration" "static_website" {
bucket = aws_s3_bucket.website.bucket
index_document {
suffix = "index.html"
}
error_document {
key = "not_found.html"
}
}
data "aws_iam_policy_document" "allow_public_read" {
statement {
actions = [
"s3:GetObject",
]
resources = [
"arn:aws:s3:::${var.bucket_name}/*"
]
principals {
type = "*"
identifiers = ["*"]
}
}
statement {
actions = [
"s3:ListBucket",
]
resources = [
"arn:aws:s3:::${var.bucket_name}"
]
principals {
type = "*"
identifiers = ["*"]
}
}
}
output "website" {
value = "http://${var.bucket_name}.s3-website.${aws_s3_bucket.website.region}.amazonaws.com/"
sensitive = false
}