-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3-static-site.tf
77 lines (62 loc) · 2.06 KB
/
s3-static-site.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
resource "aws_s3_bucket" "static_site" {
bucket = "${local.project_name}-static-site"
force_destroy = local.s3_static_site_force_destroy
}
resource "aws_s3_bucket_versioning" "static_site" {
bucket = aws_s3_bucket.static_site.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_logging" "static_site" {
count = local.enable_s3_access_logs ? 1 : 0
bucket = aws_s3_bucket.static_site.id
target_bucket = aws_s3_bucket.logs[0].id
target_prefix = "s3/static_site/"
}
resource "aws_s3_bucket_ownership_controls" "static_site" {
bucket = aws_s3_bucket.static_site.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket_acl" "static_site" {
bucket = aws_s3_bucket.static_site.id
acl = local.static_site_s3_acl
}
resource "aws_s3_bucket_public_access_block" "static_site" {
bucket = aws_s3_bucket.static_site.id
block_public_acls = local.static_site_s3_acl == "public" ? false : true
block_public_policy = local.static_site_s3_acl == "public" ? false : true
ignore_public_acls = local.static_site_s3_acl == "public" ? false : true
restrict_public_buckets = local.static_site_s3_acl == "public" ? false : true
}
resource "aws_s3_bucket_website_configuration" "static_site" {
bucket = aws_s3_bucket.static_site.bucket
index_document {
suffix = "index.html"
}
}
#tfsec:ignore:aws-s3-encryption-customer-key
resource "aws_s3_bucket_server_side_encryption_configuration" "static_site" {
count = local.static_site_s3_enable_encryption ? 1 : 0
bucket = aws_s3_bucket.static_site.bucket
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
resource "aws_s3_bucket_policy" "static_site" {
bucket = aws_s3_bucket.static_site.id
policy = local.static_site_bucket_policy
}
resource "aws_s3_object" "static_site_index" {
bucket = aws_s3_bucket.static_site.id
key = "index.html"
content = local.project_name
content_type = "text/html"
lifecycle {
prevent_destroy = true
}
}