Skip to content

Commit ad90670

Browse files
authored
Add support for Network Tier configuration (#15083)
1 parent a70078b commit ad90670

File tree

4 files changed

+170
-0
lines changed

4 files changed

+170
-0
lines changed

mmv1/third_party/terraform/services/container/resource_container_cluster.go.tmpl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,22 @@ func ResourceContainerCluster() *schema.Resource {
18741874
},
18751875
},
18761876
},
1877+
"network_tier_config": {
1878+
Type: schema.TypeList,
1879+
MaxItems: 1,
1880+
Optional: true,
1881+
Computed: true,
1882+
Description: `Used to determine the default network tier for external IP addresses on cluster resources, such as node pools and load balancers.`,
1883+
Elem: &schema.Resource{
1884+
Schema: map[string]*schema.Schema{
1885+
"network_tier": {
1886+
Type: schema.TypeString,
1887+
Required: true,
1888+
Description: `Network tier configuration.`,
1889+
},
1890+
},
1891+
},
1892+
},
18771893
},
18781894
},
18791895
},
@@ -4359,6 +4375,24 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
43594375
log.Printf("[INFO] GKE cluster %s's AutoIpamConfig has been updated", d.Id())
43604376
}
43614377

4378+
if d.HasChange("ip_allocation_policy.0.network_tier_config.0.network_tier") {
4379+
req := &container.UpdateClusterRequest{
4380+
Update: &container.ClusterUpdate{
4381+
DesiredNetworkTierConfig: &container.NetworkTierConfig{
4382+
NetworkTier: d.Get("ip_allocation_policy.0.network_tier_config.0.network_tier").(string),
4383+
},
4384+
},
4385+
}
4386+
4387+
updateF := updateFunc(req, "updating NetworkTierConfig")
4388+
// Call update serially.
4389+
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
4390+
return err
4391+
}
4392+
4393+
log.Printf("[INFO] GKE cluster %s's NetworkTierConfig has been updated", d.Id())
4394+
}
4395+
43624396
if n, ok := d.GetOk("node_pool.#"); ok {
43634397
for i := 0; i < n.(int); i++ {
43644398
nodePoolInfo, err := extractNodePoolInformationFromCluster(d, config, clusterName)
@@ -5610,9 +5644,22 @@ func expandIPAllocationPolicy(configured interface{}, d *schema.ResourceData, ne
56105644
StackType: stackType,
56115645
PodCidrOverprovisionConfig: expandPodCidrOverprovisionConfig(config["pod_cidr_overprovision_config"]),
56125646
AutoIpamConfig: expandAutoIpamConfig(config["auto_ipam_config"]),
5647+
NetworkTierConfig: expandNetworkTierConfig(config["network_tier_config"]),
56135648
}, additionalIpRangesConfigs, nil
56145649
}
56155650

5651+
func expandNetworkTierConfig(configured interface{}) *container.NetworkTierConfig {
5652+
l := configured.([]interface{})
5653+
if len(l) == 0 || l[0] == nil {
5654+
return nil
5655+
}
5656+
5657+
config := l[0].(map[string]interface{})
5658+
return &container.NetworkTierConfig{
5659+
NetworkTier: config["network_tier"].(string),
5660+
}
5661+
}
5662+
56165663
func expandAutoIpamConfig(configured interface{}) *container.AutoIpamConfig {
56175664
l, ok := configured.([]interface{})
56185665
if !ok || len(l) == 0 || l[0] == nil {
@@ -7268,6 +7315,18 @@ func flattenAdditionalIpRangesConfigs(c []*container.AdditionalIPRangesConfig) [
72687315
return outRanges
72697316
}
72707317

7318+
func flattenNetworkTierConfig(ntc *container.NetworkTierConfig) []map[string]interface{} {
7319+
if ntc == nil {
7320+
return nil
7321+
}
7322+
7323+
return []map[string]interface{}{
7324+
{
7325+
"network_tier": ntc.NetworkTier,
7326+
},
7327+
}
7328+
}
7329+
72717330
func flattenIPAllocationPolicy(c *container.Cluster, d *schema.ResourceData, config *transport_tpg.Config) ([]map[string]interface{}, error) {
72727331
// If IP aliasing isn't enabled, none of the values in this block can be set.
72737332
if c == nil || c.IpAllocationPolicy == nil || !c.IpAllocationPolicy.UseIpAliases {
@@ -7300,6 +7359,7 @@ func flattenIPAllocationPolicy(c *container.Cluster, d *schema.ResourceData, con
73007359
"additional_pod_ranges_config": flattenAdditionalPodRangesConfig(c.IpAllocationPolicy),
73017360
"additional_ip_ranges_config": flattenAdditionalIpRangesConfigs(p.AdditionalIpRangesConfigs),
73027361
"auto_ipam_config": flattenAutoIpamConfig(p.AutoIpamConfig),
7362+
"network_tier_config": flattenNetworkTierConfig(p.NetworkTierConfig),
73037363
},
73047364
}, nil
73057365
}

mmv1/third_party/terraform/services/container/resource_container_cluster_meta.yaml.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ fields:
165165
- api_field: 'ipAllocationPolicy.autoIpamConfig.enabled'
166166
- api_field: 'ipAllocationPolicy.clusterIpv4CidrBlock'
167167
- api_field: 'ipAllocationPolicy.clusterSecondaryRangeName'
168+
- api_field: 'ipAllocationPolicy.networkTierConfig.networkTier'
168169
- field: 'ip_allocation_policy.pod_cidr_overprovision_config.disabled'
169170
api_field: 'ip_allocation_policy.pod_cidr_overprovision_config.disable'
170171
- api_field: 'ipAllocationPolicy.servicesIpv4CidrBlock'

mmv1/third_party/terraform/services/container/resource_container_cluster_test.go.tmpl

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6868,6 +6868,105 @@ func TestAccContainerCluster_withCpuCfsQuotaPool(t *testing.T) {
68686868
})
68696869
}
68706870

6871+
func TestAccContainerCluster_network_tier_config(t *testing.T) {
6872+
t.Parallel()
6873+
6874+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
6875+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
6876+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
6877+
6878+
acctest.VcrTest(t, resource.TestCase{
6879+
PreCheck: func() { acctest.AccTestPreCheck(t) },
6880+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
6881+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
6882+
Steps: []resource.TestStep{
6883+
{
6884+
Config: testAccContainerCluster_network_tier_config_none(clusterName, networkName, subnetworkName),
6885+
Check: resource.ComposeTestCheckFunc(
6886+
resource.TestCheckResourceAttr("google_container_cluster.primary", "ip_allocation_policy.0.network_tier_config.0.network_tier", "NETWORK_TIER_DEFAULT"),
6887+
),
6888+
},
6889+
{
6890+
ResourceName: "google_container_cluster.primary",
6891+
ImportState: true,
6892+
ImportStateVerify: true,
6893+
ImportStateVerifyIgnore: []string{"deletion_protection"},
6894+
},
6895+
{
6896+
Config: testAccContainerCluster_network_tier_config(clusterName, networkName, subnetworkName, "NETWORK_TIER_PREMIUM"),
6897+
ConfigPlanChecks: resource.ConfigPlanChecks{
6898+
PreApply: []plancheck.PlanCheck{
6899+
plancheck.ExpectResourceAction("google_container_cluster.primary", plancheck.ResourceActionUpdate),
6900+
},
6901+
},
6902+
},
6903+
{
6904+
ResourceName: "google_container_cluster.primary",
6905+
ImportState: true,
6906+
ImportStateVerify: true,
6907+
ImportStateVerifyIgnore: []string{"deletion_protection"},
6908+
},
6909+
{
6910+
Config: testAccContainerCluster_network_tier_config(clusterName, networkName, subnetworkName, "NETWORK_TIER_STANDARD"),
6911+
ConfigPlanChecks: resource.ConfigPlanChecks{
6912+
PreApply: []plancheck.PlanCheck{
6913+
plancheck.ExpectResourceAction("google_container_cluster.primary", plancheck.ResourceActionUpdate),
6914+
},
6915+
},
6916+
},
6917+
{
6918+
ResourceName: "google_container_cluster.primary",
6919+
ImportState: true,
6920+
ImportStateVerify: true,
6921+
ImportStateVerifyIgnore: []string{"deletion_protection"},
6922+
},
6923+
},
6924+
})
6925+
}
6926+
6927+
func testAccContainerCluster_network_tier_config(clusterName, networkName, subnetworkName, networkTier string) string {
6928+
return fmt.Sprintf(`
6929+
resource "google_container_cluster" "primary" {
6930+
name = "%s"
6931+
location = "us-central1-a"
6932+
initial_node_count = 2
6933+
dns_config {
6934+
cluster_dns = "CLOUD_DNS"
6935+
}
6936+
6937+
network = "%s"
6938+
subnetwork = "%s"
6939+
6940+
deletion_protection = false
6941+
6942+
ip_allocation_policy {
6943+
network_tier_config {
6944+
network_tier = "%s"
6945+
}
6946+
}
6947+
}`, clusterName, networkName, subnetworkName, networkTier)
6948+
}
6949+
6950+
func testAccContainerCluster_network_tier_config_none(clusterName, networkName, subnetworkName string) string {
6951+
return fmt.Sprintf(`
6952+
resource "google_container_cluster" "primary" {
6953+
name = "%s"
6954+
location = "us-central1-a"
6955+
initial_node_count = 2
6956+
dns_config {
6957+
cluster_dns = "CLOUD_DNS"
6958+
}
6959+
6960+
network = "%s"
6961+
subnetwork = "%s"
6962+
6963+
deletion_protection = false
6964+
6965+
ip_allocation_policy {
6966+
}
6967+
}`, clusterName, networkName, subnetworkName)
6968+
}
6969+
68716970
func testAccContainerCluster_masterAuthorizedNetworksDisabled(t *testing.T, resource_name string) resource.TestCheckFunc {
68726971
return func(s *terraform.State) error {
68736972
rs, ok := s.RootModule().Resources[resource_name]

mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,8 @@ Structure is [documented below](#nested_additional_ip_ranges_config).
831831

832832
* `auto_ipam_config` - (Optional) All the information related to Auto IPAM. Structure is [documented below](#nested_auto_ipam_config)
833833

834+
* `network_tier_config` - (Optional) Contains network tier information. Structure is [documented below](#nested_network_tier_config)
835+
834836
<a name="nested_auto_ipam_config"></a>The auto ipam config supports:
835837

836838
* `enabled` - (Required) The flag that enables Auto IPAM on this cluster.
@@ -847,6 +849,14 @@ Structure is [documented below](#nested_additional_ip_ranges_config).
847849

848850
* `pod_ipv4_range_names`- (Required) List of secondary ranges names within this subnetwork that can be used for pod IPs.
849851

852+
<a name="nested_network_tier_config"></a>The `network_tier_config` block supports:
853+
854+
* `network_tier` - (Required) Network tier configuration.
855+
Accepted values are:
856+
* `NETWORK_TIER_DEFAULT`: (Default) Use project-level configuration.
857+
* `NETWORK_TIER_PREMIUM`: Premium network tier.
858+
* `NETWORK_TIER_STANDARD`: Standard network tier.
859+
850860

851861
<a name="nested_master_auth"></a>The `master_auth` block supports:
852862

0 commit comments

Comments
 (0)