hashicorp / terraform-provider-kubernetes

Terraform Kubernetes provider
https://www.terraform.io/docs/providers/kubernetes/
Mozilla Public License 2.0
1.59k stars 969 forks source link

Availability of hostname attribute after ingress creation #1369

Open LevinDmytro2 opened 3 years ago

LevinDmytro2 commented 3 years ago

Terraform Version, Provider Version and Kubernetes Version

Terraform version:1.0.3
Kubernetes provider version:2.4.1
Kubernetes version:1.20

Affected Resource(s)

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key.

Debug Output

Panic Output

Steps to Reproduce

provider "aws" { region = "us-west-1" } provider "kubernetes" { config_path = "~/.kube/config" } resource "kubernetes_ingress" "test2" { metadata { name = "upland-test-ingress2" namespace = "test-app2" annotations = { "kubernetes.io/ingress.class" = "nginx" } } spec {

rule {
  host = "analytics-test3.upland-dev2.me"
  http {
    path {
      path = "/(.*)"
      backend {
        service_name = "upland-analytics"
        service_port = "3001"
      }

    }

  }
}

}

} resource "kubernetes_namespace" "example2" { metadata { annotations = { name = "test-app2" }

name = "test-app2"

} } resource "aws_ecr_repository" "foo" { name = kubernetes_ingress.test2.status.0.load_balancer.0.ingress.0.hostname

}

Expected Behavior

Expecting successfully found hostname attribute.

Actual Behavior

│ Error: Invalid index │ │ on ingress.tf line 53, in resource "aws_ecr_repository" "foo": │ 53: name = kubernetes_ingress.test2.status.0.load_balancer.0.ingress.0.hostname │ ├──────────────── │ │ kubernetes_ingress.test2.status[0].load_balancer[0].ingress is empty list of object │ │ The given key does not identify an element in this collection value: the collection has no elements.

EvgeniyaL commented 2 years ago

Hey, I'm hitting the same issue described above, but the versions are different:

Terraform version:1.2.1
Kubernetes provider version:2.10.0
Kubernetes version:1.22.0

Steps to Reproduce

resource "kubernetes_ingress_v1" "ingress_controller" {
  metadata {
    annotations = {
      "alb.ingress.kubernetes.io/certificate-arn": module.acm_certificate.certificate_arn
      "kubernetes.io/ingress.class" = "alb"
    }
    name = local.name
    namespace = local.k8s_namespace
  }
  spec {
    rule {
      http {
        path {
          backend {
            service {
              name = var.service_name
              port {
                number = 80
              }
            }
          }
          path = "/path*"
        }

        path {
          backend {
            service {
              name = var.service_name
              port {
                number = 80
              }
            }
          }
          path = "/path1*"
        }

        path {
          backend {
            service {
              name = var.service_name
              port {
                number = 80
              }
            }
          }

          path = "/path3*"
        }
      }
    }
  }
}
resource "aws_route53_record" "ingress_controller" {
  zone_id = data.aws_route53_zone.ic.zone_id
  name    = local.domain-name
  type    = "CNAME"
  ttl     = "300"
  records = [kubernetes_ingress_v1.ingress_controller.status.0.load_balancer.0.ingress.0.hostname]
}

Expected Behavior

Expecting successfully found hostname attribute.

Actual Behavior

Error: Invalid index │ │ on ..\modules\k8s\k8s_ingress_controller.tf line 17, in resource "aws_route53_record" "ingress_controller": │ 17: records = [kubernetes_ingress_v1.ingress_controller.status.0.load_balancer.0.ingress.0.hostname] │ ├──────────────── │ │ kubernetes_ingress_v1.ingress_controller.status[0].load_balancer[0].ingress is empty list of object │ │ The given key does not identify an element in this collection value: the collection has no elements.

Any input will be much appreciated :)

iliev-georgi commented 2 years ago

https://stackoverflow.com/questions/53125583/terraform-wait-for-classic-load-balancers-a-record describes similar behavior for the classic load balancer. They suggest a workaround with a dummy dependency to wait until the resource is created.

NibiruHeisenberg commented 1 year ago

I'm also running into this issue on the first terraform apply. After waiting a bit and re-applying, it seems to have the ingress attributes (ip, hostname, etc.)

mikeroll commented 1 year ago

What about wait_for_load_balancer? Worked for me nicely.