Question

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

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?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

I used a timeout as a workaround

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

  create_duration = "360s"
}