Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,24 @@ func ResourceContainerCluster() *schema.Resource {
},
},
},
"network_tier_config": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Description: `Used to determine the default network tier for external IP addresses on cluster resources, such as node pools and load balancers.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network_tier": {
Type: schema.TypeString,
Optional: true,
Default: "NETWORK_TIER_DEFAULT",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend marking this as Required: true so that if the network_tier_config block is specified, users must provide a value for network_tier.

Generally we try to avoid allowing empty blocks (unless they have a special meaning separate from the block being omitted.)

Suggested change
Optional: true,
Default: "NETWORK_TIER_DEFAULT",
Required: true,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

ValidateFunc: validation.StringInSlice([]string{"NETWORK_TIER_DEFAULT", "NETWORK_TIER_STANDARD", "NETWORK_TIER_PREMIUM"}, false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a chance that more values will be added in the future, you might want to leave off the validation func so that the field will be forwards-compatible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Description: `Network tier configuration.`,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -4359,6 +4377,24 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
log.Printf("[INFO] GKE cluster %s's AutoIpamConfig has been updated", d.Id())
}

if d.HasChange("ip_allocation_policy.0.network_tier_config.0.network_tier") {
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredNetworkTierConfig: &container.NetworkTierConfig{
NetworkTier: d.Get("ip_allocation_policy.0.network_tier_config.0.network_tier").(string),
},
},
}

updateF := updateFunc(req, "updating NetworkTierConfig")
// Call update serially.
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s's NetworkTierConfig has been updated", d.Id())
}

if n, ok := d.GetOk("node_pool.#"); ok {
for i := 0; i < n.(int); i++ {
nodePoolInfo, err := extractNodePoolInformationFromCluster(d, config, clusterName)
Expand Down Expand Up @@ -5610,9 +5646,22 @@ func expandIPAllocationPolicy(configured interface{}, d *schema.ResourceData, ne
StackType: stackType,
PodCidrOverprovisionConfig: expandPodCidrOverprovisionConfig(config["pod_cidr_overprovision_config"]),
AutoIpamConfig: expandAutoIpamConfig(config["auto_ipam_config"]),
NetworkTierConfig: expandNetworkTierConfig(config["network_tier_config"]),
}, additionalIpRangesConfigs, nil
}

func expandNetworkTierConfig(configured interface{}) *container.NetworkTierConfig {
l := configured.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil
}

config := l[0].(map[string]interface{})
return &container.NetworkTierConfig{
NetworkTier: config["network_tier"].(string),
}
}

func expandAutoIpamConfig(configured interface{}) *container.AutoIpamConfig {
l, ok := configured.([]interface{})
if !ok || len(l) == 0 || l[0] == nil {
Expand Down Expand Up @@ -7268,6 +7317,18 @@ func flattenAdditionalIpRangesConfigs(c []*container.AdditionalIPRangesConfig) [
return outRanges
}

func flattenNetworkTierConfig(ntc *container.NetworkTierConfig) []map[string]interface{} {
if ntc == nil {
return nil
}

return []map[string]interface{}{
{
"network_tier": ntc.NetworkTier,
},
}
}

func flattenIPAllocationPolicy(c *container.Cluster, d *schema.ResourceData, config *transport_tpg.Config) ([]map[string]interface{}, error) {
// If IP aliasing isn't enabled, none of the values in this block can be set.
if c == nil || c.IpAllocationPolicy == nil || !c.IpAllocationPolicy.UseIpAliases {
Expand Down Expand Up @@ -7300,6 +7361,7 @@ func flattenIPAllocationPolicy(c *container.Cluster, d *schema.ResourceData, con
"additional_pod_ranges_config": flattenAdditionalPodRangesConfig(c.IpAllocationPolicy),
"additional_ip_ranges_config": flattenAdditionalIpRangesConfigs(p.AdditionalIpRangesConfigs),
"auto_ipam_config": flattenAutoIpamConfig(p.AutoIpamConfig),
"network_tier_config": flattenNetworkTierConfig(p.NetworkTierConfig),
},
}, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ fields:
- api_field: 'ipAllocationPolicy.autoIpamConfig.enabled'
- api_field: 'ipAllocationPolicy.clusterIpv4CidrBlock'
- api_field: 'ipAllocationPolicy.clusterSecondaryRangeName'
- api_field: 'ipAllocationPolicy.networkTierConfig.networkTier'
- field: 'ip_allocation_policy.pod_cidr_overprovision_config.disabled'
api_field: 'ip_allocation_policy.pod_cidr_overprovision_config.disable'
- api_field: 'ipAllocationPolicy.servicesIpv4CidrBlock'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6868,6 +6868,101 @@ func TestAccContainerCluster_withCpuCfsQuotaPool(t *testing.T) {
})
}

func TestAccContainerCluster_network_tier_config(t *testing.T) {
t.Parallel()

clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_network_tier_config_none(clusterName, networkName, subnetworkName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.primary", "ip_allocation_policy.0.network_tier_config.0.network_tier", "NETWORK_TIER_DEFAULT"),
),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_network_tier_config(clusterName, networkName, subnetworkName, "NETWORK_TIER_PREMIUM"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.primary", "ip_allocation_policy.0.network_tier_config.0.network_tier", "NETWORK_TIER_PREMIUM"),
),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_network_tier_config(clusterName, networkName, subnetworkName, "NETWORK_TIER_STANDARD"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.primary", "ip_allocation_policy.0.network_tier_config.0.network_tier", "NETWORK_TIER_STANDARD"),
),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
},
})
}

func testAccContainerCluster_network_tier_config(clusterName, networkName, subnetworkName, networkTier string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-a"
initial_node_count = 2
dns_config {
cluster_dns = "CLOUD_DNS"
}

network = "%s"
subnetwork = "%s"

deletion_protection = false

ip_allocation_policy {
network_tier_config {
network_tier = "%s"
}
}
}`, clusterName, networkName, subnetworkName, networkTier)
}

func testAccContainerCluster_network_tier_config_none(clusterName, networkName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-a"
initial_node_count = 2
dns_config {
cluster_dns = "CLOUD_DNS"
}

network = "%s"
subnetwork = "%s"

deletion_protection = false

ip_allocation_policy {
}
}`, clusterName, networkName, subnetworkName)
}

func testAccContainerCluster_masterAuthorizedNetworksDisabled(t *testing.T, resource_name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resource_name]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ Structure is [documented below](#nested_additional_ip_ranges_config).

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

* `network_tier_config` - (Optional) Contains network tier information. Structure is [documented below](#nested_network_tier_config)

<a name="nested_auto_ipam_config"></a>The auto ipam config supports:

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

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

<a name="nested_network_tier_config"></a>The `network_tier_config` block supports:

* `network_tier` - (Optional) Network tier configuration.
Accepted values are:
* `NETWORK_TIER_DEFAULT`: Use project-level configuration.
* `NETWORK_TIER_PREMIUM`: Premium network tier.
* `NETWORK_TIER_STANDARD`: Standard network tier.


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

Expand Down
Loading