helm_release nginx-ingress-controller renames digitalocean_loadbalancer name

Viewed 186

I have terraform config that creates digitalocean_loadbalancer and then creates helm_release with nginx-ingress-controller chart.

The first part:

resource "digitalocean_loadbalancer" "do_lb" {
  name   = "do-lb"
  region = "ams3"
  size = "lb-small"
  algorithm = "round_robin"
  redirect_http_to_https = true

  forwarding_rule {
    entry_port     = 80
    entry_protocol = "http"

    target_port     = 80
    target_protocol = "http"
  }

  forwarding_rule {
    entry_port     = 443
    entry_protocol = "https"

    target_port     = 443
    target_protocol = "https"
    tls_passthrough = true
  }
}

it creates loadbalancer with name "do-lb" successfully.

Then, after applying helm_release

resource "helm_release" "nginx_ingress_chart" {
  name       = "nginx-ingress-controller"
  namespace  = "default"
  repository = "https://charts.bitnami.com/bitnami"
  chart      = "nginx-ingress-controller"
  set {
    name  = "service.type"
    value = "LoadBalancer"
  }
  set {
    name  = "service.annotations.kubernetes\\.digitalocean\\.com/load-balancer-id"
    value = digitalocean_loadbalancer.do_lb.id
  }
  depends_on = [
    digitalocean_loadbalancer.do_lb,
  ]
}

it automatically renames the loadbalancer name to something md5-like.

The question is how to prevent such renaming?

1 Answers

The solution is to provide the service.beta.kubernetes.io/do-loadbalancer-name annotation.

Specifies a custom name for the Load Balancer. Existing Load Balancers will be renamed. The name must adhere to the following rules:

  • it must not be longer than 255 characters
  • it must start with an alphanumeric character
  • it must consist of alphanumeric characters or the '.' (dot) or '-' (dash) characters
  • except for the final character which must not be '-' (dash)

If no custom name is specified, a default name is chosen consisting of the character a appended by the Service UID.

Your case:

resource "helm_release" "nginx_ingress_chart" {
  name       = "nginx-ingress-controller"
  namespace  = "default"
  repository = "https://charts.bitnami.com/bitnami"
  chart      = "nginx-ingress-controller"
  set {
    name  = "service.type"
    value = "LoadBalancer"
  }
  set {
    name  = "service.annotations.kubernetes\\.digitalocean\\.com/load-balancer-id"
    value = digitalocean_loadbalancer.do_lb.id
  }
  set {
    name  = "service.annotations.kubernetes\\.digitalocean\\.com/load-balancer-name"
    value = "do-lb"
  }
  depends_on = [
    digitalocean_loadbalancer.do_lb,
  ]
}

Related