From 60a1a4baa1164769c24d7a9cb6ea7312e4bb59c2 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 1 Aug 2024 13:12:39 -0700 Subject: [PATCH] Add support for the management field in ConfigManagement Fleet-level default config (#11291) (#18963) [upstream:fcb51889011bfd782ee5127815ef6635c35eef80] Signed-off-by: Modular Magician --- .changelog/11291.txt | 3 + .../gkehub2/resource_gke_hub_feature.go | 23 +++++ .../gkehub2/resource_gke_hub_feature_test.go | 83 +++++++++++++++++++ website/docs/r/gke_hub_feature.html.markdown | 5 ++ 4 files changed, 114 insertions(+) create mode 100644 .changelog/11291.txt diff --git a/.changelog/11291.txt b/.changelog/11291.txt new file mode 100644 index 00000000000..5a854e42ee8 --- /dev/null +++ b/.changelog/11291.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +gkehub: added `management` field to ConfigManagement `fleet_default_member_config` +``` \ No newline at end of file diff --git a/google/services/gkehub2/resource_gke_hub_feature.go b/google/services/gkehub2/resource_gke_hub_feature.go index 372f0e30d77..e03bc9a9a38 100644 --- a/google/services/gkehub2/resource_gke_hub_feature.go +++ b/google/services/gkehub2/resource_gke_hub_feature.go @@ -192,6 +192,12 @@ func ResourceGKEHub2Feature() *schema.Resource { }, }, }, + "management": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: verify.ValidateEnum([]string{"MANAGEMENT_UNSPECIFIED", "MANAGEMENT_AUTOMATIC", "MANAGEMENT_MANUAL", ""}), + Description: `Set this field to MANAGEMENT_AUTOMATIC to enable Config Sync auto-upgrades, and set this field to MANAGEMENT_MANUAL or MANAGEMENT_UNSPECIFIED to disable Config Sync auto-upgrades. Possible values: ["MANAGEMENT_UNSPECIFIED", "MANAGEMENT_AUTOMATIC", "MANAGEMENT_MANUAL"]`, + }, "version": { Type: schema.TypeString, Optional: true, @@ -1340,6 +1346,8 @@ func flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagement(v interface{} transformed := make(map[string]interface{}) transformed["version"] = flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementVersion(original["version"], d, config) + transformed["management"] = + flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementManagement(original["management"], d, config) transformed["config_sync"] = flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSync(original["configSync"], d, config) return []interface{}{transformed} @@ -1348,6 +1356,10 @@ func flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementVersion(v inte return v } +func flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementManagement(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSync(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil { return nil @@ -2234,6 +2246,13 @@ func expandGKEHub2FeatureFleetDefaultMemberConfigConfigmanagement(v interface{}, transformed["version"] = transformedVersion } + transformedManagement, err := expandGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementManagement(original["management"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedManagement); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["management"] = transformedManagement + } + transformedConfigSync, err := expandGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSync(original["config_sync"], d, config) if err != nil { return nil, err @@ -2248,6 +2267,10 @@ func expandGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementVersion(v inter return v, nil } +func expandGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementManagement(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSync(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { diff --git a/google/services/gkehub2/resource_gke_hub_feature_test.go b/google/services/gkehub2/resource_gke_hub_feature_test.go index 748ed0292b9..487bb870abc 100644 --- a/google/services/gkehub2/resource_gke_hub_feature_test.go +++ b/google/services/gkehub2/resource_gke_hub_feature_test.go @@ -434,10 +434,53 @@ func TestAccGKEHubFeature_FleetDefaultMemberConfigConfigManagement(t *testing.T) ImportState: true, ImportStateVerify: true, }, + { + Config: testAccGKEHubFeature_FleetDefaultMemberConfigConfigManagementEnableAutomaticManagementUpdate(context), + }, + { + ResourceName: "google_gke_hub_feature.feature", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccGKEHubFeature_FleetDefaultMemberConfigConfigManagementRemovalUpdate(context), + }, + { + ResourceName: "google_gke_hub_feature.feature", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccGKEHubFeature_FleetDefaultMemberConfigConfigManagementAutomaticManagement(context), + }, + { + ResourceName: "google_gke_hub_feature.feature", + ImportState: true, + ImportStateVerify: true, + }, }, }) } +func testAccGKEHubFeature_FleetDefaultMemberConfigConfigManagementAutomaticManagement(context map[string]interface{}) string { + return gkeHubFeatureProjectSetupForGA(context) + acctest.Nprintf(` +resource "google_gke_hub_feature" "feature" { + name = "configmanagement" + location = "global" + fleet_default_member_config { + configmanagement { + management = "MANAGEMENT_AUTOMATIC" + config_sync { + enabled = true + } + } + } + depends_on = [google_project_service.anthos, google_project_service.gkehub, google_project_service.acm] + project = google_project.project.project_id +} +`, context) +} + func testAccGKEHubFeature_FleetDefaultMemberConfigConfigManagement(context map[string]interface{}) string { return gkeHubFeatureProjectSetupForGA(context) + acctest.Nprintf(` resource "google_gke_hub_feature" "feature" { @@ -473,6 +516,7 @@ resource "google_gke_hub_feature" "feature" { fleet_default_member_config { configmanagement { version = "1.16.1" + management = "MANAGEMENT_MANUAL" config_sync { enabled = true prevent_drift = true @@ -493,6 +537,45 @@ resource "google_gke_hub_feature" "feature" { `, context) } +func testAccGKEHubFeature_FleetDefaultMemberConfigConfigManagementEnableAutomaticManagementUpdate(context map[string]interface{}) string { + return gkeHubFeatureProjectSetupForGA(context) + acctest.Nprintf(` +resource "google_gke_hub_feature" "feature" { + name = "configmanagement" + location = "global" + fleet_default_member_config { + configmanagement { + version = "1.16.1" + management = "MANAGEMENT_AUTOMATIC" + config_sync { + prevent_drift = true + source_format = "unstructured" + oci { + sync_repo = "us-central1-docker.pkg.dev/corp-gke-build-artifacts/acm/configs:latest" + policy_dir = "/acm/nonprod-root/" + secret_type = "gcpserviceaccount" + sync_wait_secs = "15" + gcp_service_account_email = "gke-cluster@gke-foo-nonprod.iam.gserviceaccount.com" + } + } + } + } + depends_on = [google_project_service.anthos, google_project_service.gkehub, google_project_service.acm] + project = google_project.project.project_id +} +`, context) +} + +func testAccGKEHubFeature_FleetDefaultMemberConfigConfigManagementRemovalUpdate(context map[string]interface{}) string { + return gkeHubFeatureProjectSetupForGA(context) + acctest.Nprintf(` +resource "google_gke_hub_feature" "feature" { + name = "configmanagement" + location = "global" + depends_on = [google_project_service.anthos, google_project_service.gkehub, google_project_service.acm] + project = google_project.project.project_id +} +`, context) +} + func TestAccGKEHubFeature_Clusterupgrade(t *testing.T) { // VCR fails to handle batched project services acctest.SkipIfVcr(t) diff --git a/website/docs/r/gke_hub_feature.html.markdown b/website/docs/r/gke_hub_feature.html.markdown index 679a0a1c119..75fa9feeee5 100644 --- a/website/docs/r/gke_hub_feature.html.markdown +++ b/website/docs/r/gke_hub_feature.html.markdown @@ -480,6 +480,11 @@ The following arguments are supported: (Optional) Version of ACM installed +* `management` - + (Optional) + Set this field to MANAGEMENT_AUTOMATIC to enable Config Sync auto-upgrades, and set this field to MANAGEMENT_MANUAL or MANAGEMENT_UNSPECIFIED to disable Config Sync auto-upgrades. + Possible values are: `MANAGEMENT_UNSPECIFIED`, `MANAGEMENT_AUTOMATIC`, `MANAGEMENT_MANUAL`. + * `config_sync` - (Optional) ConfigSync configuration for the cluster