Skip to content

Commit 23f1dc0

Browse files
promote node_pool_auto_config field to GA provider (#8951) (#15884)
Signed-off-by: Modular Magician <[email protected]>
1 parent 6384780 commit 23f1dc0

File tree

4 files changed

+182
-3
lines changed

4 files changed

+182
-3
lines changed

.changelog/8951.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: promoted `node_pool_auto_config` field in `google_container_cluster` from beta provider to GA provider. (ga)
3+
```

google/services/container/resource_container_cluster.go

+124
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,34 @@ func ResourceContainerCluster() *schema.Resource {
12461246

12471247
"node_pool_defaults": clusterSchemaNodePoolDefaults(),
12481248

1249+
"node_pool_auto_config": {
1250+
Type: schema.TypeList,
1251+
Optional: true,
1252+
Computed: true,
1253+
MaxItems: 1,
1254+
Description: `Node pool configs that apply to all auto-provisioned node pools in autopilot clusters and node auto-provisioning enabled clusters.`,
1255+
Elem: &schema.Resource{
1256+
Schema: map[string]*schema.Schema{
1257+
"network_tags": {
1258+
Type: schema.TypeList,
1259+
Optional: true,
1260+
MaxItems: 1,
1261+
Description: `Collection of Compute Engine network tags that can be applied to a node's underlying VM instance.`,
1262+
Elem: &schema.Resource{
1263+
Schema: map[string]*schema.Schema{
1264+
"tags": {
1265+
Type: schema.TypeList,
1266+
Optional: true,
1267+
Elem: &schema.Schema{Type: schema.TypeString},
1268+
Description: `List of network tags applied to auto-provisioned node pools.`,
1269+
},
1270+
},
1271+
},
1272+
},
1273+
},
1274+
},
1275+
},
1276+
12491277
"node_version": {
12501278
Type: schema.TypeString,
12511279
Optional: true,
@@ -1912,6 +1940,7 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
19121940
NotificationConfig: expandNotificationConfig(d.Get("notification_config")),
19131941
ConfidentialNodes: expandConfidentialNodes(d.Get("confidential_nodes")),
19141942
ResourceLabels: tpgresource.ExpandStringMap(d, "resource_labels"),
1943+
NodePoolAutoConfig: expandNodePoolAutoConfig(d.Get("node_pool_auto_config")),
19151944
CostManagementConfig: expandCostManagementConfig(d.Get("cost_management_config")),
19161945
EnableK8sBetaApis: expandEnableK8sBetaApis(d.Get("enable_k8s_beta_apis"), nil),
19171946
}
@@ -2034,6 +2063,10 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
20342063
cluster.MonitoringConfig = expandMonitoringConfig(v)
20352064
}
20362065

2066+
if err := validateNodePoolAutoConfig(cluster); err != nil {
2067+
return err
2068+
}
2069+
20372070
if err := validatePrivateClusterConfig(cluster); err != nil {
20382071
return err
20392072
}
@@ -2492,6 +2525,10 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
24922525
return err
24932526
}
24942527

2528+
if err := d.Set("node_pool_auto_config", flattenNodePoolAutoConfig(cluster.NodePoolAutoConfig)); err != nil {
2529+
return err
2530+
}
2531+
24952532
if err := d.Set("node_pool_defaults", flattenNodePoolDefaults(cluster.NodePoolDefaults)); err != nil {
24962533
return err
24972534
}
@@ -3596,6 +3633,27 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
35963633
log.Printf("[INFO] GKE cluster %s Security Posture Config has been updated to %#v", d.Id(), req.Update.DesiredSecurityPostureConfig)
35973634
}
35983635

3636+
if d.HasChange("node_pool_auto_config.0.network_tags.0.tags") {
3637+
tags := d.Get("node_pool_auto_config.0.network_tags.0.tags").([]interface{})
3638+
3639+
req := &container.UpdateClusterRequest{
3640+
Update: &container.ClusterUpdate{
3641+
DesiredNodePoolAutoConfigNetworkTags: &container.NetworkTags{
3642+
Tags: tpgresource.ConvertStringArr(tags),
3643+
ForceSendFields: []string{"Tags"},
3644+
},
3645+
},
3646+
}
3647+
3648+
updateF := updateFunc(req, "updating GKE cluster node pool auto config network tags")
3649+
// Call update serially.
3650+
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
3651+
return err
3652+
}
3653+
3654+
log.Printf("[INFO] GKE cluster %s node pool auto config network tags have been updated", d.Id())
3655+
}
3656+
35993657
d.Partial(false)
36003658

