<p>I am trying to get ingress EXTERNAL-IP in k8s. Is there any way to get the details from terraform data block. like using data &quot;azurerm_kubernetes_cluster&quot; or something?</p>

iluv_dev
<p>Another solution would be to use the <a href="https://registry.terraform.io/providers/hashicorp/dns/latest/docs" rel="nofollow noreferrer">DNS provider's</a> <a href="https://registry.terraform.io/providers/hashicorp/dns/latest/docs/data-sources/dns_a_record_set" rel="nofollow noreferrer"><code>dns_a_record_set</code></a> data source to resolve the FQDN at build time.  Unlike the IP, the FQDN is exported from the azurerm_kubernetes_cluster resource.</p>
<p>That would allow you to work with the resulting IP address via the <code>dns_a_record_set</code>'s <code>addrs</code> attribute, as shown below (an example where the IP was needed for the destination of a firewall rule):</p>
<pre><code># not shown:
# * declaring dns provider in required_providers block
# * supporting resources eg azurerm_resource_group, etc

resource &quot;azurerm_kubernetes_cluster&quot; &quot;this&quot; {
  ...
}

data &quot;dns_a_record_set&quot; &quot;aks_api_ip&quot; {
  host = azurerm_kubernetes_cluster.this.fqdn
}

resource &quot;azurerm_firewall_network_rule_collection&quot; &quot;firewall_network_rule_collection&quot; {
  name                = &quot;ip_based_network_rules&quot;
  azure_firewall_name = azurerm_firewall.this.name
  resource_group_name = azurerm_resource_group.this.name
  priority            = 200
  action              = &quot;Allow&quot;

  rule {
    name                  = &quot;aks-nodes-to-control-plane&quot;
    description           = &quot;Azure Global required network rules: https://learn.microsoft.com/en-us/azure/aks/limit-egress-traffic&quot;
    source_addresses      = azurerm_subnet.this.address_prefixes
    destination_ports     = [ &quot;443&quot;, &quot;1194&quot;, &quot;9000&quot; ]
    destination_addresses = data.dns_a_record_set.aks_api_ip.addrs
    protocols             = [
      &quot;UDP&quot;,
      &quot;TCP&quot;
    ]
  }

  ...

}

</code></pre>
<p>The above worked in my case, and successfully added the correct IP to the rule destination.  No <code>depends_on</code> needed, Terraform thankfully is able to suss out build order.</p>
