<p>I am deploying private AKS Cluster with hub-spoke network topology.
I also want to specify &quot;private_dns_link&quot; with terraform code.
I want link AKS subnet to my hub network.</p>
<p>I added this resource to my .tf file.</p>
<pre><code>resource &quot;azurerm_private_dns_zone_virtual_network_link&quot; &quot;link_to_hub_vnet&quot; {
name = &quot;link_to_hub_vnet&quot;
private_dns_zone_name = join(&quot;.&quot;, slice(split(&quot;.&quot;, 
azurerm_kubernetes_cluster.dev.private_fqdn), 1, length(split(&quot;.&quot;, 
azurerm_kubernetes_cluster.dev.private_fqdn))))
resource_group_name   = azurerm_resource_group.k8srg.name
virtual_network_id    = azurerm_virtual_network.hubVnetAddress.id

depends_on = [azurerm_kubernetes_cluster.dev]
}
</code></pre>
<p>But when do &quot;terraform apply&quot; it gives me below error.</p>
<blockquote>
<p>Error: creating/updating Virtual Network Link &quot;link_to_hub_vnet&quot; (Private DNS Zone &quot;5ed135c0-266f-4350-b537-872c095f3696.privatelink.northeurope.azmk8s.io&quot; / Resource Group &quot;k8srg&quot;): privatedns.VirtualNetworkLinksClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code=&quot;ParentResourceNotFound&quot; Message=&quot;Can not perform requested operation on nested resource. Parent resource '5ed135c0-266f-4350-b537-872c095f3696.privatelink.northeurope.azmk8s.io' not found.&quot;</p>
</blockquote>
<p>As i understand it could not find dns name, but when i check the private dns zone in Azure Portal, i see that it is there.</p>
<p>Anybody maybe expierence it ?</p>

Amir Damirov
<p>if you read through the for hub and spoke model , it says</p>
<p>By default, when a private cluster is provisioned, a private endpoint (1) and a private DNS zone (2) are created in the cluster-managed resource group. The cluster uses an A record in the private zone to resolve the IP of the private endpoint for communication to the API server.</p>
<p><a href="https://learn.microsoft.com/en-us/azure/aks/private-clusters#hub-and-spoke-with-custom-dns" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/azure/aks/private-clusters#hub-and-spoke-with-custom-dns</a></p>
<p>so I am doubtful if you can link external private dns to the cluster</p>
<p>but if you are looking to link the cluster private dns to vnet then you can create a null_resource and call the shell script which is there in the link below.</p>
<pre><code>resource &quot;null_resource&quot; &quot;dns_zone_link&quot; {
    
 provisionor &quot;local-exec&quot; { 
   interpreter = [&quot;bash&quot;]
   command = &quot;./dns-zone-link.sh&quot;

   environment {
      VNET = &quot;&quot;
   } 
 } 
}
</code></pre>
<p><a href="https://github.com/Azure/terraform/blob/master/quickstart/301-aks-private-cluster/dns-zone-link.sh" rel="nofollow noreferrer">https://github.com/Azure/terraform/blob/master/quickstart/301-aks-private-cluster/dns-zone-link.sh</a></p>
