-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmodule_s3bucket_event_cache.tf
More file actions
173 lines (138 loc) · 3.17 KB
/
module_s3bucket_event_cache.tf
File metadata and controls
173 lines (138 loc) · 3.17 KB
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
171
172
173
module "s3bucket_event_cache" {
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-s3bucket.zip"
count = var.enable_event_cache ? 1 : 0
name = "eventsub_event_cache"
aws_account_id = var.aws_account_id
region = var.region
project = var.project
environment = var.environment
component = var.component
acl = "private"
force_destroy = var.force_destroy
versioning = true
lifecycle_rules = [
{
enabled = true
noncurrent_version_transition = [
{
noncurrent_days = "30"
storage_class = "STANDARD_IA"
}
]
noncurrent_version_expiration = {
noncurrent_days = "90"
}
abort_incomplete_multipart_upload = {
days = "1"
}
}
]
policy_documents = [
data.aws_iam_policy_document.s3bucket_event_cache[0].json
]
bucket_logging_target = {
bucket = "${var.access_logging_bucket}"
}
public_access = {
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
default_tags = {
Name = "Event Cache Storage"
NHSE-Enable-S3-Backup-Acct = "True"
}
}
data "aws_iam_policy_document" "s3bucket_event_cache" {
count = var.enable_event_cache ? 1 : 0
statement {
sid = "DontAllowNonSecureConnection"
effect = "Deny"
actions = [
"s3:*",
]
resources = [
module.s3bucket_event_cache[0].arn,
"${module.s3bucket_event_cache[0].arn}/*",
]
principals {
type = "AWS"
identifiers = [
"*",
]
}
condition {
test = "Bool"
variable = "aws:SecureTransport"
values = [
"false",
]
}
}
statement {
sid = "AllowManagedAccountsToList"
effect = "Allow"
actions = [
"s3:ListBucket",
]
resources = [
module.s3bucket_event_cache[0].arn,
]
principals {
type = "AWS"
identifiers = [
"arn:aws:iam::${var.aws_account_id}:root"
]
}
}
statement {
sid = "AllowManagedAccountsToGet"
effect = "Allow"
actions = [
"s3:GetObject",
]
resources = [
"${module.s3bucket_event_cache[0].arn}/*",
]
principals {
type = "AWS"
identifiers = [
"arn:aws:iam::${var.aws_account_id}:root"
]
}
}
statement {
sid = "AllowGlueListBucketAndGetLocation"
effect = "Allow"
principals {
type = "AWS"
identifiers = [var.glue_role_arn]
}
actions = [
"s3:ListBucket",
"s3:GetBucketLocation"
]
resources = [
"arn:aws:s3:::${module.s3bucket_event_cache[0].bucket}"
]
}
# Object-level permissions: Get/Put/Delete objects
statement {
sid = "AllowGlueObjectAccess"
effect = "Allow"
principals {
type = "AWS"
identifiers = [var.glue_role_arn]
}
actions = [
"s3:GetObject",
"s3:GetObjectVersion",
"s3:PutObject",
"s3:DeleteObject"
]
resources = [
"arn:aws:s3:::${module.s3bucket_event_cache[0].bucket}/*"
]
}
}