Question

Some of the specified target droplets don't belong to the same VPC as the Load Balancer

Posted June 5, 2021 98 views
Load BalancingKubernetesTerraformDigitalOcean VPC

I have a simple Terraform definition of a kubernetes cluster and a load balancer that will point to the kubernetes nodes by tag.

resource "digitalocean_kubernetes_cluster" "cluster" {
  name   = "cluster"
  region = "fra1"
  version = "1.20.2-do.0"

  node_pool {
    name       = "worker-pool"
    size       = "s-2vcpu-2gb"
    node_count = 3
    tags       = [var.worker_node_tag]
  }
}

resource "digitalocean_loadbalancer" "load_balancer" {
  name   = "loadbalancer"
  region = "fra1"

  forwarding_rule {
    entry_port     = 80
    entry_protocol = "http"

    target_port     = 80
    target_protocol = "http"
  }

  healthcheck {
    port     = 22
    protocol = "tcp"
  }

  droplet_tag = var.worker_node_tag

  depends_on = [
    digitalocean_kubernetes_cluster.cluster
  ]
}

Unfortunately when I do terraform apply the first time I get this error when terraform tries to create the load balancer

Error: Error creating Load Balancer: POST https://api.digitalocean.com/v2/load_balancers: 422 (request "a1601575-6f25-4b38-bf39-cab1c182aa44") some of the specified target droplets don't belong to the same VPC as the Load Balancer

Then I wait for a few minutes, do plan and apply again and viola the load balancer gets created…

So from my understanding there seems to be a delay with the nodes networking..

Is there anyway I can do terraform apply only once?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

I used a timeout as a workaround

resource "time_sleep" "wait" {
  depends_on = [
    digitalocean_kubernetes_cluster.cluster
  ]

  create_duration = "360s"
}
  • I tried it with the sleep and it worked the first time.
    Unfortunately, I tried it several times next morning, with a vpc and without.
    The nodes are not being assigned to the vpc, neither default nor a new vpc.

    It is really frustrating. I will move on to another provider with the hope of more stability.