I am working on setting up hybrid DNS in my Azure tenant using Terraform and I am running into a problem. I have one DNS forwarding rule set to pass requests to our on-prem DNS server, and I need to link this to some of our virtual networks. This is the portion of my code where I'm doing this:
resource "azurerm_private_dns_resolver_virtual_network_link" "vnet_links" {
for_each = toset(var.forwarding_linked_vnets)
dns_forwarding_ruleset_id = azurerm_private_dns_resolver_dns_forwarding_ruleset.forwarding_ruleset.id
name = "${each.value["name"]}-link"
virtual_network_id = each.value["id"]
}
The forwarding_linked_vnets variable is declared like this:
variable "forwarding_linked_vnets" {
type = list(map(string))
}
I want to use the Azure CLI to pull a list of VNET IDs. I wrote up this CLI command to get me all the VNET IDs and names:
az graph query \
--graph-query 'Resources | where type == "microsoft.network/virtualnetworks" | where location == "westus"' \
--query "data[*].{name:name, id:id}" \
-o json
This specific command is required because I need to filter out VNETs not in our primary region. My question is, how can I get the output of that command into a variable in Terraform? I know I could just pass it through the -var argument when terraform apply is run. However, then I would have to mess around with the CD pipeline which I would really prefer to avoid because it's templated.