VPC endpoints & DNS

Hi

Currently I’m trying to create 3 resources:

1 - VPC endpoint

2 - Private DNS zone

3 - DNS Records

I have a variable below, which is also defined in the env.hcl file and is different for each region.

variable "services_bundle" {
  description = "Services bundle"
  type = map(object({
    service_name  = string
    full_dns_name = list(string)
  }))
}
services_bundle = {
  services-bundle-dev = {
    service_name = "com.amazonaws.vpce.us-east-1.vpce-svc-xxx"
    full_dns_name = [
      "dns.name.one",
      "dns.name.two"
    ]
  },
  services-bundle-prod = {
    service_name = "com.amazonaws.vpce.us-east-1.vpce-svc-zzz"
    full_dns_name = ["dns.name.one"]
  }
}

So currently, to create a VPC endpoint, I’m using for_each, and the service_name parameter of the resource looks like this service_name = each.value.service_name

The main issue is that I’m not sure how to create DNS zones based on that variable. When I try to use for_each

resource "aws_route53_zone" "this" {
  for_each = var.services_bundle

  name = each.value.full_dns_name
  vpc {
    vpc_id = "123"
  }
}

, the result is an error - each.value.full_dns_name is a list of strings with 2 elements .

I tried to use a for loop inside the for_each, but in that case, I don’t know how to correctly define aws_route53_record resource to have also dynamically set dns_zone and alias, where the VPC endpoint should be mentioned

It will be much appreciated for any help with it