36013659
if _, err := containerClusterAwaitRestingState(config, project, location, clusterName, userAgent, d.Timeout(schema.TimeoutUpdate)); err != nil {
@@ -4674,6 +4732,34 @@ func flattenNodePoolDefaults(c *container.NodePoolDefaults) []map[string]interfa
46744732
return []map[string]interface{}{result}
46754733
}
46764734

4735+
func expandNodePoolAutoConfig(configured interface{}) *container.NodePoolAutoConfig {
4736+
l := configured.([]interface{})
4737+
if len(l) == 0 || l[0] == nil {
4738+
return nil
4739+
}
4740+
npac := &container.NodePoolAutoConfig{}
4741+
config := l[0].(map[string]interface{})
4742+
4743+
if v, ok := config["network_tags"]; ok && len(v.([]interface{})) > 0 {
4744+
npac.NetworkTags = expandNodePoolAutoConfigNetworkTags(v)
4745+
}
4746+
return npac
4747+
}
4748+
4749+
func expandNodePoolAutoConfigNetworkTags(configured interface{}) *container.NetworkTags {
4750+
l := configured.([]interface{})
4751+
if len(l) == 0 || l[0] == nil {
4752+
return nil
4753+
}
4754+
nt := &container.NetworkTags{}
4755+
config := l[0].(map[string]interface{})
4756+
4757+
if v, ok := config["tags"]; ok && len(v.([]interface{})) > 0 {
4758+
nt.Tags = tpgresource.ConvertStringArr(v.([]interface{}))
4759+
}
4760+
return nt
4761+
}
4762+
46774763
func flattenNotificationConfig(c *container.NotificationConfig) []map[string]interface{} {
46784764
if c == nil {
46794765
return nil
@@ -5331,6 +5417,31 @@ func flattenManagedPrometheusConfig(c *container.ManagedPrometheusConfig) []map[
53315417
}
53325418
}
53335419

5420+
func flattenNodePoolAutoConfig(c *container.NodePoolAutoConfig) []map[string]interface{} {
5421+
if c == nil {
5422+
return nil
5423+
}
5424+
5425+
result := make(map[string]interface{})
5426+
if c.NetworkTags != nil {
5427+
result["network_tags"] = flattenNodePoolAutoConfigNetworkTags(c.NetworkTags)
5428+
}
5429+
5430+
return []map[string]interface{}{result}
5431+
}
5432+
5433+
func flattenNodePoolAutoConfigNetworkTags(c *container.NetworkTags) []map[string]interface{} {
5434+
if c == nil {
5435+
return nil
5436+
}
5437+
5438+
result := make(map[string]interface{})
5439+
if c.Tags != nil {
5440+
result["tags"] = c.Tags
5441+
}
5442+
return []map[string]interface{}{result}
5443+
}
5444+
53345445
func resourceContainerClusterStateImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
53355446
config := meta.(*transport_tpg.Config)
53365447

@@ -5537,6 +5648,19 @@ func BinaryAuthorizationDiffSuppress(k, old, new string, r *schema.ResourceData)
55375648
return false
55385649
}
55395650

