Skip to content

Commit f9d1e08

Browse files
authored
Merge pull request #15 from chris-qa-org/fix-add-cloudfront-read-policy-to-static-site-s3
Fix: Add CloudFront read policy to Static Site S3
2 parents f564fc8 + 2558481 commit f9d1e08

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

locals.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ locals {
66

77
s3_bucket_policy_statement_enforce_tls_path = "${path.module}/policies/s3-bucket-policy-statements/enforce-tls.json.tpl"
88
s3_bucket_policy_statement_log_delivery_access = "${path.module}/policies/s3-bucket-policy-statements/log-delivery-access.json.tpl"
9+
s3_bucket_policy_statement_cloudfront_read = "${path.module}/policies/s3-bucket-policy-statements/cloudfront-read.json.tpl"
910
s3_bucket_policy_path = "${path.module}/policies/s3-bucket-policy.json.tpl"
1011

1112
static_site_s3_acl = var.static_site_s3_acl
@@ -16,12 +17,20 @@ locals {
1617
bucket_arn = aws_s3_bucket.static_site.arn
1718
}
1819
)
20+
static_site_bucket_cloudfront_read_statement = templatefile(
21+
local.s3_bucket_policy_statement_cloudfront_read,
22+
{
23+
bucket_arn = aws_s3_bucket.static_site.arn,
24+
cloudfront_arn = aws_cloudfront_distribution.static_site[0].arn
25+
}
26+
)
1927
static_site_bucket_policy = templatefile(
2028
local.s3_bucket_policy_path,
2129
{
2230
statement = <<EOT
2331
[
24-
${local.static_site_bucket_enforce_tls_statement}
32+
${local.static_site_bucket_enforce_tls_statement},
33+
${local.static_site_bucket_cloudfront_read_statement}
2534
]
2635
EOT
2736
}
@@ -43,7 +52,6 @@ locals {
4352
cloudfront_static_site_http_version = var.cloudfront_static_site_http_version
4453
cloudfront_static_site_default_cache_behaviour = var.cloudfront_static_site_default_cache_behaviour
4554

46-
4755
enable_s3_access_logs = var.enable_s3_access_logs
4856
enable_cloudfront_static_site_logs = var.enable_cloudfront_static_site_logs
4957
create_logs_bucket = local.enable_s3_access_logs || local.enable_cloudfront_static_site_logs

policies/s3-bucket-policy-statements/cloudfront-read.json.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Principal": {
33
"Service": "cloudfront.amazonaws.com"
44
},
5-
"Action": "s3:GetObject"
5+
"Action": "s3:GetObject",
66
"Effect": "Allow",
77
"Resource": "${bucket_arn}/*",
88
"Condition": {

0 commit comments

Comments
 (0)