hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.29k stars 1.72k forks source link

google_container_node_pool with multiple secondary_boot_disks #19037

Open hugo-laulhere opened 1 month ago

hugo-laulhere commented 1 month ago

Community Note

Terraform Version & Provider Version(s)

Terraform v1.9.4 on darwin_arm64

Affected Resource(s)

google_container_node_pool

Terraform Configuration

resource "google_container_node_pool" "test" {
  name       = "test"
  location   = google_container_cluster.shared.location
  cluster    = google_container_cluster.shared.name
  node_count = 0

  management {
    auto_repair  = "true"
    auto_upgrade = "true"
  }

  node_config {

    image_type   = "COS_CONTAINERD"
    machine_type = "e2-standard-2"

    disk_size_gb = "30"
    disk_type    = "pd-standard"

    metadata = {
      disable-legacy-endpoints = "true"
    }
    gcfs_config {
      enabled = true 
    }

    secondary_boot_disks {
      disk_image = "global/images/test-image-0"
      mode = "CONTAINER_IMAGE_CACHE"
    }

    secondary_boot_disks {
      disk_image = "global/images/test-image-1"
      mode = "CONTAINER_IMAGE_CACHE"
    }
  }
}

Debug Output

No response

Expected Behavior

The created nodepool should have 2 secondary boot disks.

Actual Behavior

The node pool only has one boot disk: the one with test-image-0

Steps to reproduce

  1. terraform apply

Important Factoids

No response

References

No response

ggtisc commented 1 month ago

Hi @hugo-laulhere!

I noticed that the value of node_count is 0. GKE requires at least one node in a node pool. This is because several GKE functionalities depend on having at least one running node. Setting node_count to 0 would cause the node pool creation to fail.

As an additional consideration you must ensure that your Compute Engine resource quota is sufficient for this number of instances.

hugo-laulhere commented 1 month ago

Hi @ggtisc ! I tried with node_count set to 1. The node was provisioned but only one secondary boot disk was there.

ggtisc commented 1 month ago

This looks more like troubleshooting than a bug. You could check your quotas, permissions and try the next code:

resource "google_container_cluster" "cc_19037" {
  name     = "cc-19037"
  location = "us-central1"
  remove_default_node_pool = true
  initial_node_count       = 1
  deletion_protection = false
}

resource "google_compute_image" "ci_19037_a" {
  name   = "ci-19037-a"

  raw_disk {
    source = "https://storage.googleapis.com/bosh-gce-raw-stemcells/bosh-stemcell-97.98-google-kvm-ubuntu-xenial-go_agent-raw-1557960142.tar.gz"
  }
}

resource "google_compute_image" "ci_19037_b" {
  name   = "ci-19037-b"

  raw_disk {
    source = "https://storage.googleapis.com/bosh-gce-raw-stemcells/bosh-stemcell-97.98-google-kvm-ubuntu-xenial-go_agent-raw-1557960142.tar.gz"
  }
}

resource "google_container_node_pool" "cnp_19037" {
  name       = "cnp-19037"
  location   = google_container_cluster.cc_19037.location
  cluster    = google_container_cluster.cc_19037.name
  node_count = 1

  management {
    auto_repair  = "true"
    auto_upgrade = "true"
  }

  node_config {
    image_type   = "COS_CONTAINERD"
    machine_type = "e2-standard-2"

    disk_size_gb = "30"
    disk_type    = "pd-standard"

    metadata = {
      disable-legacy-endpoints = "true"
    }
    gcfs_config {
      enabled = true 
    }

    secondary_boot_disks {
      disk_image = "global/images/ci-19037-a"
      mode = "CONTAINER_IMAGE_CACHE"
    }

    secondary_boot_disks {
      disk_image = "global/images/ci-19037-b"
      mode = "CONTAINER_IMAGE_CACHE"
    }
  }
}

If after this you still continue with issues I suggest you to check the documentation of terraform registry, verify your project configuration and read some guides

hugo-laulhere commented 1 month ago

I will try what you suggested. However I don't think it is a troubleshooting issue, I can create the node_pool I have described from GCP UI, it's not working only from terraform

ggtisc commented 1 month ago

ok I'll be waiting for the results