FN_
FN_

Reputation: 853

AWS NLB over Helm in Terraform - how to find DNS name?

I am using Helm chart provisioned by Terraform which creates Network Load Balancer, but I do not know how to get DNS name of this balancer so I can create Route53 records in Terraform for it.

If I can get it's ARN, I can call it over data block and read dns_name, however there is nothing like thit that Helm can return for me.

Do you have any suggestions?
I would like to keep it as IaC as possible

PS: I am passing some values to Helm chart so it's creating NLB, native functionality of this Chart is to create Classic LB.

   service.beta.kubernetes.io/aws-load-balancer-type: nlb

Upvotes: 0

Views: 1381

Answers (2)

jonny
jonny

Reputation: 646

I had to use kubernetes_ingress_v1 so to create a Route 53 entry for the ingress hostname:

data "kubernetes_ingress_v1" "this" {
  metadata {
    name = "ingress-myservice"
    namespace = "myservice"
  }
  depends_on = [
    module.myservice-eks
  ]
}

resource "aws_route53_record" "this" {
  zone_id = local.route53_zone_id
  name    = "whatever.myservice.com"
  type    = "CNAME"
  ttl     = "300"
  records = [data.kubernetes_ingress_v1.this.status.0.load_balancer.0.ingress.0.hostname]
}

Upvotes: 0

FN_
FN_

Reputation: 853

I just found and answer, it's simple using: Note: I had to specify namespace, otherwise was service null (not found).

data "kubernetes_service" "ingress_nginx" {
  metadata {
    name = "ingress-nginx-controller"
    namespace = "kube-system"
  }
}
output "k8s_service_ingress" {
  description   = "External DN name of load balancer"
  value         = data.kubernetes_service.ingress_nginx.status.0.load_balancer.0.ingress.0.hostname
}

It can be found in official docs too - https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/service

Upvotes: 2

Related Questions