When you say “fetch” what are you meaning? Are you meaning you want to get some details about the Route53 zones? If so, take a look at the aws_route53_zone data source: Terraform Registry
As far as I can see, there’s no filtering option for aws_route53_zone data source, so not sure how I’d be able to filter for test.<team>.company.services?
That isn’t possible. The aws_route53_zone requires you to pass in either the zone_id or name. Do you not know the <team> value in your example, so you could construct the full name?
That’s the problem… Team name could be anything (depending on which AWS account they’re accessing, and we have A LOT). And our Terraform file needs to be generic when it comes to that, which is why I was trying to see if there’s a way to fetch the zone names from AWS directly just like how it can be done via their API.
I assume that you must have the current team available in your module somehow. For example, perhaps you have an input variable so you can get the current team name using var.team.
If so, you should be able to use that as part of your query to the data source:
data "aws_route53_zone" "example" {
name = "dev.${var.team}.company.services"
# ...
}
I am looking to solve this same issue. We have 100+ accounts to pull hosted zones from. We are creating cnames in modules for various services and do a data source to get hosted zones to input zone id into cname resource. All of the modules have variables in the data source for name that use lookup function to convert it to another value. This isn’t practical because each time we create a new account, we need to add the hosted zone for that VPC to the variable we do the lookup for. Having to update the variable each time we create a new account is not practical. Hosted zone data source requires either name or ID and neither are known in a module that is not account specific. The data source needs tag filters that don’t require name to be inserted.
Basically, we need a better way to retrieve the hosted zone without having to know zone name or zone id.