Skip to content

Commit

Permalink
Merge pull request #100 from answerdigital/route53-redirect-bucket-ow…
Browse files Browse the repository at this point in the history
…nership

Add Object Ownership to enable ACLs for redirect bucket
  • Loading branch information
cmbuckley authored Oct 13, 2023
2 parents ef0bb01 + 3911446 commit 911452f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions modules/aws/route53/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The module also simplifies a few boilerplate records at the apex for security pu
| [aws_route53_zone.redirect_zone](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone) | resource |
| [aws_s3_bucket.redirect](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
| [aws_s3_bucket_acl.redirect](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_acl) | resource |
| [aws_s3_bucket_ownership_controls.redirect](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls) | resource |
| [aws_s3_bucket_website_configuration.redirect](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_website_configuration) | resource |

## Inputs
Expand Down
13 changes: 11 additions & 2 deletions modules/aws/route53/aliases.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ resource "aws_s3_bucket" "redirect" {
bucket = each.key
}

resource "aws_s3_bucket_acl" "redirect" {
resource "aws_s3_bucket_ownership_controls" "redirect" {
for_each = toset(concat(var.aliases, [for a in var.aliases : "www.${a}"]))
bucket = aws_s3_bucket.redirect[each.key].bucket
acl = "private"
rule {
object_ownership = "ObjectWriter"
}
}

resource "aws_s3_bucket_acl" "redirect" {
for_each = toset(concat(var.aliases, [for a in var.aliases : "www.${a}"]))
depends_on = [aws_s3_bucket_ownership_controls.redirect]
bucket = aws_s3_bucket.redirect[each.key].bucket
acl = "private"
}

resource "aws_s3_bucket_website_configuration" "redirect" {
Expand Down

0 comments on commit 911452f

Please sign in to comment.