forked from stacksimplify/terraform-aws-s3-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
81 lines (70 loc) · 1.78 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
# S3 static website bucket
# Resource-1: aws_s3_bucket
resource "aws_s3_bucket" "mywebsite" {
bucket = var.bucket_name
tags = var.tags
force_destroy = true
}
# Resource-2: aws_s3_bucket_website_configuration
resource "aws_s3_bucket_website_configuration" "mywebsite" {
bucket = aws_s3_bucket.mywebsite.id
index_document {
suffix = "index.html"
}
error_document {
key = "error.html"
}
}
# Resource-3: aws_s3_bucket_versioning
resource "aws_s3_bucket_versioning" "mywebsite" {
bucket = aws_s3_bucket.mywebsite.id
versioning_configuration {
status = "Enabled"
}
}
# Resource-4: aws_s3_bucket_ownership_controls
resource "aws_s3_bucket_ownership_controls" "mywebsite" {
bucket = aws_s3_bucket.mywebsite.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
# Resource-5: aws_s3_bucket_public_access_block
resource "aws_s3_bucket_public_access_block" "mywebsite" {
bucket = aws_s3_bucket.mywebsite.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
# Resource-6: aws_s3_bucket_acl
resource "aws_s3_bucket_acl" "mywebsite" {
depends_on = [
aws_s3_bucket_ownership_controls.mywebsite,
aws_s3_bucket_public_access_block.mywebsite
]
bucket = aws_s3_bucket.mywebsite.id
acl = "public-read"
}
# Resource-7: aws_s3_bucket_policy
resource "aws_s3_bucket_policy" "mywebsite" {
bucket = aws_s3_bucket.mywebsite.id
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::${var.bucket_name}/*"
]
}
]
}
EOF
}