by shigemk2

当面は技術的なことしか書かない

aws_route53_recordのaliasのzone_id

type=Aのaws_route53_recordでaliasの中のzone_idについて。

resource "aws_elb" "main" {
  name               = "foobar-terraform-elb"
  availability_zones = ["us-east-1c"]

  listener {
    instance_port     = 80
    instance_protocol = "http"
    lb_port           = 80
    lb_protocol       = "http"
  }
}

resource "aws_route53_record" "www" {
  zone_id = aws_route53_zone.primary.zone_id
  name    = "example.com"
  type    = "A"

  alias {
    name                   = aws_elb.main.dns_name
    zone_id                = aws_elb.main.zone_id
    evaluate_target_health = true
  }
}

aws_route53_recordのaliasのzone_idにはこういうことが書いてある

zone_id - (Required) Hosted zone ID for a CloudFront distribution, S3 bucket, ELB, or Route 53 hosted zone. See resource_elb.zone_id for example.

aws_elbのzone_idにはこういうことが書いてある

zone_id - The canonical hosted zone ID of the ELB (to be used in a Route 53 Alias record)

このzone idはELB/ALB固有のもので、リージョンごとに固有のホストゾーンIDが存在する。東京だと Z14GRHDCWA56QT がそれ。

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elb

docs.aws.amazon.com