<p>I am trying to provision Azure AKS using terraform. When I create AKS with the LoadBalancer profile it will create a load balancer with static public IP. I need these IP to pass onto Nginx controller</p>

<p>What I am trying to do is I am using a data block to get the IPs created by Terraform and pass it to terraform helm templates to provision Nginx ingress controller</p>

<p>When I use data block</p>

<pre><code>data "azurerm_public_ips" "example" {
  resource_group_name = azurerm_kubernetes_cluster.aks.node_resource_group
  attached            = true
  allocation_type = "Static"
  name_prefix = "kubernetes"
  depends_on = [
  azurerm_kubernetes_cluster.aks]
}

output "ip" {
  value = data.azurerm_public_ips.example.public_ips
}
</code></pre>

<p>I will be getting the output as follow </p>

<pre><code> ip = [
  {
     "domain_name_label" = ""
     "fqdn" = ""
     "id" = "/subscriptions/xxxx/resourceGroups/xx/providers/Microsoft.Network/publicIPAddresses/kubernetesxx"
     "ip_address" = "00.00.00.00"
     "name" = "kubernetes-xxxxx"
  },
]


</code></pre>

<p>What I want to achieve is to pass the value of ip_address to my helm chart</p>

<pre><code>data "helm_repository" "incubator" {
  name = "stable"
  url  = "https://kubernetes-charts.storage.googleapis.com"
}
resource "helm_release" "ingress" {
  repository = data.helm_repository.incubator.url
  chart = "nginx-ingress"
  name = "test"
  set {
    name  = "controller.service.loadBalancerIP"
  value  =data.azurerm_public_ips.example.public_ips[ip_address]
  }
  depends_on = [
  data.azurerm_public_ips.example
  ]
}
</code></pre>

<p>When I tried with above method it throwing an error saying</p>

<pre><code> Error: Invalid reference
on aks.tf , in output "ip":
   value = data.azurerm_public_ips.example.public_ips[ip_address]
  A reference to a resource type must be followed by at least one attribute access, specifying 
  the resource name.
</code></pre>

adesh REDDY
<p>you should do this:</p>

<pre><code>element(data.azurerm_public_ips.example.public_ip, 1).ip_address
</code></pre>

<p><a href="https://www.terraform.io/docs/configuration/functions/element.html" rel="nofollow noreferrer">https://www.terraform.io/docs/configuration/functions/element.html</a></p>

<p>notice this is for 0.12, for 0.11 check <a href="https://www.terraform.io/docs/configuration-0-11/interpolation.html" rel="nofollow noreferrer">this</a> article</p>
