hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.29k stars 1.72k forks source link

google_dns_managed_zone lookup by dns_name #19000

Open KevinBrooke opened 1 month ago

KevinBrooke commented 1 month ago

Community Note

Description

data "google_dns_managed_zone" "env_dns_zone" { name = "qa-zone" }

Only supports name and project, we need to be able to look it up by DNS_NAME. This is possible via CLI, so we are currently using an external data resource, but TF should support this instead.

gcloud dns managed-zones list --project="${var.project_id}" --filter="DNS_NAME:${var.fqdn}" --format=json | jq -c .[0].name

New or Affected Resource(s)

google_dns_managed_zone

Potential Terraform Configuration

data "google_dns_managed_zone" "env_dns_zone" {
  dns_name = "myfqdn.com"
}

References

No response

b/359238452

rileykarson commented 1 month ago

We have https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/dns_managed_zones for list calls, but don't have an inline filter on the resource; that'd be the easiest way to do this, I think. You'd then supply the identity fields from the first element to the singleton datasource.