1

I'm trying to create an hcloud (hetzner cloud) load balancer and add an https service to it via terraform. For some reason I'm unable to attach the certificates to the load balancer service and I get the following error:

Error: Incorrect attribute value type

  on hcloud.tf line 76, in resource "hcloud_load_balancer_service" "web_lb_service":
  76:     certificates     = data.hcloud_certificate.lb_cert.id

Inappropriate value for attribute "certificates": list of number required.

My terraform config used for the load balancer service is the following:

resource "hcloud_certificate" "domain_cert" {
    name = var.domain

    private_key = tls_private_key.cert_private_key.private_key_pem
    certificate = acme_certificate.certificate.certificate_pem

    labels = {
        type = "cert"
    }
}

resource "hcloud_load_balancer" "web_lb" {
  name               = "web_lb"
  load_balancer_type = "lb11"
  location           = var.location
  labels = {
    type = "web"
  }

  dynamic "target" {
    for_each = hcloud_server.web
    content {
      type      = "server"
      server_id = target.value["id"]
    }
  }

  algorithm {
    type = "round_robin"
  }
}

data "hcloud_certificate" "lb_cert" {
    id = hcloud_certificate.domain_cert.id
}

resource "hcloud_load_balancer_service" "web_lb_service" {
  load_balancer_id = hcloud_load_balancer.web_lb.id
  protocol         = "https"
  listen_port      = var.https_port
  destination_port = var.https_port
  health_check {
    protocol = var.https_protocol
    port     = var.https_port
    interval = "10"
    timeout  = "10"
    http {
      path         = "/"
      status_codes = ["2??", "3??"]
    }
   }
  http {
    certificates     = data.hcloud_certificate.lb_cert.id
 }
}

resource "hcloud_load_balancer_network" "web_network" {
  load_balancer_id        = hcloud_load_balancer.web_lb.id
  subnet_id               = hcloud_network_subnet.hc_private_subnet.id
  enable_public_interface = "true"
}

Any ideas?`

Thanks!

br

1 Answers1

0

You need to pass certificates as a list, not as a single parameter. https://registry.terraform.io/providers/hetznercloud/hcloud/latest/docs/resources/load_balancer_service

certificates - (Optional, list[int]) List of IDs from certificates which the Load Balancer has.

So this section should look like

resource "hcloud_load_balancer_service" "web_lb_service" {
  load_balancer_id = hcloud_load_balancer.web_lb.id
  protocol         = "https"
  listen_port      = var.https_port
  destination_port = var.https_port
  health_check {
    protocol = var.https_protocol
    port     = var.https_port
    interval = "10"
    timeout  = "10"
    http {
      path         = "/"
      status_codes = ["2??", "3??"]
    }
   }
  http {
    certificates     = [data.hcloud_certificate.lb_cert.id]
 }
}
wisp
  • 446
  • 5
  • 8