<p>I am trying to retrieve the hostname in my Application Load Balancer that I configured as ingress.</p>
<p>The scenario currently is: I am deploying a helm chart using terraform, and have configured an ALB as ingress. The ALB and the Helm chart was deployed normally and is working, however, I need to retrieve the hostname of this ALB to create a Route53 record pointing to this ALB. When I try to retrieve this information, it returns null values.</p>
<p>According to terraform's own documentation, the correct way is as follows:</p>
<pre><code>data &quot;kubernetes_ingress&quot; &quot;example&quot; {
  metadata {
    name = &quot;terraform-example&quot;
  }
}

resource &quot;aws_route53_record&quot; &quot;example&quot; {
  zone_id = data.aws_route53_zone.k8.zone_id
  name    = &quot;example&quot;
  type    = &quot;CNAME&quot;
  ttl     = &quot;300&quot;
  records = [data.kubernetes_ingress.example.status.0.load_balancer.0.ingress.0.hostname]
} 
</code></pre>
<p>I did exactly as in the documentation (even the provider version is the latest), here is an excerpt of my code:</p>
<pre><code># Helm release resource
resource &quot;helm_release&quot; &quot;argocd&quot; {
  name = &quot;argocd&quot;

  repository       = &quot;https://argoproj.github.io/argo-helm&quot;
  chart            = &quot;argo-cd&quot;
  namespace        = &quot;argocd&quot;
  version          = &quot;4.9.7&quot;
  create_namespace = true

  values = [
    templatefile(&quot;${path.module}/settings/helm/argocd/values.yaml&quot;, {
      certificate_arn = module.acm_certificate.arn
    })
  ]
}

# Kubernetes Ingress data to retrieve de ingress hostname from helm deployment (ALB Hostname)
data &quot;kubernetes_ingress&quot; &quot;argocd&quot; {
  metadata {
    name      = &quot;argocd-server&quot;
    namespace = helm_release.argocd.namespace
  }

  depends_on = [
    helm_release.argocd
  ]
}

# Route53 record creation
resource &quot;aws_route53_record&quot; &quot;argocd&quot; {
  name    = &quot;argocd&quot;
  type    = &quot;CNAME&quot;
  ttl     = 600
  zone_id = aws_route53_zone.r53_zone.id

  records = [data.kubernetes_ingress.argocd.status.0.load_balancer.0.ingress.0.hostname]
}

</code></pre>
<p>When I run the <code>terraform apply</code> I've get the following error:</p>
<pre><code>╷
│ Error: Attempt to index null value
│ 
│   on route53.tf line 67, in resource &quot;aws_route53_record&quot; &quot;argocd&quot;:
│   67:   records = [data.kubernetes_ingress.argocd.status.0.load_balancer.0.ingress.0.hostname]
│     ├────────────────
│     │ data.kubernetes_ingress.argocd.status is null
│ 
│ This value is null, so it does not have any indices.
</code></pre>
<p>My ingress configuration (deployed by Helm Release):</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: argocd-server
  namespace: argocd
  uid: 646f6ea0-7991-4a13-91d0-da236164ac3e
  resourceVersion: '4491'
  generation: 1
  creationTimestamp: '2022-08-08T13:29:16Z'
  labels:
    app.kubernetes.io/component: server
    app.kubernetes.io/instance: argocd
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: argocd-server
    app.kubernetes.io/part-of: argocd
    helm.sh/chart: argo-cd-4.9.7
  annotations:
    alb.ingress.kubernetes.io/backend-protocol: HTTPS
    alb.ingress.kubernetes.io/certificate-arn: &gt;-
      arn:aws:acm:us-east-1:124416843011:certificate/7b79fa2c-d446-423d-b893-c8ff3d92a5e1
    alb.ingress.kubernetes.io/group.name: altb-devops-eks-support-alb
    alb.ingress.kubernetes.io/listen-ports: '[{&quot;HTTPS&quot;:443}]'
    alb.ingress.kubernetes.io/load-balancer-name: altb-devops-eks-support-alb
    alb.ingress.kubernetes.io/scheme: internal
    alb.ingress.kubernetes.io/tags: &gt;-
      Name=altb-devops-eks-support-alb,Stage=Support,CostCenter=Infrastructure,Project=Shared
      Infrastructure,Team=DevOps
    alb.ingress.kubernetes.io/target-type: ip
    kubernetes.io/ingress.class: alb
    meta.helm.sh/release-name: argocd
    meta.helm.sh/release-namespace: argocd
  finalizers:
    - group.ingress.k8s.aws/altb-devops-eks-support-alb
  managedFields:
    - manager: controller
      operation: Update
      apiVersion: networking.k8s.io/v1
      time: '2022-08-08T13:29:16Z'
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:finalizers:
            .: {}
            v:&quot;group.ingress.k8s.aws/altb-devops-eks-support-alb&quot;: {}
    - manager: terraform-provider-helm_v2.6.0_x5
      operation: Update
      apiVersion: networking.k8s.io/v1
      time: '2022-08-08T13:29:16Z'
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:annotations:
            .: {}
            f:alb.ingress.kubernetes.io/backend-protocol: {}
            f:alb.ingress.kubernetes.io/certificate-arn: {}
            f:alb.ingress.kubernetes.io/group.name: {}
            f:alb.ingress.kubernetes.io/listen-ports: {}
            f:alb.ingress.kubernetes.io/load-balancer-name: {}
            f:alb.ingress.kubernetes.io/scheme: {}
            f:alb.ingress.kubernetes.io/tags: {}
            f:alb.ingress.kubernetes.io/target-type: {}
            f:kubernetes.io/ingress.class: {}
            f:meta.helm.sh/release-name: {}
            f:meta.helm.sh/release-namespace: {}
          f:labels:
            .: {}
            f:app.kubernetes.io/component: {}
            f:app.kubernetes.io/instance: {}
            f:app.kubernetes.io/managed-by: {}
            f:app.kubernetes.io/name: {}
            f:app.kubernetes.io/part-of: {}
            f:helm.sh/chart: {}
        f:spec:
          f:rules: {}
    - manager: controller
      operation: Update
      apiVersion: networking.k8s.io/v1
      time: '2022-08-08T13:29:20Z'
      fieldsType: FieldsV1
      fieldsV1:
        f:status:
          f:loadBalancer:
            f:ingress: {}
      subresource: status
  selfLink: /apis/networking.k8s.io/v1/namespaces/argocd/ingresses/argocd-server
status:
  loadBalancer:
    ingress:
      - hostname: &gt;-
          internal-altb-devops-eks122-support-alb-1845221539.us-east-1.elb.amazonaws.com
spec:
  rules:
    - host: argocd.altb.co
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: argocd-server
                port:
                  number: 80
</code></pre>

thiagoaraujogit
<p>The terraform datasource for Ingress is : kubernetes_ingress_v1.
<a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/ingress_v1" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/ingress_v1</a></p>
<pre><code>data &quot;kubernetes_ingress_v1&quot; &quot;argocd&quot; {
  metadata {
    name      = &quot;argocd-server&quot;
    namespace = helm_release.argocd.namespace
  }

  depends_on = [
    helm_release.argocd
  ]
}

</code></pre>
<p>This should work.</p>
