Skip to content

Commit 9405515

Browse files
moved s3 policy documents to module
1 parent 985c299 commit 9405515

5 files changed

Lines changed: 89 additions & 101 deletions

File tree

infrastructure/terraform/components/api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ No requirements.
4545
|------|--------|---------|
4646
| <a name="module_authorizer_lambda"></a> [authorizer\_lambda](#module\_authorizer\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
4747
| <a name="module_domain_truststore"></a> [domain\_truststore](#module\_domain\_truststore) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-s3bucket.zip | n/a |
48-
| <a name="module_eventpub"></a> [eventpub](#module\_eventpub) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-eventpub.zip | n/a |
48+
| <a name="module_eventpub"></a> [eventpub](#module\_eventpub) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.31/terraform-eventpub.zip | n/a |
4949
| <a name="module_eventsub"></a> [eventsub](#module\_eventsub) | ../../modules/eventsub | n/a |
5050
| <a name="module_get_letter"></a> [get\_letter](#module\_get\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
5151
| <a name="module_get_letter_data"></a> [get\_letter\_data](#module\_get\_letter\_data) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |

infrastructure/terraform/components/api/modules_eventpub.tf

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "eventpub" {
2-
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-eventpub.zip"
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.31/terraform-eventpub.zip"
33

44
name = "eventpub"
55

@@ -27,4 +27,51 @@ module "eventpub" {
2727

2828
data_plane_bus_arn = var.eventpub_data_plane_bus_arn
2929
control_plane_bus_arn = var.eventpub_control_plane_bus_arn
30+
31+
additional_policies_for_event_cache_bucket = [
32+
data.aws_iam_policy_document.eventcache[0].json
33+
]
34+
}
35+
data "aws_iam_policy_document" "eventcache" {
36+
count = local.event_cache_bucket_name != null ? 1 : 0
37+
statement {
38+
sid = "AllowGlueListBucketAndGetLocation"
39+
effect = "Allow"
40+
41+
principals {
42+
type = "AWS"
43+
identifiers = [aws_iam_role.glue_role.arn]
44+
}
45+
46+
actions = [
47+
"s3:ListBucket",
48+
"s3:GetBucketLocation"
49+
]
50+
51+
resources = [
52+
"arn:aws:s3:::${local.csi_global}-eventcache"
53+
]
54+
}
55+
56+
# Object-level permissions: Get/Put/Delete objects
57+
statement {
58+
sid = "AllowGlueObjectAccess"
59+
effect = "Allow"
60+
61+
principals {
62+
type = "AWS"
63+
identifiers = [aws_iam_role.glue_role.arn]
64+
}
65+
66+
actions = [
67+
"s3:GetObject",
68+
"s3:GetObjectVersion",
69+
"s3:PutObject",
70+
"s3:DeleteObject"
71+
]
72+
73+
resources = [
74+
"arn:aws:s3:::${local.csi_global}-eventcache/*"
75+
]
76+
}
3077
}

infrastructure/terraform/components/api/s3_bucket_policy_eventcache.tf

Lines changed: 0 additions & 51 deletions
This file was deleted.

infrastructure/terraform/modules/eventsub/module_s3bucket_event_cache.tf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,44 @@ data "aws_iam_policy_document" "s3bucket_event_cache" {
126126
]
127127
}
128128
}
129+
statement {
130+
sid = "AllowGlueListBucketAndGetLocation"
131+
effect = "Allow"
132+
133+
principals {
134+
type = "AWS"
135+
identifiers = [var.glue_role_arn]
136+
}
137+
138+
actions = [
139+
"s3:ListBucket",
140+
"s3:GetBucketLocation"
141+
]
142+
143+
resources = [
144+
"arn:aws:s3:::${module.s3bucket_event_cache[0].bucket}"
145+
]
146+
}
147+
148+
# Object-level permissions: Get/Put/Delete objects
149+
statement {
150+
sid = "AllowGlueObjectAccess"
151+
effect = "Allow"
152+
153+
principals {
154+
type = "AWS"
155+
identifiers = [var.glue_role_arn]
156+
}
157+
158+
actions = [
159+
"s3:GetObject",
160+
"s3:GetObjectVersion",
161+
"s3:PutObject",
162+
"s3:DeleteObject"
163+
]
164+
165+
resources = [
166+
"arn:aws:s3:::${module.s3bucket_event_cache[0].bucket}/*"
167+
]
168+
}
129169
}

infrastructure/terraform/modules/eventsub/s3_bucket_policy_eventcache.tf

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)