digitalocean / terraform-provider-digitalocean

Terraform DigitalOcean provider
https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs
Mozilla Public License 2.0
492 stars 259 forks source link

Kubernetes example should be able to output LoadBalancer external IP #692

Open kriswuollett opened 2 years ago

kriswuollett commented 2 years ago

I followed the Kubernetes example and tried adding the following outputs as seen in the kubernetes_service data source:

output "load_balancer_hostname" {
  value = kubernetes_ingress.test_ingress.status.0.load_balancer.0.ingress.0.hostname
}

output "load_balancer_ip" {
  value = kubernetes_ingress.test_ingress.status.0.load_balancer.0.ingress.0.ip
}

The load_balancer_ip appears to be a droplet IP address and not the external IP of the Load Balancer that was created. I'm not too sure that is an actual bug, so perhaps it would be nice if the Kubernetes example showed how to output the external IP whether through the kubernetes or digitialocean providers.

kriswuollett commented 2 years ago

It sort of makes sense that test_ingress gives the cluster member IP. And so I just tried the following that works:

output "test_url" {
  value = module.kubernetes-config.test_url
}
data "kubernetes_service" "nginx-ingress-controller" {
  metadata {
    name      = "nginx-ingress-controller"
    namespace = kubernetes_namespace.test.metadata.0.name
  }
}
output "test_url" {
  value = "http://${data.kubernetes_service.nginx-ingress-controller.status.0.load_balancer.0.ingress.0.ip}/test"
}

Having test_url in the example is nice since it can provide a clickable link in some terminals. But in practice also showing how to get the IP would be useful for setting up other resources like DNS entries.

Something like this seems a reasonable thing to add to the example?