-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add support for Network Tier configuration #15083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
89e90e7
7703031
5e3f23c
d0c9161
8da58c5
6273a8e
82c1202
3acca55
58c74a1
9fc8764
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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", | ||
| ValidateFunc: validation.StringInSlice([]string{"NETWORK_TIER_DEFAULT", "NETWORK_TIER_STANDARD", "NETWORK_TIER_PREMIUM"}, false), | ||
|
||
| Description: `Network tier configuration.`, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
@@ -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) | ||
|
|
@@ -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 { | ||
|
|
@@ -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 { | ||
|
|
@@ -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 | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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: trueso 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.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done