diff --git a/mmv1/third_party/terraform/services/container/resource_container_node_pool.go.tmpl b/mmv1/third_party/terraform/services/container/resource_container_node_pool.go.tmpl index e808ce486cb7..a5f719062424 100644 --- a/mmv1/third_party/terraform/services/container/resource_container_node_pool.go.tmpl +++ b/mmv1/third_party/terraform/services/container/resource_container_node_pool.go.tmpl @@ -518,7 +518,15 @@ var schemaNodePool = map[string]*schema.Schema{ Optional: true, Computed: true, ForceNew: true, - Description: `Creates a unique name for the node pool beginning with the specified prefix. Conflicts with name.`, + Description: `Creates a unique name for the node pool beginning with the specified prefix. Conflicts with name. Max length is 31 characters. Prefixes with lengths longer than 14 characters will use a shortened UUID that will be more prone to collisions.`, + ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { + value := v.(string) + if len(value) > 31 { + errors = append(errors, fmt.Errorf( + "%q cannot be longer than 31 characters, name is limited to 40", k)) + } + return + }, }, "node_config": schemaNodeConfig(), @@ -1209,7 +1217,12 @@ func expandNodePool(d *schema.ResourceData, prefix string) (*container.NodePool, } name = v.(string) } else if v, ok := d.GetOk(prefix + "name_prefix"); ok { - name = id.PrefixedUniqueId(v.(string)) + p := v.(string) + if len(p) > 14 { + name = tpgresource.ReducedPrefixedUniqueId(p) + } else { + name = id.PrefixedUniqueId(p) + } } else { name = id.UniqueId() } diff --git a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.tmpl b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.tmpl index 147eb02d8ee8..401ab7c44309 100644 --- a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.tmpl +++ b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.tmpl @@ -224,6 +224,33 @@ func TestAccContainerNodePool_namePrefix(t *testing.T) { }) } +func TestAccContainerNodePool_namePrefix_long(t *testing.T) { + // Randomness + acctest.SkipIfVcr(t) + t.Parallel() + + cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) + networkName := tpgcompute.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := tpgcompute.BootstrapSubnet(t, "gke-cluster", networkName) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccContainerNodePool_namePrefix(cluster, "tf-np-long-prefix-", networkName, subnetworkName), + }, + { + ResourceName: "google_container_node_pool.np", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"name_prefix"}, + }, + }, + }) +} + func TestAccContainerNodePool_noName(t *testing.T) { // Randomness acctest.SkipIfVcr(t) diff --git a/mmv1/third_party/terraform/website/docs/guides/version_8_upgrade.html.markdown b/mmv1/third_party/terraform/website/docs/guides/version_8_upgrade.html.markdown index 0732887aa239..2f32dd6e9699 100644 --- a/mmv1/third_party/terraform/website/docs/guides/version_8_upgrade.html.markdown +++ b/mmv1/third_party/terraform/website/docs/guides/version_8_upgrade.html.markdown @@ -92,6 +92,14 @@ terraform { ## Resources +## Resource: `google_container_node_pool` and `google_container_cluster` + +### `name_prefix` max length has been extended from 14 to 31 characters + +Previously, the max length of `name_prefix` for `google_container_node_pool` and `google_container_cluster.node_pool` was 14 characters since the autogenerated UUID suffix was 26 characters which combined to 40 characters (the max limit for GKE node pool names). + +In 8.0.0, providing a `name_prefix` larger than 14 characters will prompt the provider to use a shortened suffix of only 9 characters, leading to a new max of 31 characters for `name_prefix`. This shortened suffix is inevitably more prone to collisions, so use the longer max `name_prefix` length with caution. + ## Resource: `google_cloud_run_v2_worker_pool` ### `custom_audiences` is now removed diff --git a/mmv1/third_party/terraform/website/docs/r/container_node_pool.html.markdown b/mmv1/third_party/terraform/website/docs/r/container_node_pool.html.markdown index 9299e5145254..913879b19d4f 100644 --- a/mmv1/third_party/terraform/website/docs/r/container_node_pool.html.markdown +++ b/mmv1/third_party/terraform/website/docs/r/container_node_pool.html.markdown @@ -144,7 +144,14 @@ cluster. auto-generate a unique name. * `name_prefix` - (Optional) Creates a unique name for the node pool beginning - with the specified prefix. Conflicts with `name`. + with the specified prefix. Conflicts with `name`. Max length is 31 characters. + Prefixes with lengths longer than 14 characters will use a shortened + UUID that will be more prone to collisions. + + Resulting name for a `name_prefix` <= 14 characters: + `name_prefix` + YYYYmmddHHSSssss + 8 digit incremental counter + Resulting name for a `name_prefix` 15 - 31 characters: + `name_prefix` + YYmmdd + 3 digit incremental counter * `node_config` - (Optional) Parameters used in creating the node pool. Structure is [documented below](#nested_node_config). See [google_container_cluster](container_cluster.html#nested_node_config) for exact schema.