This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
generated from dwp/dataworks-repo-template-terraform
-
Notifications
You must be signed in to change notification settings - Fork 3
/
s3.tf
114 lines (96 loc) · 2.18 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
resource "random_id" "rtg_temp_bucket" {
byte_length = 16
}
resource "aws_kms_key" "rtg_temp_bucket_cmk" {
description = "RTG temp Bucket Master Key"
deletion_window_in_days = 7
is_enabled = true
enable_key_rotation = true
tags = merge(
local.common_tags,
{
"Name" = "rtg_temp_bucket_cmk"
},
{
"requires-custom-key-policy" = "false"
},
)
}
resource "aws_kms_alias" "rtg_temp_bucket_alias" {
name = "alias/rtg_temp_bucket"
target_key_id = aws_kms_key.rtg_temp_bucket_cmk.key_id
}
resource "aws_s3_bucket" "rtg_temp" {
bucket = random_id.rtg_temp_bucket.hex
acl = "private"
tags = merge(
local.common_tags,
{
Name = "rtg_temp_bucket"
},
)
versioning {
enabled = false
}
lifecycle_rule {
id = "DeleteBucketData"
prefix = ""
enabled = true
expiration {
days = 1
}
}
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.rtg_temp_bucket_cmk.arn
sse_algorithm = "aws:kms"
}
}
}
}
data "aws_iam_policy_document" "rtg_temp_bucket" {
statement {
sid = "BlockHTTP"
effect = "Deny"
actions = ["*"]
resources = [
aws_s3_bucket.rtg_temp.arn,
"${aws_s3_bucket.rtg_temp.arn}/*",
]
principals {
identifiers = ["*"]
type = "AWS"
}
condition {
test = "Bool"
values = ["false"]
variable = "aws:SecureTransport"
}
}
}
resource "aws_s3_bucket_policy" "rtg_temp" {
bucket = aws_s3_bucket.rtg_temp.id
policy = data.aws_iam_policy_document.rtg_temp_bucket.json
}
resource "aws_s3_bucket_public_access_block" "rtg_temp" {
bucket = aws_s3_bucket.rtg_temp.id
block_public_acls = true
block_public_policy = true
restrict_public_buckets = true
ignore_public_acls = true
depends_on = [
aws_s3_bucket_policy.rtg_temp
]
}
output "rtg_temp_bucket" {
value = {
id = aws_s3_bucket.rtg_temp.id
arn = aws_s3_bucket.rtg_temp.arn
}
}
output "rtg_temp_bucket_cmk" {
value = {
arn = aws_kms_key.rtg_temp_bucket_cmk.arn
}
}