From 2e837b8101ba599d6b96c265ce8c00a1b56ab897 Mon Sep 17 00:00:00 2001 From: Chris Sng Date: Fri, 20 Sep 2019 19:24:09 +0800 Subject: [PATCH 01/15] Add Release Channel config for GKE --- products/container/api.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/products/container/api.yaml b/products/container/api.yaml index e8f53dad2e64..dc72ec260a54 100644 --- a/products/container/api.yaml +++ b/products/container/api.yaml @@ -466,6 +466,20 @@ objects: enabled, identities in the system, including service accounts, nodes, and controllers, will have statically granted permissions beyond those provided by the RBAC configuration or IAM. + - !ruby/object:Api::Type::NestedObject + name: 'releaseChannel' + min_version: beta + description: | + Release channel configuration. + properties: + - !ruby/object:Api::Type::Enum + name: 'channel' + description: channel specifies which release channel the cluster is subscribed to. + values: + - "UNSPECIFIED" + - "RAPID" + - "REGULAR" + - "STABLE" - !ruby/object:Api::Type::NestedObject name: 'networkPolicy' description: | From f38ce4bb9edea146c8d7200a8b75b5822eba576d Mon Sep 17 00:00:00 2001 From: Chris Sng Date: Sat, 21 Sep 2019 17:03:51 +0800 Subject: [PATCH 02/15] Terraform only --- products/container/api.yaml | 14 -------------- .../resource_container_cluster.go.erb | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/products/container/api.yaml b/products/container/api.yaml index dc72ec260a54..e8f53dad2e64 100644 --- a/products/container/api.yaml +++ b/products/container/api.yaml @@ -466,20 +466,6 @@ objects: enabled, identities in the system, including service accounts, nodes, and controllers, will have statically granted permissions beyond those provided by the RBAC configuration or IAM. - - !ruby/object:Api::Type::NestedObject - name: 'releaseChannel' - min_version: beta - description: | - Release channel configuration. - properties: - - !ruby/object:Api::Type::Enum - name: 'channel' - description: channel specifies which release channel the cluster is subscribed to. - values: - - "UNSPECIFIED" - - "RAPID" - - "REGULAR" - - "STABLE" - !ruby/object:Api::Type::NestedObject name: 'networkPolicy' description: | diff --git a/third_party/terraform/resources/resource_container_cluster.go.erb b/third_party/terraform/resources/resource_container_cluster.go.erb index cf09740c5d06..54245f240b98 100644 --- a/third_party/terraform/resources/resource_container_cluster.go.erb +++ b/third_party/terraform/resources/resource_container_cluster.go.erb @@ -711,6 +711,24 @@ func resourceContainerCluster() *schema.Resource { }, }, + "release_channel": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "provider": { + Type: schema.TypeString, + Default: "UNSPECIFIED", + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"UNSPECIFIED", "RAPID", "REGULAR", "STABLE"}, false), + DiffSuppressFunc: emptyOrDefaultStringSuppress("UNSPECIFIED"), + }, + }, + }, + }, + "resource_labels": { Type: schema.TypeMap, Optional: true, From be719473b3a76356a1663b2dfc2050d509031661 Mon Sep 17 00:00:00 2001 From: Chris Sng Date: Wed, 2 Oct 2019 11:35:18 +0800 Subject: [PATCH 03/15] Create and write state --- .../resource_container_cluster.go.erb | 32 +++++++++++++++- .../resource_container_cluster_test.go.erb | 38 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/third_party/terraform/resources/resource_container_cluster.go.erb b/third_party/terraform/resources/resource_container_cluster.go.erb index 54245f240b98..a9b071e8a2a7 100644 --- a/third_party/terraform/resources/resource_container_cluster.go.erb +++ b/third_party/terraform/resources/resource_container_cluster.go.erb @@ -718,7 +718,7 @@ func resourceContainerCluster() *schema.Resource { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "provider": { + "channel": { Type: schema.TypeString, Default: "UNSPECIFIED", Optional: true, @@ -975,6 +975,7 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er Enabled: d.Get("enable_shielded_nodes").(bool), ForceSendFields: []string{"Enabled"}, }, + ReleaseChannel: expandReleaseChannel(d.Get("release_channel")), EnableTpu: d.Get("enable_tpu").(bool), BinaryAuthorization: &containerBeta.BinaryAuthorization{ Enabled: d.Get("enable_binary_authorization").(bool), @@ -1238,6 +1239,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro if err := d.Set("authenticator_groups_config", flattenAuthenticatorGroupsConfig(cluster.AuthenticatorGroupsConfig)); err != nil { return err } + if err := d.Set("release_channel", flattenReleaseChannel(cluster.ReleaseChannel)); err != nil { + return err + } d.Set("enable_intranode_visibility", cluster.NetworkConfig.EnableIntraNodeVisibility) <% else -%> if err := d.Set("cluster_autoscaling", nil); err != nil { @@ -2376,6 +2380,17 @@ func expandPrivateClusterConfig(configured interface{}) *containerBeta.PrivateCl } <% unless version == 'ga' -%> +func expandReleaseChannel(configured interface{}) *containerBeta.ReleaseChannel { + l := configured.([]interface{}) + if len(l) == 0 { + return nil + } + config := l[0].(map[string]interface{}) + return &containerBeta.ReleaseChannel{ + Channel: config["channel"].(string), + } +} + func expandDatabaseEncryption(configured interface{}) *containerBeta.DatabaseEncryption { l := configured.([]interface{}) if len(l) == 0 { @@ -2582,6 +2597,21 @@ func flattenPrivateClusterConfig(c *containerBeta.PrivateClusterConfig) []map[st } <% unless version == 'ga' -%> +func flattenReleaseChannel(c *containerBeta.ReleaseChannel) []map[string]interface{} { + result := []map[string]interface{}{} + if c != nil { + result = append(result, map[string]interface{}{ + "channel": c.Channel, + }) + } else { + // Explicitly set the network policy to the default. + result = append(result, map[string]interface{}{ + "channel": "UNSPECIFIED", + }) + } + return result +} + func flattenVerticalPodAutoscaling(c *containerBeta.VerticalPodAutoscaling) []map[string]interface{} { if c == nil { return nil diff --git a/third_party/terraform/tests/resource_container_cluster_test.go.erb b/third_party/terraform/tests/resource_container_cluster_test.go.erb index 7e7538e8748c..80e5489179b1 100644 --- a/third_party/terraform/tests/resource_container_cluster_test.go.erb +++ b/third_party/terraform/tests/resource_container_cluster_test.go.erb @@ -361,6 +361,29 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) { }) } +<% unless version == 'ga' -%> +func TestAccContainerCluster_withReleaseChannel(t *testing.T) { + t.Parallel() + clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccContainerCluster_withReleaseChannel(clusterName, "STABLE"), + }, + { + ResourceName: "google_container_cluster.with_release_channel", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} +<% end -%> + func TestAccContainerCluster_withMasterAuthorizedNetworksConfig(t *testing.T) { t.Parallel() @@ -1970,6 +1993,21 @@ resource "google_container_cluster" "with_network_policy_enabled" { }`, clusterName) } +<% unless version == 'ga' -%> +func testAccContainerCluster_withReleaseChannel(clusterName string, channel string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "with_release_channel" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + + release_channel { + channel = "%s" + } +}`, clusterName, channel) +} +<% end -%> + func testAccContainerCluster_removeNetworkPolicy(clusterName string) string { return fmt.Sprintf(` resource "google_container_cluster" "with_network_policy_enabled" { From 4f5cb99ae6fabb77e3ce44e8134a944dace077e1 Mon Sep 17 00:00:00 2001 From: Chris Sng Date: Wed, 2 Oct 2019 12:09:46 +0800 Subject: [PATCH 04/15] dont suppress default val --- .../terraform/resources/resource_container_cluster.go.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/third_party/terraform/resources/resource_container_cluster.go.erb b/third_party/terraform/resources/resource_container_cluster.go.erb index a9b071e8a2a7..89f36cc6690d 100644 --- a/third_party/terraform/resources/resource_container_cluster.go.erb +++ b/third_party/terraform/resources/resource_container_cluster.go.erb @@ -723,7 +723,6 @@ func resourceContainerCluster() *schema.Resource { Default: "UNSPECIFIED", Optional: true, ValidateFunc: validation.StringInSlice([]string{"UNSPECIFIED", "RAPID", "REGULAR", "STABLE"}, false), - DiffSuppressFunc: emptyOrDefaultStringSuppress("UNSPECIFIED"), }, }, }, From acb75c804d179773c8bf8118b94336215f6f4219 Mon Sep 17 00:00:00 2001 From: Chris Sng Date: Wed, 2 Oct 2019 12:58:54 +0800 Subject: [PATCH 05/15] more tests --- .../terraform/resources/resource_container_cluster.go.erb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/third_party/terraform/resources/resource_container_cluster.go.erb b/third_party/terraform/resources/resource_container_cluster.go.erb index 89f36cc6690d..862aabc72b3d 100644 --- a/third_party/terraform/resources/resource_container_cluster.go.erb +++ b/third_party/terraform/resources/resource_container_cluster.go.erb @@ -713,6 +713,7 @@ func resourceContainerCluster() *schema.Resource { "release_channel": { Type: schema.TypeList, + ForceNew: true, Optional: true, Computed: true, MaxItems: 1, @@ -722,7 +723,9 @@ func resourceContainerCluster() *schema.Resource { Type: schema.TypeString, Default: "UNSPECIFIED", Optional: true, + ForceNew: true, ValidateFunc: validation.StringInSlice([]string{"UNSPECIFIED", "RAPID", "REGULAR", "STABLE"}, false), + DiffSuppressFunc: emptyOrDefaultStringSuppress("UNSPECIFIED"), }, }, }, @@ -2381,7 +2384,7 @@ func expandPrivateClusterConfig(configured interface{}) *containerBeta.PrivateCl <% unless version == 'ga' -%> func expandReleaseChannel(configured interface{}) *containerBeta.ReleaseChannel { l := configured.([]interface{}) - if len(l) == 0 { + if len(l) == 0 || l[0] == nil { return nil } config := l[0].(map[string]interface{}) From 0d585fd9183cba9b2838800c21fddc6dda2ab4f6 Mon Sep 17 00:00:00 2001 From: Chris Sng Date: Wed, 2 Oct 2019 13:28:43 +0800 Subject: [PATCH 06/15] more tests --- .../resource_container_cluster_test.go.erb | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/third_party/terraform/tests/resource_container_cluster_test.go.erb b/third_party/terraform/tests/resource_container_cluster_test.go.erb index 80e5489179b1..88d06e7d74ec 100644 --- a/third_party/terraform/tests/resource_container_cluster_test.go.erb +++ b/third_party/terraform/tests/resource_container_cluster_test.go.erb @@ -362,7 +362,7 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) { } <% unless version == 'ga' -%> -func TestAccContainerCluster_withReleaseChannel(t *testing.T) { +func TestAccContainerCluster_withReleaseChannelEnabled(t *testing.T) { t.Parallel() clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10)) resource.Test(t, resource.TestCase{ @@ -371,7 +371,46 @@ func TestAccContainerCluster_withReleaseChannel(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccContainerCluster_withReleaseChannel(clusterName, "STABLE"), + Config: testAccContainerCluster_withReleaseChannelEnabled(clusterName, "STABLE"), + }, + { + ResourceName: "google_container_cluster.with_release_channel", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccContainerCluster_withReleaseChannelEnabled(clusterName, "REGULAR"), + }, + { + ResourceName: "google_container_cluster.with_release_channel", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccContainerCluster_withReleaseChannelEnabled(clusterName, "RAPID"), + }, + { + ResourceName: "google_container_cluster.with_release_channel", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccContainerCluster_withReleaseChannelDisabled(t *testing.T) { + t.Parallel() + clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccContainerCluster_withReleaseChannelDisabled(clusterName), }, { ResourceName: "google_container_cluster.with_release_channel", @@ -1994,7 +2033,7 @@ resource "google_container_cluster" "with_network_policy_enabled" { } <% unless version == 'ga' -%> -func testAccContainerCluster_withReleaseChannel(clusterName string, channel string) string { +func testAccContainerCluster_withReleaseChannelEnabled(clusterName string, channel string) string { return fmt.Sprintf(` resource "google_container_cluster" "with_release_channel" { name = "%s" @@ -2006,6 +2045,17 @@ resource "google_container_cluster" "with_release_channel" { } }`, clusterName, channel) } + +func testAccContainerCluster_withReleaseChannelDisabled(clusterName string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "with_release_channel" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + + release_channel {} +}`, clusterName) +} <% end -%> func testAccContainerCluster_removeNetworkPolicy(clusterName string) string { From b0e2f12fe0e4b384be2ffeb5364cf930b4ece221 Mon Sep 17 00:00:00 2001 From: Chris Sng Date: Wed, 2 Oct 2019 13:28:54 +0800 Subject: [PATCH 07/15] Update docs --- .../docs/r/container_cluster.html.markdown | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/third_party/terraform/website/docs/r/container_cluster.html.markdown b/third_party/terraform/website/docs/r/container_cluster.html.markdown index b82307a2754e..9f7b7ed14810 100644 --- a/third_party/terraform/website/docs/r/container_cluster.html.markdown +++ b/third_party/terraform/website/docs/r/container_cluster.html.markdown @@ -156,7 +156,7 @@ in this cluster in CIDR notation (e.g. 10.96.0.0/14). Leave blank to have one automatically chosen or specify a /14 block in 10.0.0.0/8. This field will only work if your cluster is not VPC-native- when an `ip_allocation_policy` block is not defined, or `ip_allocation_policy.use_ip_aliases` is set to false. If your -cluster is VPC-native, use `ip_allocation_policy.cluster_ipv4_cidr_block`. +cluster is VPC-native, use `ip_allocation_policy.cluster_ipv4_cidr_block`. * `cluster_autoscaling` - (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) Per-cluster configuration of Node Auto-Provisioning with Cluster Autoscaler to @@ -289,6 +289,10 @@ to the datasource. A `region` can have a different set of supported versions tha * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `release_channel` - (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) Configuration options for the + [Release channel](https://cloud.google.com/kubernetes-engine/docs/concepts/release-channels) + feature, which provide more control over automatic upgrades of your GKE clusters. Structure is documented below. + * `remove_default_node_pool` - (Optional) If `true`, deletes the default node pool upon cluster creation. If you're using `google_container_node_pool` resources with no default node pool, this should be set to `true`, alongside @@ -433,7 +437,7 @@ to have a range chosen with a specific netmask. Set to a CIDR notation (e.g. 10. from the RFC-1918 private networks (e.g. 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) to pick a specific range to use. This field will only work if your cluster is VPC-native- when `ip_allocation_policy.use_ip_aliases` is undefined or set to -true. If your cluster is not VPC-native, use `cluster_ipv4_cidr`. +true. If your cluster is not VPC-native, use `cluster_ipv4_cidr`. * `node_ipv4_cidr_block` - (Optional) The IP address range of the node IPs in this cluster. This should be set only if `create_subnetwork` is true. @@ -547,7 +551,7 @@ The `node_config` block supports: are preemptible. See the [official documentation](https://cloud.google.com/container-engine/docs/preemptible-vm) for more information. Defaults to false. -* `sandbox_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) [GKE Sandbox](https://cloud.google.com/kubernetes-engine/docs/how-to/sandbox-pods) configuration. When enabling this feature you must specify `image_type = "COS_CONTAINERD"` and `node_version = "1.12.7-gke.17"` or later to use it. +* `sandbox_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) [GKE Sandbox](https://cloud.google.com/kubernetes-engine/docs/how-to/sandbox-pods) configuration. When enabling this feature you must specify `image_type = "COS_CONTAINERD"` and `node_version = "1.12.7-gke.17"` or later to use it. Structure is documented below. * `service_account` - (Optional) The service account to be used by the Node VMs. @@ -614,6 +618,15 @@ The `sandbox_type` block supports: * `"gvisor"`: Pods run within a gVisor sandbox. +The `release_channel` block supports: + +* `channel` - (Optional) The selected release channel. Defaults to `UNSPECIFIED`. + Accepted values are: + * UNSPECIFIED: Not set. + * RAPID: Weekly upgrade cadence; Early testers and developers who requires new features. + * REGULAR: Multiple per month upgrade cadence; Production users who need features not yet offered in the Stable channel. + * STABLE: Every few months upgrade cadence; Production users who need stability above all else, and for whom frequent upgrades are too risky. + The `resource_usage_export_config` block supports: * `enable_network_egress_metering` (Optional) - Whether to enable network egress metering for this cluster. If enabled, a daemonset will be created From c2a7517e0d45c2eb284647e361030f6603782a59 Mon Sep 17 00:00:00 2001 From: Chris Sng Date: Wed, 2 Oct 2019 13:46:31 +0800 Subject: [PATCH 08/15] fix tab formatting --- .../terraform/resources/resource_container_cluster.go.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/third_party/terraform/resources/resource_container_cluster.go.erb b/third_party/terraform/resources/resource_container_cluster.go.erb index 862aabc72b3d..40d4606f7d32 100644 --- a/third_party/terraform/resources/resource_container_cluster.go.erb +++ b/third_party/terraform/resources/resource_container_cluster.go.erb @@ -1241,9 +1241,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro if err := d.Set("authenticator_groups_config", flattenAuthenticatorGroupsConfig(cluster.AuthenticatorGroupsConfig)); err != nil { return err } - if err := d.Set("release_channel", flattenReleaseChannel(cluster.ReleaseChannel)); err != nil { - return err - } + if err := d.Set("release_channel", flattenReleaseChannel(cluster.ReleaseChannel)); err != nil { + return err + } d.Set("enable_intranode_visibility", cluster.NetworkConfig.EnableIntraNodeVisibility) <% else -%> if err := d.Set("cluster_autoscaling", nil); err != nil { From 85d9ebabc3fd7063679829e7f950f3f7aaed4cef Mon Sep 17 00:00:00 2001 From: Chris Sng Date: Wed, 2 Oct 2019 13:49:03 +0800 Subject: [PATCH 09/15] fix tab formatting --- .../terraform/tests/resource_container_cluster_test.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/terraform/tests/resource_container_cluster_test.go.erb b/third_party/terraform/tests/resource_container_cluster_test.go.erb index 88d06e7d74ec..fdd7cf63fd02 100644 --- a/third_party/terraform/tests/resource_container_cluster_test.go.erb +++ b/third_party/terraform/tests/resource_container_cluster_test.go.erb @@ -409,7 +409,7 @@ func TestAccContainerCluster_withReleaseChannelDisabled(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckContainerClusterDestroy, Steps: []resource.TestStep{ - { + { Config: testAccContainerCluster_withReleaseChannelDisabled(clusterName), }, { From ad20a901b0140cc22e11153e20cea7c81a68376e Mon Sep 17 00:00:00 2001 From: Chris Sng Date: Tue, 15 Oct 2019 11:01:20 +0800 Subject: [PATCH 10/15] Move schema to beta, fix typos --- .../resources/resource_container_cluster.go.erb | 14 +++++++------- .../tests/resource_container_cluster_test.go.erb | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/third_party/terraform/resources/resource_container_cluster.go.erb b/third_party/terraform/resources/resource_container_cluster.go.erb index 40d4606f7d32..20ae5b4dae48 100644 --- a/third_party/terraform/resources/resource_container_cluster.go.erb +++ b/third_party/terraform/resources/resource_container_cluster.go.erb @@ -711,6 +711,13 @@ func resourceContainerCluster() *schema.Resource { }, }, + "resource_labels": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + +<% unless version == 'ga' -%> "release_channel": { Type: schema.TypeList, ForceNew: true, @@ -721,11 +728,9 @@ func resourceContainerCluster() *schema.Resource { Schema: map[string]*schema.Schema{ "channel": { Type: schema.TypeString, - Default: "UNSPECIFIED", Optional: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{"UNSPECIFIED", "RAPID", "REGULAR", "STABLE"}, false), - DiffSuppressFunc: emptyOrDefaultStringSuppress("UNSPECIFIED"), }, }, }, @@ -2605,11 +2610,6 @@ func flattenReleaseChannel(c *containerBeta.ReleaseChannel) []map[string]interfa result = append(result, map[string]interface{}{ "channel": c.Channel, }) - } else { - // Explicitly set the network policy to the default. - result = append(result, map[string]interface{}{ - "channel": "UNSPECIFIED", - }) } return result } diff --git a/third_party/terraform/tests/resource_container_cluster_test.go.erb b/third_party/terraform/tests/resource_container_cluster_test.go.erb index fdd7cf63fd02..eb757a7afc5a 100644 --- a/third_party/terraform/tests/resource_container_cluster_test.go.erb +++ b/third_party/terraform/tests/resource_container_cluster_test.go.erb @@ -2048,7 +2048,7 @@ resource "google_container_cluster" "with_release_channel" { func testAccContainerCluster_withReleaseChannelDisabled(clusterName string) string { return fmt.Sprintf(` -resource "google_container_cluster" "with_release_channel" { +resource "google_container_cluster" "without_release_channel" { name = "%s" location = "us-central1-a" initial_node_count = 1 From cd4687050781dfcde951c1853ef013e1d0bc821b Mon Sep 17 00:00:00 2001 From: Chris Sng Date: Tue, 15 Oct 2019 11:59:34 +0800 Subject: [PATCH 11/15] test for invalid release channel --- .../resource_container_cluster_test.go.erb | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/third_party/terraform/tests/resource_container_cluster_test.go.erb b/third_party/terraform/tests/resource_container_cluster_test.go.erb index eb757a7afc5a..af68fdd80f8e 100644 --- a/third_party/terraform/tests/resource_container_cluster_test.go.erb +++ b/third_party/terraform/tests/resource_container_cluster_test.go.erb @@ -397,11 +397,20 @@ func TestAccContainerCluster_withReleaseChannelEnabled(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccContainerCluster_withReleaseChannelEnabled(clusterName, "UNSPECIFIED"), + }, + { + ResourceName: "google_container_cluster.with_release_channel", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + }, }, }) } -func TestAccContainerCluster_withReleaseChannelDisabled(t *testing.T) { +func TestAccContainerCluster_withInvalidReleaseChannel(t *testing.T) { t.Parallel() clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10)) resource.Test(t, resource.TestCase{ @@ -410,13 +419,8 @@ func TestAccContainerCluster_withReleaseChannelDisabled(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccContainerCluster_withReleaseChannelDisabled(clusterName), - }, - { - ResourceName: "google_container_cluster.with_release_channel", - ImportStateIdPrefix: "us-central1-a/", - ImportState: true, - ImportStateVerify: true, + Config: testAccContainerCluster_withReleaseChannelEnabled(clusterName, "CANARY"), + ExpectError: regexp.MustCompile(`config is invalid: expected release_channel\.0\.channel to be one of \[UNSPECIFIED RAPID REGULAR STABLE\], got CANARY`), }, }, }) @@ -2045,17 +2049,6 @@ resource "google_container_cluster" "with_release_channel" { } }`, clusterName, channel) } - -func testAccContainerCluster_withReleaseChannelDisabled(clusterName string) string { - return fmt.Sprintf(` -resource "google_container_cluster" "without_release_channel" { - name = "%s" - location = "us-central1-a" - initial_node_count = 1 - - release_channel {} -}`, clusterName) -} <% end -%> func testAccContainerCluster_removeNetworkPolicy(clusterName string) string { From c1d8b7213cdc28280df9ef79111465320b11d454 Mon Sep 17 00:00:00 2001 From: Chris Sng Date: Tue, 15 Oct 2019 14:57:04 +0800 Subject: [PATCH 12/15] nil as unspecified, test for invalid channels --- .../resource_container_cluster.go.erb | 7 +++++ .../resource_container_cluster_test.go.erb | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/third_party/terraform/resources/resource_container_cluster.go.erb b/third_party/terraform/resources/resource_container_cluster.go.erb index 20ae5b4dae48..4442e3df378e 100644 --- a/third_party/terraform/resources/resource_container_cluster.go.erb +++ b/third_party/terraform/resources/resource_container_cluster.go.erb @@ -728,9 +728,11 @@ func resourceContainerCluster() *schema.Resource { Schema: map[string]*schema.Schema{ "channel": { Type: schema.TypeString, + Default: "UNSPECIFIED", Optional: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{"UNSPECIFIED", "RAPID", "REGULAR", "STABLE"}, false), + DiffSuppressFunc: emptyOrDefaultStringSuppress("UNSPECIFIED"), }, }, }, @@ -2610,6 +2612,11 @@ func flattenReleaseChannel(c *containerBeta.ReleaseChannel) []map[string]interfa result = append(result, map[string]interface{}{ "channel": c.Channel, }) + } else { + // Explicitly set the release channel to the default. + result = append(result, map[string]interface{}{ + "channel": "UNSPECIFIED", + }) } return result } diff --git a/third_party/terraform/tests/resource_container_cluster_test.go.erb b/third_party/terraform/tests/resource_container_cluster_test.go.erb index af68fdd80f8e..4d7990c33210 100644 --- a/third_party/terraform/tests/resource_container_cluster_test.go.erb +++ b/third_party/terraform/tests/resource_container_cluster_test.go.erb @@ -410,6 +410,27 @@ func TestAccContainerCluster_withReleaseChannelEnabled(t *testing.T) { }) } +func TestAccContainerCluster_withReleaseChannelDefault(t *testing.T) { + t.Parallel() + clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccContainerCluster_withReleaseChannelDefault(clusterName), + }, + { + ResourceName: "google_container_cluster.with_default_release_channel", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccContainerCluster_withInvalidReleaseChannel(t *testing.T) { t.Parallel() clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10)) @@ -2049,6 +2070,16 @@ resource "google_container_cluster" "with_release_channel" { } }`, clusterName, channel) } + +func testAccContainerCluster_withReleaseChannelDefault(clusterName string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "with_default_release_channel" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + release_channel {} +}`, clusterName) +} <% end -%> func testAccContainerCluster_removeNetworkPolicy(clusterName string) string { From 209d5bf2761306df776df07f387e7170073dc3f2 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Tue, 15 Oct 2019 13:55:55 -0700 Subject: [PATCH 13/15] Fix an extra erb tag from my rebase --- .../resource_container_cluster.go.erb | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/third_party/terraform/resources/resource_container_cluster.go.erb b/third_party/terraform/resources/resource_container_cluster.go.erb index 4442e3df378e..63bc32856fc4 100644 --- a/third_party/terraform/resources/resource_container_cluster.go.erb +++ b/third_party/terraform/resources/resource_container_cluster.go.erb @@ -717,6 +717,19 @@ func resourceContainerCluster() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, }, + "resource_labels": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + + "default_max_pods_per_node": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Computed: true, + }, + <% unless version == 'ga' -%> "release_channel": { Type: schema.TypeList, @@ -738,20 +751,6 @@ func resourceContainerCluster() *schema.Resource { }, }, - "resource_labels": { - Type: schema.TypeMap, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - - "default_max_pods_per_node": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Computed: true, - }, - -<% unless version == 'ga' -%> "vertical_pod_autoscaling": { Type: schema.TypeList, MaxItems: 1, From d2d4013cbb9dd0484ac4c53366bde7cd3cbf9785 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Tue, 15 Oct 2019 14:05:44 -0700 Subject: [PATCH 14/15] Duplicated resource_labels during rebase --- .../terraform/resources/resource_container_cluster.go.erb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/third_party/terraform/resources/resource_container_cluster.go.erb b/third_party/terraform/resources/resource_container_cluster.go.erb index 63bc32856fc4..7a426b8e7250 100644 --- a/third_party/terraform/resources/resource_container_cluster.go.erb +++ b/third_party/terraform/resources/resource_container_cluster.go.erb @@ -717,12 +717,6 @@ func resourceContainerCluster() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, }, - "resource_labels": { - Type: schema.TypeMap, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "default_max_pods_per_node": { Type: schema.TypeInt, Optional: true, From f6861a2161a04146f42c12a05469063b855002eb Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 15 Oct 2019 21:19:53 +0000 Subject: [PATCH 15/15] Update tracked submodules -> HEAD on Tue Oct 15 21:19:53 UTC 2019 Tracked submodules are build/terraform-beta build/terraform-mapper build/terraform build/ansible build/inspec. --- build/terraform | 2 +- build/terraform-beta | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/terraform b/build/terraform index a0dfdc80c5df..87a05b2fc09c 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit a0dfdc80c5df22af808f004180695f9e4d578356 +Subproject commit 87a05b2fc09ca86b6074e641792bf80dc228eef7 diff --git a/build/terraform-beta b/build/terraform-beta index c39a624b52e6..df6ba8c84acd 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit c39a624b52e61bf4ff6920e1973fc6f558c275cb +Subproject commit df6ba8c84acd790c636bbff74a45fd85bc8934dd