5651+
func validateNodePoolAutoConfig(cluster *container.Cluster) error {
5652+
if cluster == nil || cluster.NodePoolAutoConfig == nil {
5653+
return nil
5654+
}
5655+
if cluster.NodePoolAutoConfig != nil && cluster.NodePoolAutoConfig.NetworkTags != nil && len(cluster.NodePoolAutoConfig.NetworkTags.Tags) > 0 {
5656+
if (cluster.Autopilot == nil || !cluster.Autopilot.Enabled) && (cluster.Autoscaling == nil || !cluster.Autoscaling.EnableNodeAutoprovisioning) {
5657+
return fmt.Errorf("node_pool_auto_config network tags can only be set if enable_autopilot or cluster_autoscaling is enabled")
5658+
}
5659+
}
5660+
5661+
return nil
5662+
}
5663+
55405664
func containerClusterSurgeSettingsCustomizeDiff(_ context.Context, d *schema.ResourceDiff, meta interface{}) error {
55415665
if v, ok := d.GetOk("cluster_autoscaling.0.auto_provisioning_defaults.0.upgrade_settings.0.strategy"); ok {
55425666
if v != "SURGE" {

google/services/container/resource_container_cluster_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,33 @@ func TestAccContainerCluster_autoprovisioningDefaultsUpgradeSettings(t *testing.
21562156
})
21572157
}
21582158

2159+
func TestAccContainerCluster_nodeAutoprovisioningNetworkTags(t *testing.T) {
2160+
t.Parallel()
2161+
2162+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
2163+
2164+
acctest.VcrTest(t, resource.TestCase{
2165+
PreCheck: func() { acctest.AccTestPreCheck(t) },
2166+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
2167+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
2168+
Steps: []resource.TestStep{
2169+
{
2170+
Config: testAccContainerCluster_autoprovisioning(clusterName, true, true),
2171+
Check: resource.ComposeTestCheckFunc(
2172+
resource.TestCheckResourceAttr("google_container_cluster.with_autoprovisioning",
2173+
"node_pool_auto_config.0.network_tags.0.tags.0", "test-network-tag"),
2174+
),
2175+
},
2176+
{
2177+
ResourceName: "google_container_cluster.with_autoprovisioning",
2178+
ImportState: true,
2179+
ImportStateVerify: true,
2180+
ImportStateVerifyIgnore: []string{"min_master_version"},
2181+
},
2182+
},
2183+
})
2184+
}
2185+
21592186
func TestAccContainerCluster_withShieldedNodes(t *testing.T) {
21602187
t.Parallel()
21612188

@@ -2266,6 +2293,31 @@ func TestAccContainerCluster_errorAutopilotLocation(t *testing.T) {
22662293
})
22672294
}
22682295

2296+
func TestAccContainerCluster_withAutopilotNetworkTags(t *testing.T) {
2297+
t.Parallel()
2298+
2299+
pid := envvar.GetTestProjectFromEnv()
2300+
containerNetName := fmt.Sprintf("tf-test-container-net-%s", acctest.RandString(t, 10))
2301+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
2302+
2303+
acctest.VcrTest(t, resource.TestCase{
2304+
PreCheck: func() { acctest.AccTestPreCheck(t) },
2305+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
2306+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
2307+
Steps: []resource.TestStep{
2308+
{
2309+
Config: testAccContainerCluster_withAutopilot(pid, containerNetName, clusterName, "us-central1", true, true, ""),
2310+
},
2311+
{
2312+
ResourceName: "google_container_cluster.with_autopilot",
2313+
ImportState: true,
2314+
ImportStateVerify: true,
2315+
ImportStateVerifyIgnore: []string{"min_master_version"},
2316+
},
2317+
},
2318+
})
2319+
}
2320+
22692321
func TestAccContainerCluster_withWorkloadIdentityConfig(t *testing.T) {
22702322
t.Parallel()
22712323

website/docs/r/container_cluster.html.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ region are guaranteed to support the same version.
268268
to say "these are the _only_ node pools associated with this cluster", use the
269269
[google_container_node_pool](container_node_pool.html) resource instead of this property.
270270

271-
* `node_pool_auto_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) Node pool configs that apply to auto-provisioned node pools in
271+
* `node_pool_auto_config` - (Optional) Node pool configs that apply to auto-provisioned node pools in
272272
[autopilot](https://cloud.google.com/kubernetes-engine/docs/concepts/autopilot-overview#comparison) clusters and
273273
[node auto-provisioning](https://cloud.google.com/kubernetes-engine/docs/how-to/node-auto-provisioning)-enabled clusters. Structure is [documented below](#nested_node_pool_auto_config).
274274

@@ -1027,11 +1027,11 @@ workload_identity_config {
10271027

10281028
<a name="nested_node_pool_auto_config"></a>The `node_pool_auto_config` block supports:
10291029

1030-
* `network_tags` (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) - The network tag config for the cluster's automatically provisioned node pools.
1030+
* `network_tags` (Optional) - The network tag config for the cluster's automatically provisioned node pools.
10311031

10321032
The `network_tags` block supports:
10331033

1034-
* `tags` (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) - List of network tags applied to auto-provisioned node pools.
1034+
* `tags` (Optional) - List of network tags applied to auto-provisioned node pools.
10351035

10361036
```hcl
10371037
node_pool_auto_config {

0 commit comments

Comments
 (0)