Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]: aws_s3_bucket_website_configuration does not export hosted_zone_id #37509

Open
troyready opened this issue May 14, 2024 · 1 comment
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/s3 Issues and PRs that pertain to the s3 service.

Comments

@troyready
Copy link
Contributor

Description

The website configuration on aws_s3_bucket is listed as deprecated and it is recommended to use aws_s3_bucket_website_configuration. The website_configuration resource has a website_domain attribute that it says is used in creating alias records, however the hosted_zone_id is also required to create alias records. Both attributes are available with the deprecated features but you have to do some workarounds to get the data from both resources, especially if you are creating multiple buckets with a single resource.

# Create the buckets that will generate the 301 redirects
resource "aws_s3_bucket" "redirect_buckets" {
  for_each = var.redirect_records

  bucket = "${each.key}.${aws_route53_zone.zone.name}"
}

# Set the bucket ACL
resource "aws_s3_bucket_acl" "redirect_buckets" {
  for_each = var.redirect_records
  bucket   = aws_s3_bucket.redirect_buckets[each.key].id

  acl = "public-read"
}

# Configure the redirection
resource "aws_s3_bucket_website_configuration" "redirect_buckets" {
  for_each = var.redirect_records
  bucket   = aws_s3_bucket.redirect_buckets[each.key].id
  redirect_all_requests_to {
    host_name = each.value.url
  }
}

# Create the redirect alias records
resource "aws_route53_record" "redirect_records" {
  for_each = var.redirect_records
  depends_on = [
    aws_s3_bucket_website_configuration.redirect_buckets

  ]

  zone_id = aws_route53_zone.zone.zone_id
  name    = each.key
  type    = "A"
  alias {
    name                   = aws_s3_bucket_website_configuration.redirect_buckets[each.key].website_domain
    zone_id                = aws_s3_bucket.redirect_buckets[each.key].hosted_zone_id
    evaluate_target_health = true
  }
}

Affected Resource(s) and/or Data Source(s)

No response

Potential Terraform Configuration

No response

References

#24313

Would you like to implement a fix?

None

@troyready troyready added the enhancement Requests to existing resources that expand the functionality or scope. label May 14, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added service/route53 Issues and PRs that pertain to the route53 service. service/s3 Issues and PRs that pertain to the s3 service. labels May 14, 2024
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label May 14, 2024
@justinretzolk justinretzolk removed needs-triage Waiting for first response or review from a maintainer. service/route53 Issues and PRs that pertain to the route53 service. labels May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/s3 Issues and PRs that pertain to the s3 service.
Projects
None yet
Development

No branches or pull requests

2 participants