From 6828148607bb8ba681a470abc681b55ecf7e5246 Mon Sep 17 00:00:00 2001 From: Kasper Hasior Date: Fri, 8 Dec 2023 17:49:32 -0800 Subject: [PATCH 1/6] Add support for gkehub clusterupgrade feature --- mmv1/products/gkehub2/Feature.yaml | 58 ++++++++ .../gkehub_feature_clusterupgrade.tf.erb | 12 ++ .../resource_gke_hub_feature_test.go.erb | 138 ++++++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 mmv1/templates/terraform/examples/gkehub_feature_clusterupgrade.tf.erb diff --git a/mmv1/products/gkehub2/Feature.yaml b/mmv1/products/gkehub2/Feature.yaml index 67be3b1efc02..4e34d2e219ea 100644 --- a/mmv1/products/gkehub2/Feature.yaml +++ b/mmv1/products/gkehub2/Feature.yaml @@ -108,6 +108,11 @@ examples: skip_test: true primary_resource_name: 'fmt.Sprintf("policycontroller")' primary_resource_id: 'feature' + - !ruby/object:Provider::Terraform::Examples + name: 'gkehub_feature_clusterupgrade' + skip_test: true + primary_resource_name: 'fmt.Sprint("clusterupgrade")' + primary_resource_id: 'feature' autogen_async: true # Skip sweeper gen since this is a child resource. skip_sweeper: true @@ -195,6 +200,59 @@ properties: - :MODE_UNSPECIFIED - :COPY - :MOVE + - !ruby/object:Api::Type::NestedObject + name: clusterupgrade + description: Clusterupgrade feature spec. + properties: + - !ruby/object:Api::Type::Array + name: 'upstreamFleets' + description: | + Specified if other fleet should be considered as a source of upgrades. Currently, at most one upstream fleet is allowed. The fleet name should be either fleet project number or id. + required: true + item_type: Api::Type::String + - !ruby/object:Api::Type::NestedObject + name: 'postConditions' + description: | + Post conditions to override for the specified upgrade. + required: true + default_from_api: true + properties: + - !ruby/object:Api::Type::String + name: 'soaking' + description: | + Amount of time to "soak" after a rollout has been finished before marking it COMPLETE. Cannot exceed 30 days. + required: true + - !ruby/object:Api::Type::Array + name: 'gkeUpgradeOverrides' + description: | + Configuration overrides for individual upgrades. + item_type: !ruby/object:Api::Type::NestedObject + properties: + - !ruby/object:Api::Type::NestedObject + name: 'upgrade' + description: | + Which upgrade to override. + required: true + properties: + - !ruby/object:Api::Type::String + name: 'name' + description: | + Name of the upgrade, e.g., "k8s_control_plane". It should be a valid upgrade name. It must not exceet 99 characters. + - !ruby/object:Api::Type::String + name: 'version' + description: | + Version of the upgrade, e.g., "1.22.1-gke.100". It should be a valid version. It must not exceet 99 characters. + - !ruby/object:Api::Type::NestedObject + name: 'postConditions' + description: | + Post conditions to override for the specified upgrade. + required: true + properties: + - !ruby/object:Api::Type::String + name: 'soaking' + description: | + Amount of time to "soak" after a rollout has been finished before marking it COMPLETE. Cannot exceed 30 days. + required: true - !ruby/object:Api::Type::NestedObject name: fleetDefaultMemberConfig description: Optional. Fleet Default Membership Configuration. diff --git a/mmv1/templates/terraform/examples/gkehub_feature_clusterupgrade.tf.erb b/mmv1/templates/terraform/examples/gkehub_feature_clusterupgrade.tf.erb new file mode 100644 index 000000000000..a10a76f90d1f --- /dev/null +++ b/mmv1/templates/terraform/examples/gkehub_feature_clusterupgrade.tf.erb @@ -0,0 +1,12 @@ +resource "google_gke_hub_feature" "feature" { + name = "clusterupgrade" + location = "global" + spec { + clusterupgrade { + upstream_fleets = [] + post_conditions { + soaking = "60s" + } + } + } +} diff --git a/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb b/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb index f2c14b2d223f..ec9291fdcbe2 100644 --- a/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb +++ b/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb @@ -504,6 +504,119 @@ resource "google_gke_hub_feature" "feature" { `, context) } +func TestAccGKEHubFeature_Clusterupgrade(t *testing.T) { + // VCR fails to handle batched project services + acctest.SkipIfVcr(t) + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + "org_id": envvar.GetTestOrgFromEnv(t), + "billing_account": envvar.GetTestBillingAccountFromEnv(t), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckGKEHubFeatureDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccGKEHubFeature_Clusterupgrade(context), + }, + { + ResourceName: "google_gke_hub_feature.feature", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"project"}, + }, + { + Config: testAccGKEHubFeature_ClusterupgradeUpdate(context), + }, + { + ResourceName: "google_gke_hub_feature.feature", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccGKEHubFeature_Clusterupgrade(context map[string]interface{}) string { + return gkeHubFeatureProjectSetupForGA(context) + acctest.Nprintf(` +resource "google_gke_hub_feature" "feature" { + name = "clusterupgrade" + location = "global" + spec { + clusterupgrade { + upstream_fleets = [] + post_conditions { + soaking = "60s" + } + } + } + depends_on = [google_project_service.gkehub] + project = google_project.project.project_id +} + +resource "google_gke_hub_feature" "feature_2" { + name = "clusterupgrade" + location = "global" + spec { + clusterupgrade { + upstream_fleets = [] + post_conditions { + soaking = "60s" + } + } + } + depends_on = [google_project_service.gkehub_2] + project = google_project.project_2.project_id +} +`, context) +} + +func testAccGKEHubFeature_ClusterupgradeUpdate(context map[string]interface{}) string { + return gkeHubFeatureProjectSetupForGA(context) + acctest.Nprintf(` +resource "google_gke_hub_feature" "feature" { + name = "clusterupgrade" + location = "global" + spec { + clusterupgrade { + upstream_fleets = [tostring(google_project.project_2.number)] + post_conditions { + soaking = "120s" + } + gke_upgrade_overrides { + upgrade { + name = "k8s_control_plane" + version = "1.22.1-gke.100" + } + post_conditions { + soaking = "240s" + } + } + } + } + project = google_project.project.project_id +} + +resource "google_gke_hub_feature" "feature_2" { + name = "clusterupgrade" + location = "global" + spec { + clusterupgrade { + upstream_fleets = [] + post_conditions { + soaking = "60s" + } + } + } + depends_on = [google_project_service.gkehub_2] + project = google_project.project_2.project_id +} +`, context) +} + func TestAccGKEHubFeature_FleetDefaultMemberConfigPolicyController(t *testing.T) { // VCR fails to handle batched project services acctest.SkipIfVcr(t) @@ -790,6 +903,31 @@ resource "google_project_service" "gkehub" { service = "gkehub.googleapis.com" disable_on_destroy = false } + +resource "google_project" "project_2" { + name = "tf-test-gkehub%{random_suffix}-2" + project_id = "tf-test-gkehub%{random_suffix}-2" + org_id = "%{org_id}" + billing_account = "%{billing_account}" +} + +resource "google_project_service" "compute_2" { + project = google_project.project_2.project_id + service = "compute.googleapis.com" + disable_on_destroy = false +} + +resource "google_project_service" "container_2" { + project = google_project.project_2.project_id + service = "container.googleapis.com" + disable_on_destroy = false +} + +resource "google_project_service" "gkehub_2" { + project = google_project.project_2.project_id + service = "gkehub.googleapis.com" + disable_on_destroy = false +} `, context) } From 5ca47bf889ecb162c344a3e38dfe77181b621e90 Mon Sep 17 00:00:00 2001 From: Kasper Hasior Date: Mon, 11 Dec 2023 16:21:22 -0800 Subject: [PATCH 2/6] Fix gkehub Feature indentation --- mmv1/products/gkehub2/Feature.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mmv1/products/gkehub2/Feature.yaml b/mmv1/products/gkehub2/Feature.yaml index 4e34d2e219ea..efb5069f4da4 100644 --- a/mmv1/products/gkehub2/Feature.yaml +++ b/mmv1/products/gkehub2/Feature.yaml @@ -243,16 +243,16 @@ properties: description: | Version of the upgrade, e.g., "1.22.1-gke.100". It should be a valid version. It must not exceet 99 characters. - !ruby/object:Api::Type::NestedObject - name: 'postConditions' - description: | - Post conditions to override for the specified upgrade. - required: true - properties: - - !ruby/object:Api::Type::String - name: 'soaking' - description: | - Amount of time to "soak" after a rollout has been finished before marking it COMPLETE. Cannot exceed 30 days. - required: true + name: 'postConditions' + description: | + Post conditions to override for the specified upgrade. + required: true + properties: + - !ruby/object:Api::Type::String + name: 'soaking' + description: | + Amount of time to "soak" after a rollout has been finished before marking it COMPLETE. Cannot exceed 30 days. + required: true - !ruby/object:Api::Type::NestedObject name: fleetDefaultMemberConfig description: Optional. Fleet Default Membership Configuration. From 26f6c44c8cdb1ac467c79038a78f5a16524c7962 Mon Sep 17 00:00:00 2001 From: Kasper Hasior Date: Tue, 19 Dec 2023 16:53:52 -0800 Subject: [PATCH 3/6] Remove unnecessary tostring() call --- .../services/gkehub2/resource_gke_hub_feature_test.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb b/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb index ec9291fdcbe2..51e42137d1bb 100644 --- a/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb +++ b/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb @@ -582,7 +582,7 @@ resource "google_gke_hub_feature" "feature" { location = "global" spec { clusterupgrade { - upstream_fleets = [tostring(google_project.project_2.number)] + upstream_fleets = [google_project.project_2.number] post_conditions { soaking = "120s" } From c5d8a5978cff14b998b2740087bdede986c8df36 Mon Sep 17 00:00:00 2001 From: Kasper Hasior Date: Tue, 19 Dec 2023 16:57:17 -0800 Subject: [PATCH 4/6] Make upgrade type and version fields required for specifying overrides --- mmv1/products/gkehub2/Feature.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mmv1/products/gkehub2/Feature.yaml b/mmv1/products/gkehub2/Feature.yaml index efb5069f4da4..ce9edaaafc96 100644 --- a/mmv1/products/gkehub2/Feature.yaml +++ b/mmv1/products/gkehub2/Feature.yaml @@ -238,10 +238,12 @@ properties: name: 'name' description: | Name of the upgrade, e.g., "k8s_control_plane". It should be a valid upgrade name. It must not exceet 99 characters. + required: true - !ruby/object:Api::Type::String name: 'version' description: | Version of the upgrade, e.g., "1.22.1-gke.100". It should be a valid version. It must not exceet 99 characters. + required: true - !ruby/object:Api::Type::NestedObject name: 'postConditions' description: | From 006b73d499625a893c8837cd78b5b592177075bc Mon Sep 17 00:00:00 2001 From: Kasper Hasior Date: Tue, 19 Dec 2023 17:25:02 -0800 Subject: [PATCH 5/6] Ignore update_time in tests --- .../services/gkehub2/resource_gke_hub_feature_test.go.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb b/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb index 51e42137d1bb..48433f3a97a8 100644 --- a/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb +++ b/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb @@ -527,7 +527,7 @@ func TestAccGKEHubFeature_Clusterupgrade(t *testing.T) { ResourceName: "google_gke_hub_feature.feature", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"project"}, + ImportStateVerifyIgnore: []string{"project", "update_time"}, }, { Config: testAccGKEHubFeature_ClusterupgradeUpdate(context), @@ -536,6 +536,7 @@ func TestAccGKEHubFeature_Clusterupgrade(t *testing.T) { ResourceName: "google_gke_hub_feature.feature", ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"update_time"}, }, }, }) From e24bbaa5ed49206f9cc4d3e8ff765d091300d557 Mon Sep 17 00:00:00 2001 From: Kasper Hasior Date: Tue, 2 Jan 2024 14:50:39 -0800 Subject: [PATCH 6/6] Replace tabulations with spaces --- .../resource_gke_hub_feature_test.go.erb | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb b/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb index 48433f3a97a8..2ce6028947fd 100644 --- a/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb +++ b/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_feature_test.go.erb @@ -505,45 +505,45 @@ resource "google_gke_hub_feature" "feature" { } func TestAccGKEHubFeature_Clusterupgrade(t *testing.T) { - // VCR fails to handle batched project services - acctest.SkipIfVcr(t) - t.Parallel() - - context := map[string]interface{}{ - "random_suffix": acctest.RandString(t, 10), - "org_id": envvar.GetTestOrgFromEnv(t), - "billing_account": envvar.GetTestBillingAccountFromEnv(t), - } + // VCR fails to handle batched project services + acctest.SkipIfVcr(t) + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + "org_id": envvar.GetTestOrgFromEnv(t), + "billing_account": envvar.GetTestBillingAccountFromEnv(t), + } - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccCheckGKEHubFeatureDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testAccGKEHubFeature_Clusterupgrade(context), - }, - { - ResourceName: "google_gke_hub_feature.feature", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"project", "update_time"}, - }, - { - Config: testAccGKEHubFeature_ClusterupgradeUpdate(context), - }, - { - ResourceName: "google_gke_hub_feature.feature", - ImportState: true, - ImportStateVerify: true, + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckGKEHubFeatureDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccGKEHubFeature_Clusterupgrade(context), + }, + { + ResourceName: "google_gke_hub_feature.feature", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"project", "update_time"}, + }, + { + Config: testAccGKEHubFeature_ClusterupgradeUpdate(context), + }, + { + ResourceName: "google_gke_hub_feature.feature", + ImportState: true, + ImportStateVerify: true, ImportStateVerifyIgnore: []string{"update_time"}, - }, - }, - }) + }, + }, + }) } func testAccGKEHubFeature_Clusterupgrade(context map[string]interface{}) string { - return gkeHubFeatureProjectSetupForGA(context) + acctest.Nprintf(` + return gkeHubFeatureProjectSetupForGA(context) + acctest.Nprintf(` resource "google_gke_hub_feature" "feature" { name = "clusterupgrade" location = "global" @@ -577,7 +577,7 @@ resource "google_gke_hub_feature" "feature_2" { } func testAccGKEHubFeature_ClusterupgradeUpdate(context map[string]interface{}) string { - return gkeHubFeatureProjectSetupForGA(context) + acctest.Nprintf(` + return gkeHubFeatureProjectSetupForGA(context) + acctest.Nprintf(` resource "google_gke_hub_feature" "feature" { name = "clusterupgrade" location = "global"