Skip to content

Commit

Permalink
Add distribution bucket policy resources
Browse files Browse the repository at this point in the history
  • Loading branch information
reweeden committed Jul 28, 2023
1 parent 40790d9 commit 0774635
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
41 changes: 41 additions & 0 deletions daac/distribution_bucket_policy.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
data "aws_cloudfront_origin_access_identity" "distribution_cloudfront_oai" {
for_each = toset(values(var.distribution_bucket_oais))

id = each.key
}

data "aws_iam_policy_document" "distribution_bucket_policy_document" {
for_each = var.distribution_bucket_oais

statement {
actions = ["s3:GetObject"]
resources = ["arn:aws:s3:::${local.prefix}-${each.key}/*"]

principals {
type = "AWS"
identifiers = [
data.aws_cloudfront_origin_access_identity.distribution_cloudfront_oai[each.value].iam_arn
]
}
}

# Need ListBucket permissions so that missing keys will return 404 errors instead of 403
statement {
actions = ["s3:ListBucket"]
resources = ["arn:aws:s3:::${local.prefix}-${each.key}"]

principals {
type = "AWS"
identifiers = [
data.aws_cloudfront_origin_access_identity.distribution_cloudfront_oai[each.value].iam_arn
]
}
}
}

resource "aws_s3_bucket_policy" "distribution_bucket_policy" {
for_each = var.distribution_bucket_oais

bucket = "${local.prefix}-${each.key}"
policy = try(data.aws_iam_policy_document.distribution_bucket_policy_document[each.key].json, null)
}
5 changes: 5 additions & 0 deletions daac/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ variable "partner_bucket_names" {
default = []
}

variable "distribution_bucket_oais" {
type = map(any)
default = {}
}

variable "s3_replicator_target_bucket" {
type = string
default = null
Expand Down

0 comments on commit 0774635

Please sign in to comment.