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.33k stars 1.73k forks source link

`container_node_pool` Name Prefix Can Be Too Long #17504

Open tgoodsell-tempus opened 7 months ago

tgoodsell-tempus commented 7 months ago

Community Note

Terraform Version

1.5.6

Affected Resource(s)

google_container_node_pool

Terraform Configuration

resource "google_container_node_pool" "main" {

  project     = "PROJECT-ID"
  cluster     = "CLUSTER-NAME"
  location    = "CLUSTER-LOCATION"
  name_prefix = "general-large-pool-"

  # When updating a nodepool it may take a long time to roll all the nodes in the pool
  # so setting a long timeout for the update action
  timeouts {
    update = "600m"
  }

Debug Output

  # module.node_pool_large.google_container_node_pool.main will be created
  + resource "google_container_node_pool" "main" {
      + cluster                     = "CLUSTER-NAME"
      + id                          = (known after apply)
      + initial_node_count          = (known after apply)
      + instance_group_urls         = (known after apply)
      + location                    = "CLUSTER-LOCATION"
      + managed_instance_group_urls = (known after apply)
      + max_pods_per_node           = (known after apply)
      + name                        = (known after apply)
      + name_prefix                 = "general-large-pool-"
      + node_count                  = (known after apply)
      + node_locations              = (known after apply)
      + operation                   = (known after apply)
      + project                     = "PROJECT-ID"
      + version                     = (known after apply)

 ....
 module.node_pool_large.google_container_node_pool.main: Creating...
╷
│ Error: error creating NodePool: googleapi: Error 400: Node_pool.name must be less than 40 characters.
│ Details:
│ [
│   {
│     "@type": "type.googleapis.com/google.rpc.RequestInfo",
│     "requestId": "0x5146f7488b204957"
│   }
│ ]
│ , badRequest
│ 
│ 

Expected Behavior

name_prefix respects upstream limits and generates an appropriate random ID for the name.

Actual Behavior

API failure

Steps to reproduce

  1. Create a node pool using the name_prefix option with a semi-long entry.

Important Factoids

The API docs don't have a documented max length so I can understand why this would be unknown information.

References

API Docs: https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1/projects.locations.clusters.nodePools

b/328653939

ggtisc commented 7 months ago

Confirmed issue: If the name_prefix exceed 40 characters trigger the error. There isn't any info about the max length of this field in any official source including:

  1. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool
  2. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool
  3. https://github.com/hashicorp/terraform-provider-google/blob/main/google/services/container/resource_container_node_pool.go