From 044e5c33af8eb5eac6b0a538ab416e63e4ecca2b Mon Sep 17 00:00:00 2001 From: vijaykanthm Date: Tue, 24 Sep 2024 15:26:18 -0700 Subject: [PATCH] fixed flaky test TestAccSecurityCenterManagement (#11756) --- ...health_analytics_custom_module_test.go.erb} | 12 +++++++++++- ...threat_detection_custom_module_test.go.erb} | 18 ++++++++++++------ ...health_analytics_custom_module_test.go.erb} | 9 ++++++++- ...health_analytics_custom_module_test.go.erb} | 9 ++++++++- 4 files changed, 39 insertions(+), 9 deletions(-) rename mmv1/third_party/terraform/services/securitycentermanagement/{resource_scc_management_folder_security_health_analytics_custom_module_test.go => resource_scc_management_folder_security_health_analytics_custom_module_test.go.erb} (96%) rename mmv1/third_party/terraform/services/securitycentermanagement/{resource_scc_management_organization_event_threat_detection_custom_module_test.go => resource_scc_management_organization_event_threat_detection_custom_module_test.go.erb} (92%) rename mmv1/third_party/terraform/services/securitycentermanagement/{resource_scc_management_organization_project_security_health_analytics_custom_module_test.go => resource_scc_management_organization_project_security_health_analytics_custom_module_test.go.erb} (96%) rename mmv1/third_party/terraform/services/securitycentermanagement/{resource_scc_management_organization_security_health_analytics_custom_module_test.go => resource_scc_management_organization_security_health_analytics_custom_module_test.go.erb} (97%) diff --git a/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module_test.go b/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module_test.go.erb similarity index 96% rename from mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module_test.go rename to mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module_test.go.erb index 297c0c297d6b..0fefafa48092 100644 --- a/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module_test.go +++ b/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module_test.go.erb @@ -1,4 +1,6 @@ +<% autogen_exception -%> package securitycentermanagement_test +<% unless version == 'ga' -%> import ( "fmt" @@ -27,7 +29,7 @@ func testAccSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule(t acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), ExternalProviders: map[string]resource.ExternalProvider{ "random": {}, "time": {}, @@ -68,6 +70,7 @@ func testAccSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule(t func testAccSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule_sccFolderCustomModuleBasicExample(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_folder" "folder" { + provider = google-beta parent = "organizations/%{org_id}" display_name = "tf-test-folder-name%{random_suffix}" deletion_protection = false @@ -80,6 +83,7 @@ resource "time_sleep" "wait_1_minute" { } resource "google_scc_management_folder_security_health_analytics_custom_module" "example" { + provider = google-beta folder = google_folder.folder.folder_id location = "%{location}" display_name = "tf_test_basic_custom_module%{random_suffix}" @@ -107,12 +111,14 @@ resource "google_scc_management_folder_security_health_analytics_custom_module" func testAccSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule_sccFolderCustomModuleFullExample(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_folder" "folder" { + provider = google-beta parent = "organizations/%{org_id}" display_name = "tf-test-folder-name%{random_suffix}" deletion_protection = false } resource "google_scc_management_folder_security_health_analytics_custom_module" "example" { + provider = google-beta folder = google_folder.folder.folder_id location = "%{location}" display_name = "tf_test_full_custom_module%{random_suffix}" @@ -151,12 +157,14 @@ resource "google_scc_management_folder_security_health_analytics_custom_module" func testAccSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule_sccFolderCustomModuleUpdate(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_folder" "folder" { + provider = google-beta parent = "organizations/%{org_id}" display_name = "tf-test-folder-name%{random_suffix}" deletion_protection = false } resource "google_scc_management_folder_security_health_analytics_custom_module" "example" { + provider = google-beta folder = google_folder.folder.folder_id location = "%{location}" display_name = "tf_test_full_custom_module%{random_suffix}" @@ -234,3 +242,5 @@ func testAccCheckSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModu return nil } } + +<% end -%> diff --git a/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module_test.go b/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module_test.go.erb similarity index 92% rename from mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module_test.go rename to mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module_test.go.erb index aa3afe0781cf..07b261ecad5a 100644 --- a/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module_test.go +++ b/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module_test.go.erb @@ -1,4 +1,7 @@ +<% autogen_exception -%> + package securitycentermanagement_test +<% unless version == 'ga' -%> import ( "fmt" @@ -23,10 +26,6 @@ func TestAccSecurityCenterManagement(t *testing.T) { } for name, tc := range testCases { - // shadow the tc variable into scope so that when - // the loop continues, if t.Run hasn't executed tc(t) - // yet, we don't have a race condition - // see https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables tc := tc t.Run(name, func(t *testing.T) { tc(t) @@ -35,7 +34,9 @@ func TestAccSecurityCenterManagement(t *testing.T) { } func testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModule(t *testing.T) { - // t.Parallel() + + <%# Comment explaining the beta-only status due to concurrent modification issues (Error 409). %> + <%# This is being marked as beta-only. See the bug link: %> context := map[string]interface{}{ "org_id": envvar.GetTestOrgFromEnv(t), @@ -45,7 +46,7 @@ func testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModule acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), // Ensure beta factory is used CheckDestroy: testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModuleDestroyProducer(t), Steps: []resource.TestStep{ { @@ -73,6 +74,8 @@ func testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModule func testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModule__sccOrganizationCustomModuleExample(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_scc_management_organization_event_threat_detection_custom_module" "example" { + provider = google-beta + organization = "%{org_id}" location = "%{location}" display_name = "tf_test_custom_module%{random_suffix}" @@ -96,6 +99,8 @@ resource "google_scc_management_organization_event_threat_detection_custom_modul func testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModule_sccOrganizationCustomModuleUpdate(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_scc_management_organization_event_threat_detection_custom_module" "example" { + provider = google-beta + organization = "%{org_id}" location = "%{location}" display_name = "tf_test_custom_module%{random_suffix}_updated" @@ -156,3 +161,4 @@ func testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModule return nil } } +<% end -%> diff --git a/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_project_security_health_analytics_custom_module_test.go b/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_project_security_health_analytics_custom_module_test.go.erb similarity index 96% rename from mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_project_security_health_analytics_custom_module_test.go rename to mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_project_security_health_analytics_custom_module_test.go.erb index 0edd70f41a48..32d88c901c4c 100644 --- a/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_project_security_health_analytics_custom_module_test.go +++ b/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_project_security_health_analytics_custom_module_test.go.erb @@ -1,4 +1,6 @@ +<% autogen_exception -%> package securitycentermanagement_test +<% unless version == 'ga' -%> import ( "fmt" @@ -24,7 +26,7 @@ func testAccSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule(t acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), CheckDestroy: testAccCheckSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModuleDestroyProducer(t), Steps: []resource.TestStep{ { @@ -58,6 +60,7 @@ func testAccSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule(t func testAccCheckSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule_sccProjectCustomModuleBasicExample(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_scc_management_project_security_health_analytics_custom_module" "example" { + provider = google-beta display_name = "tf_test_basic_custom_module%{random_suffix}" enablement_state = "ENABLED" location = "%{location}" @@ -81,6 +84,7 @@ resource "google_scc_management_project_security_health_analytics_custom_module" func testAccCheckSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule_sccProjectCustomModuleFullExample(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_scc_management_project_security_health_analytics_custom_module" "example" { + provider = google-beta display_name = "tf_test_full_custom_module%{random_suffix}" enablement_state = "ENABLED" location = "%{location}" @@ -118,6 +122,7 @@ resource "google_scc_management_project_security_health_analytics_custom_module" func testAccCheckSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule_sccProjectCustomModuleUpdate(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_scc_management_project_security_health_analytics_custom_module" "example" { + provider = google-beta location = "%{location}" display_name = "full_custom_module" enablement_state = "DISABLED" @@ -193,3 +198,5 @@ func testAccCheckSecurityCenterManagementProjectSecurityHealthAnalyticsCustomMod return nil } } + +<% end -%> diff --git a/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module_test.go b/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module_test.go.erb similarity index 97% rename from mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module_test.go rename to mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module_test.go.erb index fdd2dcba60f6..0d1e19e91fca 100644 --- a/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module_test.go +++ b/mmv1/third_party/terraform/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module_test.go.erb @@ -1,4 +1,6 @@ +<% autogen_exception -%> package securitycentermanagement_test +<% unless version == 'ga' -%> import ( "fmt" @@ -26,7 +28,7 @@ func testAccSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomMod acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), CheckDestroy: testAccCheckSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModuleDestroyProducer(t), Steps: []resource.TestStep{ { @@ -63,6 +65,7 @@ func testAccSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomMod func testAccSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModule_sccOrganizationCustomModuleBasicExample(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_scc_management_organization_security_health_analytics_custom_module" "example" { + provider = google-beta organization = "%{org_id}" location = "%{location}" display_name = "tf_test_basic_custom_module%{random_suffix}" @@ -87,6 +90,7 @@ resource "google_scc_management_organization_security_health_analytics_custom_mo func testAccSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModule_sccOrganizationCustomModuleFullExample(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_scc_management_organization_security_health_analytics_custom_module" "example" { + provider = google-beta organization = "%{org_id}" location = "%{location}" display_name = "tf_test_full_custom_module%{random_suffix}" @@ -125,6 +129,7 @@ resource "google_scc_management_organization_security_health_analytics_custom_mo func testAccSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModule_sccOrganizationCustomModuleUpdate(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_scc_management_organization_security_health_analytics_custom_module" "example" { + provider = google-beta organization = "%{org_id}" location = "%{location}" display_name = "tf_test_full_custom_module%{random_suffix}" @@ -202,3 +207,5 @@ func testAccCheckSecurityCenterManagementOrganizationSecurityHealthAnalyticsCust return nil } } + +<% end -%>