<p>I'm trying to get the nginx ingress controller load balancer ip in Azure AKS.  I figured I would use the kubernetes provider via:</p>
<pre><code>data &quot;kubernetes_service&quot; &quot;nginx_service&quot; {
  metadata {
    name      = &quot;${local.ingress_name}-ingress-nginx-controller&quot;
    namespace = local.ingress_ns
  }

  depends_on = [helm_release.ingress]
}
</code></pre>
<p>However, i'm not seeing the IP address, this is what i get back:</p>
<pre><code>nginx_service = [
      + {
          + cluster_ip                  = &quot;10.0.165.249&quot;
          + external_ips                = []
          + external_name               = &quot;&quot;
          + external_traffic_policy     = &quot;Local&quot;
          + health_check_node_port      = 31089
          + load_balancer_ip            = &quot;&quot;
          + load_balancer_source_ranges = []
          + port                        = [
              + {
                  + name        = &quot;http&quot;
                  + node_port   = 30784
                  + port        = 80
                  + protocol    = &quot;TCP&quot;
                  + target_port = &quot;http&quot;
                },
              + {
                  + name        = &quot;https&quot;
                  + node_port   = 32337
                  + port        = 443
                  + protocol    = &quot;TCP&quot;
                  + target_port = &quot;https&quot;
                },
            ]
          + publish_not_ready_addresses = false
          + selector                    = {
              + &quot;app.kubernetes.io/component&quot; = &quot;controller&quot;
              + &quot;app.kubernetes.io/instance&quot;  = &quot;nginx-ingress-internal&quot;
              + &quot;app.kubernetes.io/name&quot;      = &quot;ingress-nginx&quot;
            }
          + session_affinity            = &quot;None&quot;
          + type                        = &quot;LoadBalancer&quot;
        },
   ]
</code></pre>
<p>However when I pull down the service via <code>kubectl</code> I can get the IP address via:</p>
<pre><code> kubectl get svc nginx-ingress-internal-ingress-nginx-controller -n nginx-ingress -o json | jq -r '.status.loadBalancer.ingress[].ip'
10.141.100.158
</code></pre>
<p>Is this a limitation of kubernetes provider for AKS?  If so, what is a workaround other people have used?  My end goals is to use the IP to configure the application gateway backend.</p>
<p>I guess I can use <code>local-exec</code>, but that seem hacky. Howerver, this might be my only option at the moment.</p>
<p>Thanks,</p>
<p>Jerry</p>

<p>although i strongly advise against creating resources inside Kubernetes with Terraform, you can do that:</p>
<p>Create a Public IP with Terraform -&gt; Create the ingress-nginx inside Kubernetes with Terraform and pass <code>annotations</code> and <code>loadBalancerIP</code>with data from your Terraform resources. The final manifest should look like this:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-resource-group: myResourceGroup
  name: ingress-nginx-controller
spec:
  loadBalancerIP: &lt;YOUR_STATIC_IP&gt;
  type: LoadBalancer
</code></pre>
<p>Terraform could look like this:</p>
<pre><code>resource &quot;kubernetes_service&quot; &quot;ingress_nginx&quot; {
  metadata {
    name = &quot;tingress-nginx-controller&quot;
    
    annotations {
      &quot;service.beta.kubernetes.io/azure-load-balancer-resource-group&quot; = &quot;${azurerm_resource_group.YOUR_RG.name}&quot;
    }

  spec {
    selector = {
      app = &lt;PLACEHOLDER&gt;
    }
    port {
      port        = &lt;PLACEHOLDER&gt;
      target_port = &lt;PLACEHOLDER&gt;
    }

    type = &quot;LoadBalancer&quot;
    load_balancer_ip = &quot;${azurerm_public_ip.YOUR_IP.ip_address}&quot;
  }
}
</code></pre>
