forked from nozaq/terraform-aws-secure-baseline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
153 lines (122 loc) · 3.39 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
data "aws_iam_policy_document" "access_log_policy" {
statement {
actions = ["s3:*"]
effect = "Deny"
resources = [
aws_s3_bucket.access_log.arn,
"${aws_s3_bucket.access_log.arn}/*"
]
condition {
test = "Bool"
variable = "aws:SecureTransport"
values = ["false"]
}
principals {
type = "*"
identifiers = ["*"]
}
}
}
resource "aws_s3_bucket" "access_log" {
bucket = var.log_bucket_name
force_destroy = var.force_destroy
tags = var.tags
}
resource "aws_s3_bucket_acl" "access_log" {
bucket = aws_s3_bucket.access_log.id
acl = "log-delivery-write"
}
resource "aws_s3_bucket_server_side_encryption_configuration" "access_log" {
bucket = aws_s3_bucket.access_log.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
resource "aws_s3_bucket_lifecycle_configuration" "access_log" {
count = var.lifecycle_glacier_transition_days > 0 ? 1 : 0
bucket = aws_s3_bucket.access_log.id
rule {
id = "auto-archive"
status = "Enabled"
filter {}
transition {
days = var.lifecycle_glacier_transition_days
storage_class = "GLACIER"
}
}
}
resource "aws_s3_bucket_policy" "access_log_policy" {
bucket = aws_s3_bucket.access_log.id
policy = data.aws_iam_policy_document.access_log_policy.json
depends_on = [
aws_s3_bucket_public_access_block.access_log,
]
}
resource "aws_s3_bucket_public_access_block" "access_log" {
bucket = aws_s3_bucket.access_log.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket" "content" {
bucket = var.bucket_name
force_destroy = var.force_destroy
tags = var.tags
depends_on = [
aws_s3_bucket_public_access_block.access_log
]
}
resource "aws_s3_bucket_acl" "content" {
bucket = aws_s3_bucket.content.id
acl = "private"
}
resource "aws_s3_bucket_server_side_encryption_configuration" "content" {
bucket = aws_s3_bucket.content.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
bucket_key_enabled = var.bucket_key_enabled
}
}
resource "aws_s3_bucket_logging" "content" {
bucket = aws_s3_bucket.content.id
target_bucket = aws_s3_bucket.access_log.id
target_prefix = ""
}
resource "aws_s3_bucket_lifecycle_configuration" "content" {
count = var.lifecycle_glacier_transition_days > 0 ? 1 : 0
bucket = aws_s3_bucket.content.id
rule {
id = "auto-archive"
status = "Enabled"
filter {}
transition {
days = var.lifecycle_glacier_transition_days
storage_class = "GLACIER"
}
noncurrent_version_transition {
noncurrent_days = var.lifecycle_glacier_transition_days
storage_class = "GLACIER"
}
}
}
resource "aws_s3_bucket_versioning" "content" {
bucket = aws_s3_bucket.content.id
versioning_configuration {
status = "Enabled"
# Temporarily disabled due to Terraform issue.
# https://github.com/terraform-providers/terraform-provider-aws/issues/629
# mfa_delete = true
}
}
resource "aws_s3_bucket_public_access_block" "content" {
bucket = aws_s3_bucket.content.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}