Skip to content

Commit b9165d1

Browse files
committed
try dyn block
1 parent 364e3bc commit b9165d1

File tree

1 file changed

+31
-36
lines changed

1 file changed

+31
-36
lines changed
Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
locals {
2-
# required to avoid a circular dependency between policy and bucket
3-
download_bucket_name = "download"
4-
download_bucket_arn = "arn:aws:s3:::${local.csi_global}-${local.download_bucket_name}"
5-
}
1+
# locals {
2+
# # required to avoid a circular dependency between policy and bucket
3+
# download_bucket_name = "download"
4+
# download_bucket_arn = "arn:aws:s3:::${local.csi_global}-${local.download_bucket_name}"
5+
# }
66

77
module "s3bucket_download" {
88
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket?ref=v2.0.2"
@@ -17,7 +17,7 @@ module "s3bucket_download" {
1717

1818
kms_key_arn = var.kms_key_arn
1919

20-
policy_documents = []
20+
policy_documents = [data.aws_iam_policy_document.s3bucket_download.json]
2121

2222
public_access = {
2323
block_public_acls = true
@@ -27,44 +27,39 @@ module "s3bucket_download" {
2727
}
2828
}
2929

30-
resource "aws_s3_bucket_policy" "download_bucket_policy" {
31-
count = var.cloudfront_distribution_arn != null ? 1 : 0
32-
33-
bucket = module.s3bucket_download.id
34-
policy = data.aws_iam_policy_document.s3bucket_download[0].json
35-
}
36-
3730
data "aws_iam_policy_document" "s3bucket_download" {
38-
for_each = var.cloudfront_distribution_arn != null ? toset([var.cloudfront_distribution_arn]) : []
31+
dynamic "statement" {
32+
for_each = var.cloudfront_distribution_arn != null ? [1] : []
3933

40-
statement {
41-
sid = "AllowCloudFrontServicePrincipalReadOnly"
42-
effect = "Allow"
34+
content {
35+
sid = "AllowCloudFrontServicePrincipalReadOnly"
36+
effect = "Allow"
4337

44-
actions = [
45-
"s3:GetObject",
46-
]
38+
actions = [
39+
"s3:GetObject",
40+
]
4741

48-
resources = [
49-
local.download_bucket_arn,
50-
"${local.download_bucket_arn}/*",
51-
]
42+
resources = [
43+
module.s3bucket_download.arn,
44+
"${module.s3bucket_download.arn}/*",
45+
]
5246

53-
principals {
54-
type = "Service"
47+
principals {
48+
type = "Service"
5549

56-
identifiers = [
57-
"cloudfront.amazonaws.com"
58-
]
59-
}
50+
identifiers = [
51+
"cloudfront.amazonaws.com"
52+
]
53+
}
6054

61-
condition {
62-
test = "StringEquals"
63-
variable = "AWS:SourceArn"
55+
condition {
56+
test = "StringEquals"
57+
variable = "AWS:SourceArn"
6458

65-
values = [
66-
var.cloudfront_distribution_arn,
67-
]
59+
values = [
60+
var.cloudfront_distribution_arn,
61+
]
62+
}
6863
}
6964
}
7065
}

0 commit comments

Comments
 (0)