From a76cd43cfa6ccedae9977d588cca6b5c56a82d77 Mon Sep 17 00:00:00 2001 From: profoundwu Date: Thu, 9 Jan 2025 15:09:41 +0800 Subject: [PATCH] fix(rms): fix the failing test cases in RMS --- huaweicloud/services/acceptance/acceptance.go | 16 ++++++++++---- ...organizational_assignment_packages_test.go | 1 + ...resource_aggregator_advanced_query_test.go | 14 +----------- ...ce_aggregator_discovered_resources_test.go | 20 +---------------- ...urce_aggregator_policy_assignments_test.go | 18 +-------------- ..._resource_aggregator_policy_states_test.go | 22 ++----------------- ..._huaweicloud_rms_resource_recorder_test.go | 15 ++++++++++--- ...rce_huaweicloud_rms_assignment_packages.go | 2 +- 8 files changed, 31 insertions(+), 77 deletions(-) diff --git a/huaweicloud/services/acceptance/acceptance.go b/huaweicloud/services/acceptance/acceptance.go index 1eb04e8d1c..7d90a63bf1 100644 --- a/huaweicloud/services/acceptance/acceptance.go +++ b/huaweicloud/services/acceptance/acceptance.go @@ -111,10 +111,11 @@ var ( HW_RAM_SHARE_INVITATION_ID = os.Getenv("HW_RAM_SHARE_INVITATION_ID") HW_RAM_SHARE_ID = os.Getenv("HW_RAM_SHARE_ID") - HW_RMS_TARGET_ID_FOR_FGS = os.Getenv("HW_RMS_TARGET_ID_FOR_FGS") - HW_RMS_TARGET_ID_FOR_RFS = os.Getenv("HW_RMS_TARGET_ID_FOR_RFS") - HW_RMS_EXCLUDED_ACCOUNT_1 = os.Getenv("HW_RMS_EXCLUDED_ACCOUNT_1") - HW_RMS_EXCLUDED_ACCOUNT_2 = os.Getenv("HW_RMS_EXCLUDED_ACCOUNT_2") + HW_RMS_TARGET_ID_FOR_FGS = os.Getenv("HW_RMS_TARGET_ID_FOR_FGS") + HW_RMS_TARGET_ID_FOR_RFS = os.Getenv("HW_RMS_TARGET_ID_FOR_RFS") + HW_RMS_EXCLUDED_ACCOUNT_1 = os.Getenv("HW_RMS_EXCLUDED_ACCOUNT_1") + HW_RMS_EXCLUDED_ACCOUNT_2 = os.Getenv("HW_RMS_EXCLUDED_ACCOUNT_2") + HW_RMS_RESOURCE_RECORDER_CLOSED = os.Getenv("HW_RMS_RESOURCE_RECORDER_CLOSED") HW_CDN_DOMAIN_NAME = os.Getenv("HW_CDN_DOMAIN_NAME") // `HW_CDN_CERT_DOMAIN_NAME` Configure the domain name environment variable of the certificate type. @@ -1155,6 +1156,13 @@ func TestAccPreCheckRMSExcludedAccounts(t *testing.T) { } } +// lintignore:AT003 +func TestAccPreCheckRMSResourceRecorder(t *testing.T) { + if HW_RMS_RESOURCE_RECORDER_CLOSED == "" { + t.Skip("HW_RMS_RESOURCE_RECORDER_CLOSED must be set for the acceptance tests.") + } +} + // lintignore:AT003 func TestAccPreCheckDms(t *testing.T) { if HW_DMS_ENVIRONMENT == "" { diff --git a/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_organizational_assignment_packages_test.go b/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_organizational_assignment_packages_test.go index 1f49fcc69e..b285ba2090 100644 --- a/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_organizational_assignment_packages_test.go +++ b/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_organizational_assignment_packages_test.go @@ -21,6 +21,7 @@ func TestAccDataSourceRmsOrganizationalAssignmentPackages_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) + acceptance.TestAccPreCheckOrganizationsOpen(t) }, ProviderFactories: acceptance.TestAccProviderFactories, Steps: []resource.TestStep{ diff --git a/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_advanced_query_test.go b/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_advanced_query_test.go index 702ef88ba3..e1cb218d80 100644 --- a/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_advanced_query_test.go +++ b/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_advanced_query_test.go @@ -20,12 +20,6 @@ func TestAccDataSourceAggregatorAdvancedQuery_basic(t *testing.T) { acceptance.TestAccPrecheckDomainId(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - ExternalProviders: map[string]resource.ExternalProvider{ - "null": { - Source: "hashicorp/null", - VersionConstraint: "3.2.1", - }, - }, Steps: []resource.TestStep{ { Config: testDataSourceAggregatorAdvancedQuery_basic(rName), @@ -46,15 +40,11 @@ resource "huaweicloud_rms_resource_aggregator" "test" { name = "%[1]s" type = "ACCOUNT" account_ids = ["%[2]s"] -} -# wait 30 seconds to let the policies evaluate -resource "null_resource" "test" { + # wait 30 seconds to let the policies evaluate provisioner "local-exec" { command = "sleep 30" } - - depends_on = [ huaweicloud_rms_resource_aggregator.test ] } `, name, acceptance.HW_DOMAIN_ID) } @@ -66,8 +56,6 @@ func testDataSourceAggregatorAdvancedQuery_basic(name string) string { data "huaweicloud_rms_resource_aggregator_advanced_query" "test" { aggregator_id = huaweicloud_rms_resource_aggregator.test.id expression = "select name, id from aggregator_resources where provider = 'ecs' and type = 'cloudservers'" - - depends_on = [ null_resource.test ] } locals { diff --git a/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_discovered_resources_test.go b/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_discovered_resources_test.go index cdbed5ffbf..7a73a33003 100644 --- a/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_discovered_resources_test.go +++ b/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_discovered_resources_test.go @@ -26,12 +26,6 @@ func TestAccDataSourceAggregatorDiscoveredResources_basic(t *testing.T) { acceptance.TestAccPrecheckDomainId(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - ExternalProviders: map[string]resource.ExternalProvider{ - "null": { - Source: "hashicorp/null", - VersionConstraint: "3.2.1", - }, - }, Steps: []resource.TestStep{ { Config: testDataSourceAggregatorDiscoveredResources_basic(rName), @@ -63,15 +57,11 @@ resource "huaweicloud_rms_resource_aggregator" "test" { account_ids = ["%[2]s"] depends_on = [huaweicloud_vpc.test] -} -# wait 30 seconds to let the aggregator discover resources -resource "null_resource" "test" { + # wait 30 seconds to let the aggregator discover resources provisioner "local-exec" { command = "sleep 30" } - - depends_on = [ huaweicloud_rms_resource_aggregator.test ] } `, name, acceptance.HW_DOMAIN_ID) } @@ -82,22 +72,16 @@ func testDataSourceAggregatorDiscoveredResources_basic(name string) string { data "huaweicloud_rms_resource_aggregator_discovered_resources" "basic" { aggregator_id = huaweicloud_rms_resource_aggregator.test.id - - depends_on = [ null_resource.test ] } data "huaweicloud_rms_resource_aggregator_discovered_resources" "filter_by_service_type" { aggregator_id = huaweicloud_rms_resource_aggregator.test.id service_type = "vpc" - - depends_on = [ null_resource.test ] } data "huaweicloud_rms_resource_aggregator_discovered_resources" "filter_by_resource_type" { aggregator_id = huaweicloud_rms_resource_aggregator.test.id resource_type = "vpcs" - - depends_on = [ null_resource.test ] } data "huaweicloud_rms_resource_aggregator_discovered_resources" "filter_by_resource_id" { @@ -106,8 +90,6 @@ data "huaweicloud_rms_resource_aggregator_discovered_resources" "filter_by_resou filter { resource_id = huaweicloud_vpc.test.id } - - depends_on = [ null_resource.test ] } locals { diff --git a/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_policy_assignments_test.go b/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_policy_assignments_test.go index 91dc159a86..74b36282e4 100644 --- a/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_policy_assignments_test.go +++ b/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_policy_assignments_test.go @@ -24,12 +24,6 @@ func TestAccDataSourceAggregatorPolicyAssignments_basic(t *testing.T) { acceptance.TestAccPrecheckDomainId(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - ExternalProviders: map[string]resource.ExternalProvider{ - "null": { - Source: "hashicorp/null", - VersionConstraint: "3.2.1", - }, - }, Steps: []resource.TestStep{ { Config: testDataSourceAggregatorPolicyAssignments_basic(rName), @@ -52,15 +46,11 @@ resource "huaweicloud_rms_resource_aggregator" "test" { name = "%[1]s" type = "ACCOUNT" account_ids = ["%[2]s"] -} -# wait 30 seconds to let the policies evaluate -resource "null_resource" "test" { + # wait 30 seconds to let the policies evaluate provisioner "local-exec" { command = "sleep 30" } - - depends_on = [ huaweicloud_rms_resource_aggregator.test ] } `, name, acceptance.HW_DOMAIN_ID) } @@ -71,8 +61,6 @@ func testDataSourceAggregatorPolicyAssignments_basic(name string) string { data "huaweicloud_rms_resource_aggregator_policy_assignments" "basic" { aggregator_id = huaweicloud_rms_resource_aggregator.test.id - - depends_on = [ null_resource.test ] } data "huaweicloud_rms_resource_aggregator_policy_assignments" "filter_by_compliance_state" { @@ -81,8 +69,6 @@ data "huaweicloud_rms_resource_aggregator_policy_assignments" "filter_by_complia filter { compliance_state = "Compliant" } - - depends_on = [ null_resource.test ] } data "huaweicloud_rms_resource_aggregator_policy_assignments" "filter_by_policy_assignment_name" { @@ -91,8 +77,6 @@ data "huaweicloud_rms_resource_aggregator_policy_assignments" "filter_by_policy_ filter { policy_assignment_name = "iam-password-policy" } - - depends_on = [ null_resource.test ] } locals { diff --git a/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_policy_states_test.go b/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_policy_states_test.go index 7cc041ba77..d436245bdd 100644 --- a/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_policy_states_test.go +++ b/huaweicloud/services/acceptance/rms/data_source_huaweicloud_rms_resource_aggregator_policy_states_test.go @@ -27,12 +27,6 @@ func TestAccDataSourceAggregatorPolicyStates_basic(t *testing.T) { acceptance.TestAccPrecheckDomainId(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - ExternalProviders: map[string]resource.ExternalProvider{ - "null": { - Source: "hashicorp/null", - VersionConstraint: "3.2.1", - }, - }, Steps: []resource.TestStep{ { Config: testDataSourceAggregatorPolicyStates_basic(rName, password), @@ -66,15 +60,11 @@ resource "huaweicloud_rms_resource_aggregator" "test" { account_ids = ["%[3]s"] depends_on = [huaweicloud_identity_user.test] -} -# wait 30 seconds to let the policies evaluate -resource "null_resource" "test" { + # wait 40 seconds to let the policies evaluate provisioner "local-exec" { - command = "sleep 30" + command = "sleep 40" } - - depends_on = [ huaweicloud_rms_resource_aggregator.test ] } `, name, password, acceptance.HW_DOMAIN_ID) } @@ -85,29 +75,21 @@ func testDataSourceAggregatorPolicyStates_basic(name, password string) string { data "huaweicloud_rms_resource_aggregator_policy_states" "basic" { aggregator_id = huaweicloud_rms_resource_aggregator.test.id - - depends_on = [ null_resource.test ] } data "huaweicloud_rms_resource_aggregator_policy_states" "filter_by_compliance_state" { aggregator_id = huaweicloud_rms_resource_aggregator.test.id compliance_state = "Compliant" - - depends_on = [ null_resource.test ] } data "huaweicloud_rms_resource_aggregator_policy_states" "filter_by_policy_assignment_name" { aggregator_id = huaweicloud_rms_resource_aggregator.test.id policy_assignment_name = "iam-password-policy" - - depends_on = [ null_resource.test ] } data "huaweicloud_rms_resource_aggregator_policy_states" "filter_by_resource_id" { aggregator_id = huaweicloud_rms_resource_aggregator.test.id resource_id = huaweicloud_identity_user.test.id - - depends_on = [ null_resource.test ] } locals { diff --git a/huaweicloud/services/acceptance/rms/resource_huaweicloud_rms_resource_recorder_test.go b/huaweicloud/services/acceptance/rms/resource_huaweicloud_rms_resource_recorder_test.go index 0ed0fc8ab0..2d51ccc040 100644 --- a/huaweicloud/services/acceptance/rms/resource_huaweicloud_rms_resource_recorder_test.go +++ b/huaweicloud/services/acceptance/rms/resource_huaweicloud_rms_resource_recorder_test.go @@ -55,7 +55,12 @@ func TestAccRecorder_basic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.TestAccPreCheck(t) }, + PreCheck: func() { + acceptance.TestAccPreCheck(t) + // Some test cases in RMS require the resource recorder to be enabled. + // Skip this test case during batch execution to ensure other test cases execute smoothly. + acceptance.TestAccPreCheckRMSResourceRecorder(t) + }, ProviderFactories: acceptance.TestAccProviderFactories, CheckDestroy: rc.CheckResourceDestroy(), Steps: []resource.TestStep{ @@ -65,7 +70,7 @@ func TestAccRecorder_basic(t *testing.T) { rc.CheckResourceExists(), resource.TestCheckResourceAttr(rName, "agency_name", "rms_tracker_agency"), resource.TestCheckResourceAttr(rName, "selector.0.all_supported", "false"), - resource.TestCheckResourceAttr(rName, "selector.0.resource_types.#", "5"), + resource.TestCheckResourceAttr(rName, "selector.0.resource_types.#", "8"), resource.TestCheckResourceAttrSet(rName, "obs_channel.0.region"), resource.TestCheckResourceAttrPair(rName, "obs_channel.0.bucket", "huaweicloud_obs_bucket.test", "bucket"), @@ -144,7 +149,11 @@ resource "huaweicloud_rms_resource_recorder" "test" { selector { all_supported = false - resource_types = ["vpc.vpcs", "rds.instances", "dms.kafkas", "dms.rabbitmqs", "dms.queues"] + + resource_types = [ + "vpc.vpcs", "rds.instances", "dms.kafkas", "dms.rabbitmqs", "dms.queues", + "config.trackers", "config.policyAssignments", "config.conformancePacks", + ] } obs_channel { diff --git a/huaweicloud/services/rms/data_source_huaweicloud_rms_assignment_packages.go b/huaweicloud/services/rms/data_source_huaweicloud_rms_assignment_packages.go index 7cf237dc8b..21943147d0 100644 --- a/huaweicloud/services/rms/data_source_huaweicloud_rms_assignment_packages.go +++ b/huaweicloud/services/rms/data_source_huaweicloud_rms_assignment_packages.go @@ -197,7 +197,7 @@ func (w *AssignmentPackagesDSWrapper) listConformancePacksToSchema(body *gjson.R func(varStr gjson.Result) any { return map[string]any{ "var_key": varStr.Get("var_key").Value(), - "var_value": varStr.Get("var_value").Value(), + "var_value": utils.JsonToString(varStr.Get("var_value").Value()), } }, ),