From d29f7e40cba710b038eaed484b16b32f87eaf9d4 Mon Sep 17 00:00:00 2001 From: bob walker Date: Mon, 1 Jul 2024 16:28:05 +0100 Subject: [PATCH] Add an AAAA record for the service which aliases to the ALB or CloudFront distribution So that we can access the service using IPv6 as well as IPv4. --- README.md | 1 + route53-infrastructure.tf | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 35070c0..c4942d1 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,7 @@ This project creates and manages resources within an AWS account for infrastruct | [aws_route53_record.service_loadbalancer_record_alb](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource | | [aws_route53_record.service_loadbalancer_record_alb_global_accelerator_a](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource | | [aws_route53_record.service_record](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource | +| [aws_route53_record.service_record_ipv6](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource | | [aws_route53_zone.custom](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone) | resource | | [aws_route53_zone.infrastructure](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone) | resource | | [aws_route_table.infrastructure_private](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table) | resource | diff --git a/route53-infrastructure.tf b/route53-infrastructure.tf index 2c09062..6fdaa12 100644 --- a/route53-infrastructure.tf +++ b/route53-infrastructure.tf @@ -83,6 +83,22 @@ resource "aws_route53_record" "service_record" { } } +resource "aws_route53_record" "service_record_ipv6" { + for_each = local.enable_infrastructure_route53_hosted_zone ? { + for k, v in local.infrastructure_ecs_cluster_services : k => v if v["container_port"] != 0 && v["enable_cloudfront"] == true + } : {} + + zone_id = aws_route53_zone.infrastructure[0].zone_id + name = "${each.key}.${local.infrastructure_route53_domain}." + type = "AAAA" + + alias { + name = aws_cloudfront_distribution.infrastructure_ecs_cluster_service_cloudfront[each.key].domain_name + zone_id = aws_cloudfront_distribution.infrastructure_ecs_cluster_service_cloudfront[each.key].hosted_zone_id + evaluate_target_health = true + } +} + resource "aws_route53_record" "custom_s3_cloudfront_record" { for_each = local.enable_infrastructure_route53_hosted_zone ? { for k, v in local.custom_s3_buckets : k => v if v["cloudfront_dedicated_distribution"] == true