terraform-provider-digitalocean icon indicating copy to clipboard operation
terraform-provider-digitalocean copied to clipboard

Delete default node pool

Open v0112358 opened this issue 5 years ago • 7 comments

Hi there,

I want to delete default node pool after create k8s cluster but it is not supported on Terraform.

Terraform Version

v0.12.18

Affected Resource(s)

Please list the resources as a list, for example:

  • digitalocean_kubernetes_cluster

Terraform Configuration Files

resource "digitalocean_kubernetes_cluster" "k8s_do_core" {
  #count  = 1
  name   = "k8s-do-core"
  region = var.region
  // Grab the latest version slug from `doctl kubernetes options versions`
  version = var.k8s_version
  tags    = [var.env, var.region]

  node_pool {
    name       = "worker-pool"
    size       = "s-1vcpu-2gb"
    node_count = 0
    auto_scale = "false"
    min_nodes  = 0
    max_nodes  = 0
    tags       = [var.env, var.region, "default-pool"]
  }
}

resource "digitalocean_kubernetes_node_pool" "k8s_do_core_node_pool" {
  cluster_id = digitalocean_kubernetes_cluster.k8s_do_core.id
  name       = "k8s-do-core-node-pool"
  size       = "s-1vcpu-2gb"
  node_count = 3
  auto_scale = "true"
  min_nodes  = 3
  max_nodes  = 10
  tags       = [var.env, var.region, "node-pool"]
}

Debug Output

Panic Output

Error: expected node_pool.0.node_count to be at least (1), got 0

  on k8s-do-core.tf line 1, in resource "digitalocean_kubernetes_cluster" "k8s_do_core":
   1: resource "digitalocean_kubernetes_cluster" "k8s_do_core" {

Expected Behavior

node_count setting accept 0 value.

Actual Behavior

Can't set node_count to 0.

Steps to Reproduce

  1. terraform apply to create k8s cluster.
  2. Change node_count to 0.
  3. terraform plan
  4. Error message above.

Important Factoids

References

v0112358 avatar Dec 17 '19 15:12 v0112358

@snormore any thoughts on this?

eddiezane avatar Jan 28 '20 16:01 eddiezane

i would love this to be supported. ideally i would prefer the node pool to be optional and not a requirement. terraform wants to destroy and create when making a change to the default node pool machine size, which is definitely not wanted or expected.

ideally id want to specify a k8s cluster with no node pool, then create 2 node pool resources (blue/green) that i can make changes to.

chasebolt avatar Feb 18 '20 16:02 chasebolt

I think we should ideally :fire: the standalone node pool resource type and only support multiple node pools defined within the cluster resource. If a new node pool is added, an existing one updated, or a node pool removed, it can happen by updating the cluster resource itself.

snormore avatar Feb 18 '20 20:02 snormore

So long as changes to the node pool don't cause the cluster to get deleted/recreated!

pbecotte avatar Mar 28 '20 15:03 pbecotte

Just hit the same issue. This is very problematic, because terraform wants to recreate the whole kubernetes cluster in case of node size changes, which is nonsense. Ideally node pool configuration should exist separately and this parameter is not really needed.

Does anyone know a good workaround for the time being (for changing instance size of default node pool)?

gp42 avatar Jul 08 '20 11:07 gp42

Just hit the same issue. My use-case is a shared K8s that needs to host one node for production, one for staging and one for development. I have a normal "shared" backend creating the kubernetes, and a backend with the 3 workspaces (prod/staging/dev) that gets the kubernetes from the "shared" backend, and adds node pools to it. Currently, I have to pay for a default node pool I will never use.

Any chance on someone solving this issue?

TheMrZZ avatar Jul 26 '20 16:07 TheMrZZ

As a workaround, I've "ignored" changes to the node_pool, and scaled the default node pool to zero via DigitalOcean's web interface.

In Terraform:

  lifecycle {
    ignore_changes = [
      # Ignore changes to `node_pool` because it has been scaled to zero
      # via DigitalOcean web interface, but we cannot scale it to zero
      # in the code.
      node_pool,
    ]
  }

MrSaints avatar Jan 04 '21 17:01 MrSaints