-
Notifications
You must be signed in to change notification settings - Fork 1
/
s3.tf
170 lines (149 loc) · 4.37 KB
/
s3.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
resource "random_string" "s3" {
length = 6
upper = false
special = false
}
resource "aws_kms_key" "data_landing_bucket_key" {
description = "This key is used to encrypt APPS buckets"
deletion_window_in_days = 7
enable_key_rotation = true
}
resource "aws_s3_bucket" "data_landing_bucket" {
bucket = "s3-data-landing-${local.naming_suffix}-${random_string.s3.result}"
# region = data.aws_region.current.name
lifecycle_rule {
enabled = true
transition {
days = 0
storage_class = "INTELLIGENT_TIERING"
}
noncurrent_version_transition {
days = 0
storage_class = "INTELLIGENT_TIERING"
}
noncurrent_version_expiration {
days = 1
}
}
tags = {
Name = "s3-data-landing-bucket-${local.naming_suffix}"
}
}
resource "aws_s3_bucket_versioning" "data_landing_bucket_versioning" {
bucket = aws_s3_bucket.data_landing_bucket.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_logging" "data_landing_bucket_logging" {
bucket = aws_s3_bucket.data_landing_bucket.id
target_bucket = var.logging_bucket_id
target_prefix = "data_landing_bucket/"
}
resource "aws_s3_bucket_server_side_encryption_configuration" "data_landing_bucket_ss_encryption_config" {
bucket = aws_s3_bucket.data_landing_bucket.id
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.data_landing_bucket_key.arn
sse_algorithm = "aws:kms"
}
}
}
resource "aws_s3_bucket_metric" "data_landing_bucket_logging" {
bucket = "s3-data-landing-${local.naming_suffix}-${random_string.s3.result}"
name = "data_landing_bucket_metric"
}
resource "aws_s3_bucket_policy" "data_landing_bucket" {
bucket = "s3-data-landing-${local.naming_suffix}-${random_string.s3.result}"
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "HTTP",
"Effect": "Deny",
"Principal": "*",
"Action": "*",
"Resource": "arn:aws:s3:::s3-data-landing-${local.naming_suffix}-${random_string.s3.result}/*",
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
}
}
]
}
POLICY
}
resource "aws_kms_key" "dacc_data_landing_bucket_key" {
description = "This key is used to encrypt APPS buckets"
deletion_window_in_days = 7
enable_key_rotation = true
}
resource "aws_s3_bucket" "dacc_data_landing_bucket" {
bucket = "s3-dacc-data-landing-${local.naming_suffix}-${random_string.s3.result}"
# region = data.aws_region.current.name
lifecycle_rule {
enabled = true
transition {
days = 0
storage_class = "INTELLIGENT_TIERING"
}
noncurrent_version_transition {
days = 0
storage_class = "INTELLIGENT_TIERING"
}
noncurrent_version_expiration {
days = 1
}
}
tags = {
Name = "s3-dacc-data-landing-bucket-${local.naming_suffix}"
}
}
resource "aws_s3_bucket_versioning" "dacc_data_landing_bucket_versioning" {
bucket = aws_s3_bucket.dacc_data_landing_bucket.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_logging" "dacc_data_landing_bucket_logging" {
bucket = aws_s3_bucket.dacc_data_landing_bucket.id
target_bucket = var.logging_bucket_id
target_prefix = "dacc_data_landing_bucket/"
}
resource "aws_s3_bucket_server_side_encryption_configuration" "dacc_data_landing_bucket_ss_encryption_config" {
bucket = aws_s3_bucket.dacc_data_landing_bucket.id
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.dacc_data_landing_bucket_key.arn
sse_algorithm = "aws:kms"
}
}
}
resource "aws_s3_bucket_metric" "dacc_data_landing_bucket_logging" {
bucket = "s3-dacc-data-landing-${local.naming_suffix}-${random_string.s3.result}"
name = "dacc_data_landing_bucket_metric"
}
resource "aws_s3_bucket_policy" "dacc_data_landing_bucket" {
bucket = "s3-dacc-data-landing-${local.naming_suffix}-${random_string.s3.result}"
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "HTTP",
"Effect": "Deny",
"Principal": "*",
"Action": "*",
"Resource": "arn:aws:s3:::s3-dacc-data-landing-${local.naming_suffix}-${random_string.s3.result}/*",
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
}
}
]
}
POLICY
}