Skip to content

Commit b14d855

Browse files
container: add support for network_performance_config (#14095) (#10117)
[upstream:249d6411f0e3a2046ca44760834c8f86e5647dd1] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent 3a110c5 commit b14d855

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

.changelog/14095.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: added `network_performance_config` field to `google_container_cluster` resource
3+
```

google-beta/services/container/resource_container_cluster.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,6 +2422,21 @@ func ResourceContainerCluster() *schema.Resource {
24222422
Description: `Defines the config of in-transit encryption`,
24232423
ValidateFunc: validation.StringInSlice([]string{"IN_TRANSIT_ENCRYPTION_CONFIG_UNSPECIFIED", "IN_TRANSIT_ENCRYPTION_DISABLED", "IN_TRANSIT_ENCRYPTION_INTER_NODE_TRANSPARENT"}, false),
24242424
},
2425+
"network_performance_config": {
2426+
Type: schema.TypeList,
2427+
Optional: true,
2428+
MaxItems: 1,
2429+
Description: `Network bandwidth tier configuration.`,
2430+
Elem: &schema.Resource{
2431+
Schema: map[string]*schema.Schema{
2432+
"total_egress_bandwidth_tier": {
2433+
Type: schema.TypeString,
2434+
Required: true,
2435+
Description: `Specifies the total network bandwidth tier for NodePools in the cluster.`,
2436+
},
2437+
},
2438+
},
2439+
},
24252440
},
24262441
}
24272442
}
@@ -2584,6 +2599,7 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
25842599
EnableMultiNetworking: d.Get("enable_multi_networking").(bool),
25852600
DefaultEnablePrivateNodes: expandDefaultEnablePrivateNodes(d),
25862601
EnableFqdnNetworkPolicy: d.Get("enable_fqdn_network_policy").(bool),
2602+
NetworkPerformanceConfig: expandNetworkPerformanceConfig(d.Get("network_performance_config")),
25872603
},
25882604
MasterAuth: expandMasterAuth(d.Get("master_auth")),
25892605
NotificationConfig: expandNotificationConfig(d.Get("notification_config")),
@@ -3266,6 +3282,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
32663282
if err := d.Set("gateway_api_config", flattenGatewayApiConfig(cluster.NetworkConfig.GatewayApiConfig)); err != nil {
32673283
return err
32683284
}
3285+
if err := d.Set("network_performance_config", flattenNetworkPerformanceConfig(cluster.NetworkConfig.NetworkPerformanceConfig)); err != nil {
3286+
return err
3287+
}
32693288
if err := d.Set("fleet", flattenFleet(cluster.Fleet)); err != nil {
32703289
return err
32713290
}
@@ -4507,6 +4526,24 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
45074526
log.Printf("[INFO] GKE cluster %s resource usage export config has been updated", d.Id())
45084527
}
45094528

4529+
if d.HasChange("network_performance_config") {
4530+
if npc, ok := d.GetOk("network_performance_config"); ok {
4531+
req := &container.UpdateClusterRequest{
4532+
Update: &container.ClusterUpdate{
4533+
DesiredNetworkPerformanceConfig: expandNetworkPerformanceConfig(npc),
4534+
},
4535+
}
4536+
4537+
updateF := updateFunc(req, "updating GKE Network Performance Config")
4538+
// Call update serially.
4539+
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
4540+
return err
4541+
}
4542+
4543+
log.Printf("[INFO] GKE cluster %s Network Performance Config has been updated", d.Id())
4544+
}
4545+
}
4546+
45104547
if d.HasChange("gateway_api_config") {
45114548
if gac, ok := d.GetOk("gateway_api_config"); ok {
45124549
req := &container.UpdateClusterRequest{
@@ -6001,6 +6038,18 @@ func expandDnsConfig(configured interface{}) *container.DNSConfig {
60016038
}
60026039
}
60036040

6041+
func expandNetworkPerformanceConfig(configured interface{}) *container.ClusterNetworkPerformanceConfig {
6042+
l := configured.([]interface{})
6043+
if len(l) == 0 || l[0] == nil {
6044+
return nil
6045+
}
6046+
6047+
config := l[0].(map[string]interface{})
6048+
return &container.ClusterNetworkPerformanceConfig{
6049+
TotalEgressBandwidthTier: config["total_egress_bandwidth_tier"].(string),
6050+
}
6051+
}
6052+
60046053
func expandGatewayApiConfig(configured interface{}) *container.GatewayAPIConfig {
60056054
l := configured.([]interface{})
60066055
if len(l) == 0 || l[0] == nil {
@@ -6988,6 +7037,17 @@ func flattenDnsConfig(c *container.DNSConfig) []map[string]interface{} {
69887037
}
69897038
}
69907039

7040+
func flattenNetworkPerformanceConfig(c *container.ClusterNetworkPerformanceConfig) []map[string]interface{} {
7041+
if c == nil {
7042+
return nil
7043+
}
7044+
return []map[string]interface{}{
7045+
{
7046+
"total_egress_bandwidth_tier": c.TotalEgressBandwidthTier,
7047+
},
7048+
}
7049+
}
7050+
69917051
func flattenGatewayApiConfig(c *container.GatewayAPIConfig) []map[string]interface{} {
69927052
if c == nil {
69937053
return nil

google-beta/services/container/resource_container_cluster_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,45 @@ func TestAccContainerCluster_inTransitEncryptionConfig(t *testing.T) {
701701
})
702702
}
703703

704+
func TestAccContainerCluster_networkPerformanceConfig(t *testing.T) {
705+
t.Parallel()
706+
707+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
708+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
709+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
710+
acctest.VcrTest(t, resource.TestCase{
711+
PreCheck: func() { acctest.AccTestPreCheck(t) },
712+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
713+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
714+
Steps: []resource.TestStep{
715+
{
716+
Config: testAccContainerCluster_networkPerformanceConfig(clusterName, networkName, subnetworkName, "TIER_1"),
717+
Check: resource.ComposeAggregateTestCheckFunc(
718+
resource.TestCheckResourceAttr("google_container_cluster.primary", "network_performance_config.0.total_egress_bandwidth_tier", "TIER_1"),
719+
),
720+
},
721+
{
722+
ResourceName: "google_container_cluster.primary",
723+
ImportState: true,
724+
ImportStateVerify: true,
725+
ImportStateVerifyIgnore: []string{"deletion_protection"},
726+
},
727+
{
728+
Config: testAccContainerCluster_networkPerformanceConfig(clusterName, networkName, subnetworkName, "TIER_UNSPECIFIED"),
729+
Check: resource.ComposeAggregateTestCheckFunc(
730+
resource.TestCheckResourceAttr("google_container_cluster.primary", "network_performance_config.0.total_egress_bandwidth_tier", "TIER_UNSPECIFIED"),
731+
),
732+
},
733+
{
734+
ResourceName: "google_container_cluster.primary",
735+
ImportState: true,
736+
ImportStateVerify: true,
737+
ImportStateVerifyIgnore: []string{"deletion_protection"},
738+
},
739+
},
740+
})
741+
}
742+
704743
func TestAccContainerCluster_withFQDNNetworkPolicy(t *testing.T) {
705744
t.Parallel()
706745

@@ -13798,3 +13837,27 @@ resource "google_container_cluster" "primary" {
1379813837
}
1379913838
`, name, networkName, subnetworkName, config)
1380013839
}
13840+
13841+
func testAccContainerCluster_networkPerformanceConfig(name, networkName, subnetworkName, config string) string {
13842+
return fmt.Sprintf(`
13843+
resource "google_container_cluster" "primary" {
13844+
name = "%s"
13845+
location = "us-central1-a"
13846+
initial_node_count = 1
13847+
network = "%s"
13848+
subnetwork = "%s"
13849+
deletion_protection = false
13850+
13851+
node_config {
13852+
machine_type = "n2-standard-32"
13853+
gvnic {
13854+
enabled = true
13855+
}
13856+
}
13857+
13858+
network_performance_config {
13859+
total_egress_bandwidth_tier = "%s"
13860+
}
13861+
}
13862+
`, name, networkName, subnetworkName, config)
13863+
}

website/docs/r/container_cluster.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,8 @@ gvnic {
955955
* `local_ssd_count` - (Optional) The amount of local SSD disks that will be
956956
attached to each cluster node. Defaults to 0.
957957

958+
* `network_performance_config` - (Optional) Network bandwidth tier configuration. Structure is [documented below](#network_performance_config).
959+
958960
* `machine_type` - (Optional) The name of a Google Compute Engine machine type.
959961
Defaults to `e2-medium`. To create a custom machine type, value should be set as specified
960962
[here](https://cloud.google.com/compute/docs/reference/latest/instances#machineType).
@@ -1141,6 +1143,10 @@ sole_tenant_config {
11411143

11421144
* `max_shared_clients_per_gpu` (Required) - The maximum number of containers that can share a GPU.
11431145

1146+
<a name="network_performance_config"></a>The `network_performance_config` block supports:
1147+
1148+
* `total_egress_bandwidth_tier` (Required) - Specifies the total network bandwidth tier for NodePools in the cluster.
1149+
11441150
<a name="nested_workload_identity_config"></a> The `workload_identity_config` block supports:
11451151

11461152
* `workload_pool` (Optional) - The workload pool to attach all Kubernetes service accounts to.

0 commit comments

Comments
 (0)