From c58ff01f6afe0bd370617cf2ea9d6b465413ceb7 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:25:04 +0000 Subject: [PATCH] chore: Unifies SDK connection getting in tests (#1864) * Conn an ConnV2 functions * muxedProviderFactoryFn doesn't need to be exported * acc.MongoDBClient * ignore "updated" filelds in flaky tests that sometimes expected and got differ in a second. example: error= | ImportStateVerify attributes not equivalent. Difference is shown below. The - symbol indicates attributes missing after import. | | \u00a0\u00a0map[string]string{ | -\u00a0\t"updated": "2024-01-23T01:33:43Z", | +\u00a0\t"updated": "2024-01-23T01:33:42Z", | \u00a0\u00a0} * apply feedback: remove muxedProviderFactoryFn --- internal/provider/provider.go | 26 ++++----------- .../resource_access_list_api_key_test.go | 14 ++------ .../resource_advanced_cluster_test.go | 10 +----- .../data_source_alert_configurations_test.go | 7 +--- .../resource_alert_configuration_test.go | 24 +++----------- .../service/apikey/resource_api_key_test.go | 16 ++------- .../atlasuser/data_source_atlas_user_test.go | 8 ++--- .../atlasuser/data_source_atlas_users_test.go | 8 ++--- .../auditing/resource_auditing_test.go | 15 ++------- .../resource_backup_compliance_policy_test.go | 19 ++--------- .../resource_cloud_backup_schedule_test.go | 16 ++------- .../resource_cloud_backup_snapshot_test.go | 19 ++--------- ...loud_backup_snapshot_export_bucket_test.go | 17 ++-------- ...e_cloud_backup_snapshot_export_job_test.go | 18 ++-------- ..._cloud_backup_snapshot_restore_job_test.go | 20 ++--------- ...loud_provider_access_authorization_test.go | 10 +----- ...source_cloud_provider_access_setup_test.go | 12 +------ .../service/cluster/resource_cluster_test.go | 10 +----- ...resource_cluster_outage_simulation_test.go | 7 +--- .../resource_custom_db_role_test.go | 17 ++-------- ...stom_dns_configuration_cluster_aws_test.go | 14 ++------ .../data_source_data_lake_pipeline_test.go | 6 +--- .../resource_data_lake_pipeline_test.go | 9 +---- .../resource_encryption_at_rest_test.go | 14 ++------ .../resource_event_trigger_test.go | 5 ++- ...source_federated_database_instance_test.go | 8 +---- .../data_source_federated_query_limit_test.go | 10 +----- .../resource_federated_query_limit_test.go | 7 +--- ...erated_settings_identity_providers_test.go | 8 +---- ...derated_settings_identity_provider_test.go | 8 +---- ...e_federated_settings_connected_org_test.go | 8 +---- ..._federated_settings_connected_orgs_test.go | 8 +---- .../data_source_federated_settings_test.go | 9 +---- ...e_federated_settings_connected_org_test.go | 8 +---- ...derated_settings_org_role_mappings_test.go | 8 +---- ...ederated_settings_org_role_mapping_test.go | 16 ++------- .../resource_global_cluster_config_test.go | 19 ++--------- .../resource_ldap_configuration_test.go | 9 +---- .../ldapverify/resource_ldap_verify_test.go | 15 ++------- .../resource_maintenance_window_test.go | 10 +----- .../resource_network_container_test.go | 15 ++------- .../resource_network_peering_test.go | 10 +----- .../resource_online_archive_test.go | 16 ++------- .../resource_organization_test.go | 2 +- .../resource_org_invitation_test.go | 11 +------ ...rce_private_endpoint_regional_mode_test.go | 7 +--- ...rce_private_endpoint_regional_mode_test.go | 33 ++----------------- .../resource_privatelink_endpoint_test.go | 15 ++------- ...ce_privatelink_endpoint_serverless_test.go | 18 ++-------- ...ource_privatelink_endpoint_service_test.go | 14 ++------ ...ice_data_federation_online_archive_test.go | 18 ++-------- ...telink_endpoint_service_serverless_test.go | 18 ++-------- .../resource_project_api_key_test.go | 14 ++------ .../resource_project_invitation_test.go | 20 ++--------- .../resource_search_deployment_test.go | 7 ++-- .../searchindex/resource_search_index_test.go | 6 +--- .../resource_serverless_instance_test.go | 16 ++------- .../resource_stream_connection_test.go | 7 ++-- .../resource_stream_instance_test.go | 4 +-- internal/service/teams/resource_teams_test.go | 13 +------- ...ata_source_third_party_integration_test.go | 9 +---- .../resource_third_party_integration_test.go | 7 +--- ..._x509_authentication_database_user_test.go | 26 +++------------ internal/testutil/acc/advanced_cluster.go | 11 ++----- internal/testutil/acc/database_user.go | 12 ++----- internal/testutil/acc/factory.go | 27 ++++++++------- internal/testutil/acc/federated.go | 7 +--- internal/testutil/acc/ldap.go | 7 +--- internal/testutil/acc/network_peering.go | 8 +---- internal/testutil/acc/org.go | 8 +---- internal/testutil/acc/project.go | 13 ++------ .../testutil/acc/project_ip_acces_list.go | 16 ++------- internal/testutil/acc/search_index.go | 8 +---- internal/testutil/acc/stream_instance.go | 4 +-- internal/testutil/acc/team.go | 7 +--- main.go | 2 -- 76 files changed, 142 insertions(+), 786 deletions(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 1f7d6e857d..065a40011c 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -21,7 +21,6 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-mux/tf5to6server" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" - sdkv2schema "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" @@ -451,28 +450,17 @@ func NewFrameworkProvider() provider.Provider { } func MuxedProviderFactory() func() tfprotov6.ProviderServer { - return MuxedProviderFactoryFn(NewSdkV2Provider()) -} - -// MuxedProviderFactoryFn creates mux provider using existing sdk v2 provider passed as parameter and creating new instance of framework provider. -// Used in testing where existing sdk v2 provider has to be used. -func MuxedProviderFactoryFn(sdkV2Provider *sdkv2schema.Provider) func() tfprotov6.ProviderServer { - fwProvider := NewFrameworkProvider() - + v2Provider := NewSdkV2Provider() + newProvider := NewFrameworkProvider() ctx := context.Background() - upgradedSdkProvider, err := tf5to6server.UpgradeServer(ctx, sdkV2Provider.GRPCProvider) + upgradedSdkProvider, err := tf5to6server.UpgradeServer(ctx, v2Provider.GRPCProvider) if err != nil { log.Fatal(err) } - - providers := []func() tfprotov6.ProviderServer{ - func() tfprotov6.ProviderServer { - return upgradedSdkProvider - }, - providerserver.NewProtocol6(fwProvider), - } - - muxServer, err := tf6muxserver.NewMuxServer(ctx, providers...) + muxServer, err := tf6muxserver.NewMuxServer(ctx, + func() tfprotov6.ProviderServer { return upgradedSdkProvider }, + providerserver.NewProtocol6(newProvider), + ) if err != nil { log.Fatal(err) } diff --git a/internal/service/accesslistapikey/resource_access_list_api_key_test.go b/internal/service/accesslistapikey/resource_access_list_api_key_test.go index 83d61cf932..ebc3e84ec3 100644 --- a/internal/service/accesslistapikey/resource_access_list_api_key_test.go +++ b/internal/service/accesslistapikey/resource_access_list_api_key_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -116,20 +115,15 @@ func TestAccProjectRSAccessListAPIKey_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasAccessListAPIKeyExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - _, _, err := conn.AccessListAPIKeys.Get(context.Background(), ids["org_id"], ids["api_key_id"], ids["entry"]) + _, _, err := acc.Conn().AccessListAPIKeys.Get(context.Background(), ids["org_id"], ids["api_key_id"], ids["entry"]) if err != nil { return fmt.Errorf("access list API Key (%s) does not exist", ids["api_key_id"]) } @@ -139,16 +133,12 @@ func testAccCheckMongoDBAtlasAccessListAPIKeyExists(resourceName string) resourc } func testAccCheckMongoDBAtlasAccessListAPIKeyDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_access_list_api_key" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - _, _, err := conn.AccessListAPIKeys.Get(context.Background(), ids["project_id"], ids["api_key_id"], ids["entry"]) + _, _, err := acc.Conn().AccessListAPIKeys.Get(context.Background(), ids["project_id"], ids["api_key_id"], ids["entry"]) if err == nil { return fmt.Errorf("access list API Key (%s) still exists", ids["api_key_id"]) } diff --git a/internal/service/advancedcluster/resource_advanced_cluster_test.go b/internal/service/advancedcluster/resource_advanced_cluster_test.go index db2652d1a2..cfc33a999d 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster_test.go +++ b/internal/service/advancedcluster/resource_advanced_cluster_test.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/mwielbut/pointy" matlas "go.mongodb.org/atlas/mongodbatlas" @@ -681,26 +680,19 @@ func TestAccClusterAdvancedCluster_WithTags(t *testing.T) { func testAccCheckMongoDBAtlasAdvancedClusterExists(resourceName string, cluster *matlas.AdvancedCluster) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestMongoDBClient.(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - log.Printf("[DEBUG] projectID: %s, name %s", ids["project_id"], ids["cluster_name"]) - - if clusterResp, _, err := conn.AdvancedClusters.Get(context.Background(), ids["project_id"], ids["cluster_name"]); err == nil { + if clusterResp, _, err := acc.Conn().AdvancedClusters.Get(context.Background(), ids["project_id"], ids["cluster_name"]); err == nil { *cluster = *clusterResp return nil } - return fmt.Errorf("cluster(%s:%s) does not exist", rs.Primary.Attributes["project_id"], rs.Primary.ID) } } diff --git a/internal/service/alertconfiguration/data_source_alert_configurations_test.go b/internal/service/alertconfiguration/data_source_alert_configurations_test.go index 37d7e81473..271f4d23e1 100644 --- a/internal/service/alertconfiguration/data_source_alert_configurations_test.go +++ b/internal/service/alertconfiguration/data_source_alert_configurations_test.go @@ -13,7 +13,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -153,21 +152,17 @@ func configTotalCount(orgID, projectName string) string { func checkCount(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) projectID := ids["project_id"] - alertResp, _, err := conn.AlertConfigurations.List(context.Background(), projectID, &matlas.ListOptions{ + alertResp, _, err := acc.Conn().AlertConfigurations.List(context.Background(), projectID, &matlas.ListOptions{ PageNum: 0, ItemsPerPage: 100, IncludeCount: true, diff --git a/internal/service/alertconfiguration/resource_alert_configuration_test.go b/internal/service/alertconfiguration/resource_alert_configuration_test.go index 8dc81f9f76..6618a1a6a7 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration_test.go +++ b/internal/service/alertconfiguration/resource_alert_configuration_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/alertconfiguration" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "go.mongodb.org/atlas-sdk/v20231115004/admin" @@ -311,7 +310,7 @@ func TestAccConfigRSAlertConfiguration_importBasic(t *testing.T) { ImportStateIdFunc: importStateProjectIDFunc(resourceName), ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"project_id"}, + ImportStateVerifyIgnore: []string{"project_id", "updated"}, }, }, }) @@ -362,7 +361,7 @@ func TestAccConfigRSAlertConfiguration_importConfigNotifications(t *testing.T) { ImportStateIdFunc: importStateProjectIDFunc(resourceName), ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"project_id"}, + ImportStateVerifyIgnore: []string{"project_id", "updated"}, }, }, }) @@ -399,7 +398,7 @@ func TestAccConfigRSAlertConfiguration_importPagerDuty(t *testing.T) { ImportStateIdFunc: importStateProjectIDFunc(resourceName), ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"notification.0.service_key"}, // service key is not returned by api in import operation + ImportStateVerifyIgnore: []string{"updated", "notification.0.service_key"}, // service key is not returned by api in import operation }, }, }) @@ -544,46 +543,34 @@ func TestAccConfigRSAlertConfiguration_withVictorOps(t *testing.T) { func checkExists(resourceName string, alert *admin.GroupAlertsConfig) resource.TestCheckFunc { return func(s *terraform.State) error { - connV2 := acc.TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - alertResp, _, err := connV2.AlertConfigurationsApi.GetAlertConfiguration(context.Background(), ids[alertconfiguration.EncodedIDKeyProjectID], ids[alertconfiguration.EncodedIDKeyAlertID]).Execute() + alertResp, _, err := acc.ConnV2().AlertConfigurationsApi.GetAlertConfiguration(context.Background(), ids[alertconfiguration.EncodedIDKeyProjectID], ids[alertconfiguration.EncodedIDKeyAlertID]).Execute() if err != nil { return fmt.Errorf("the Alert Configuration(%s) does not exist", ids[alertconfiguration.EncodedIDKeyAlertID]) } - alert = alertResp - return nil } } func checkDestroy(s *terraform.State) error { - conn := acc.TestMongoDBClient.(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_alert_configuration" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - alert, _, err := conn.AlertConfigurations.GetAnAlertConfig(context.Background(), ids[alertconfiguration.EncodedIDKeyProjectID], ids[alertconfiguration.EncodedIDKeyAlertID]) + alert, _, err := acc.Conn().AlertConfigurations.GetAnAlertConfig(context.Background(), ids[alertconfiguration.EncodedIDKeyProjectID], ids[alertconfiguration.EncodedIDKeyAlertID]) if alert != nil { return fmt.Errorf("the Project Alert Configuration(%s) still exists %s", ids[alertconfiguration.EncodedIDKeyAlertID], err) } } - return nil } @@ -593,7 +580,6 @@ func importStateProjectIDFunc(resourceName string) resource.ImportStateIdFunc { if !ok { return "", fmt.Errorf("not found: %s", resourceName) } - return fmt.Sprintf("%s-%s", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["alert_configuration_id"]), nil } } diff --git a/internal/service/apikey/resource_api_key_test.go b/internal/service/apikey/resource_api_key_test.go index bfe88cb366..bf6e6f1193 100644 --- a/internal/service/apikey/resource_api_key_test.go +++ b/internal/service/apikey/resource_api_key_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -81,44 +80,33 @@ func TestAccConfigRSAPIKey_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasAPIKeyExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - _, _, err := conn.APIKeys.Get(context.Background(), ids["org_id"], ids["api_key_id"]) + _, _, err := acc.Conn().APIKeys.Get(context.Background(), ids["org_id"], ids["api_key_id"]) if err != nil { return fmt.Errorf("API Key (%s) does not exist", ids["api_key_id"]) } - return nil } } func testAccCheckMongoDBAtlasAPIKeyDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_api_key" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - _, _, err := conn.APIKeys.Get(context.Background(), ids["org_id"], ids["role_name"]) + _, _, err := acc.Conn().APIKeys.Get(context.Background(), ids["org_id"], ids["role_name"]) if err == nil { return fmt.Errorf("API Key (%s) still exists", ids["role_name"]) } } - return nil } diff --git a/internal/service/atlasuser/data_source_atlas_user_test.go b/internal/service/atlasuser/data_source_atlas_user_test.go index a47d9215f3..77d8dfd2a2 100644 --- a/internal/service/atlasuser/data_source_atlas_user_test.go +++ b/internal/service/atlasuser/data_source_atlas_user_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "go.mongodb.org/atlas-sdk/v20231115004/admin" ) @@ -89,8 +88,7 @@ func TestAccConfigDSAtlasUser_InvalidAttrCombination(t *testing.T) { func fetchUser(t *testing.T, userID string) *admin.CloudAppUser { t.Helper() - connV2 := acc.TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - userResp, _, err := connV2.MongoDBCloudUsersApi.GetUser(context.Background(), userID).Execute() + userResp, _, err := acc.ConnV2().MongoDBCloudUsersApi.GetUser(context.Background(), userID).Execute() if err != nil { t.Fatalf("the Atlas User (%s) could not be fetched: %v", userID, err) } @@ -99,9 +97,7 @@ func fetchUser(t *testing.T, userID string) *admin.CloudAppUser { func fetchUserByUsername(t *testing.T, username string) *admin.CloudAppUser { t.Helper() - connV2 := acc.TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - - userResp, _, err := connV2.MongoDBCloudUsersApi.GetUserByUsername(context.Background(), username).Execute() + userResp, _, err := acc.ConnV2().MongoDBCloudUsersApi.GetUserByUsername(context.Background(), username).Execute() if err != nil { t.Fatalf("the Atlas User (%s) could not be fetched: %v", username, err) } diff --git a/internal/service/atlasuser/data_source_atlas_users_test.go b/internal/service/atlasuser/data_source_atlas_users_test.go index e52fee8a44..2955151164 100644 --- a/internal/service/atlasuser/data_source_atlas_users_test.go +++ b/internal/service/atlasuser/data_source_atlas_users_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/atlasuser" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "go.mongodb.org/atlas-sdk/v20231115004/admin" @@ -204,8 +203,7 @@ func TestAccConfigDSAtlasUsers_InvalidAttrCombinations(t *testing.T) { func fetchOrgUsers(t *testing.T, orgID string) *admin.PaginatedAppUser { t.Helper() - connV2 := acc.TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - users, _, err := connV2.OrganizationsApi.ListOrganizationUsers(context.Background(), orgID).Execute() + users, _, err := acc.ConnV2().OrganizationsApi.ListOrganizationUsers(context.Background(), orgID).Execute() if err != nil { t.Fatalf("the Atlas Users for Org(%s) could not be fetched: %v", orgID, err) } @@ -286,8 +284,6 @@ func testAccDSMongoDBAtlasUsersByTeamWithPagination(orgID, teamName, username st func testAccCheckMongoDBAtlasOrgWithUsersExists(dataSourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - connV2 := acc.TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - rs, ok := s.RootModule().Resources[dataSourceName] if !ok { return fmt.Errorf("not found: %s", dataSourceName) @@ -298,7 +294,7 @@ func testAccCheckMongoDBAtlasOrgWithUsersExists(dataSourceName string) resource. return fmt.Errorf("org_id not defined in data source: %s", dataSourceName) } - apiResp, _, err := connV2.OrganizationsApi.ListOrganizationUsers(context.Background(), orgID).Execute() + apiResp, _, err := acc.ConnV2().OrganizationsApi.ListOrganizationUsers(context.Background(), orgID).Execute() if err != nil { return fmt.Errorf("unable to determine if users exist in org: %s", orgID) diff --git a/internal/service/auditing/resource_auditing_test.go b/internal/service/auditing/resource_auditing_test.go index 63dbfec657..eba3cff1e8 100644 --- a/internal/service/auditing/resource_auditing_test.go +++ b/internal/service/auditing/resource_auditing_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -106,42 +105,32 @@ func TestAccAdvRSAuditing_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasAuditingExists(resourceName string, auditing *matlas.Auditing) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - auditingRes, _, err := conn.Auditing.Get(context.Background(), rs.Primary.ID) + auditingRes, _, err := acc.Conn().Auditing.Get(context.Background(), rs.Primary.ID) if err != nil { return fmt.Errorf("auditing (%s) does not exist", rs.Primary.ID) } - auditing = auditingRes - return nil } } func testAccCheckMongoDBAtlasAuditingDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_auditing" { continue } - - _, _, err := conn.Auditing.Get(context.Background(), rs.Primary.ID) + _, _, err := acc.Conn().Auditing.Get(context.Background(), rs.Primary.ID) if err != nil { return fmt.Errorf("auditing (%s) does not exist", rs.Primary.ID) } } - return nil } diff --git a/internal/service/backupcompliancepolicy/resource_backup_compliance_policy_test.go b/internal/service/backupcompliancepolicy/resource_backup_compliance_policy_test.go index 38c1c882c0..ba5b239b64 100644 --- a/internal/service/backupcompliancepolicy/resource_backup_compliance_policy_test.go +++ b/internal/service/backupcompliancepolicy/resource_backup_compliance_policy_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -169,50 +168,38 @@ func TestAccGenericBackupRSBackupCompliancePolicy_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasBackupCompliancePolicyExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) projectID := ids["project_id"] - - schedule, _, err := conn.BackupCompliancePolicy.Get(context.Background(), projectID) + schedule, _, err := acc.Conn().BackupCompliancePolicy.Get(context.Background(), projectID) if err != nil || schedule == nil { return fmt.Errorf("backup compliance policy (%s) does not exist: %s", rs.Primary.ID, err) } - return nil } } func testAccCheckMongoDBAtlasBackupCompliancePolicyDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_backup_compliance_policy" { continue } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) projectID := ids["project_id"] - - compliancePolicy, _, err := conn.BackupCompliancePolicy.Get(context.Background(), projectID) + compliancePolicy, _, err := acc.Conn().BackupCompliancePolicy.Get(context.Background(), projectID) if compliancePolicy != nil || err == nil { return fmt.Errorf("Backup Compliance Policy (%s) still exists", rs.Primary.ID) } } - return nil } @@ -222,9 +209,7 @@ func testAccCheckMongoDBAtlasBackupCompliancePolicyImportStateIDFunc(resourceNam if !ok { return "", fmt.Errorf("Not found: %s", resourceName) } - ids := conversion.DecodeStateID(rs.Primary.ID) - return ids["project_id"], nil } } diff --git a/internal/service/cloudbackupschedule/resource_cloud_backup_schedule_test.go b/internal/service/cloudbackupschedule/resource_cloud_backup_schedule_test.go index ab669434fa..8003c3f11d 100644 --- a/internal/service/cloudbackupschedule/resource_cloud_backup_schedule_test.go +++ b/internal/service/cloudbackupschedule/resource_cloud_backup_schedule_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/mwielbut/pointy" matlas "go.mongodb.org/atlas/mongodbatlas" @@ -396,47 +395,36 @@ func TestAccBackupRSCloudBackupSchedule_azure(t *testing.T) { func testAccCheckMongoDBAtlasCloudBackupScheduleExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) projectID := ids["project_id"] clusterName := ids["cluster_name"] - - schedule, _, err := conn.CloudProviderSnapshotBackupPolicies.Get(context.Background(), projectID, clusterName) + schedule, _, err := acc.Conn().CloudProviderSnapshotBackupPolicies.Get(context.Background(), projectID, clusterName) if err != nil || schedule == nil { return fmt.Errorf("cloud Provider Snapshot Schedule (%s) does not exist: %s", rs.Primary.ID, err) } - return nil } } func testAccCheckMongoDBAtlasCloudBackupScheduleDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_cloud_backup_schedule" { continue } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) projectID := ids["project_id"] clusterName := ids["cluster_name"] - - schedule, _, err := conn.CloudProviderSnapshotBackupPolicies.Get(context.Background(), projectID, clusterName) + schedule, _, err := acc.Conn().CloudProviderSnapshotBackupPolicies.Get(context.Background(), projectID, clusterName) if schedule != nil || err == nil { return fmt.Errorf("cloud Provider Snapshot Schedule (%s) still exists", rs.Primary.ID) } diff --git a/internal/service/cloudbackupsnapshot/resource_cloud_backup_snapshot_test.go b/internal/service/cloudbackupsnapshot/resource_cloud_backup_snapshot_test.go index 05505ceaff..50ee740122 100644 --- a/internal/service/cloudbackupsnapshot/resource_cloud_backup_snapshot_test.go +++ b/internal/service/cloudbackupsnapshot/resource_cloud_backup_snapshot_test.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudbackupsnapshot" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" @@ -65,28 +64,21 @@ func TestAccBackupRSCloudBackupSnapshot_basic(t *testing.T) { func testAccCheckMongoDBAtlasCloudBackupSnapshotExists(resourceName string, cloudBackupSnapshot *matlas.CloudProviderSnapshot) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - ids := conversion.DecodeStateID(rs.Primary.ID) - if ids["snapshot_id"] == "" { return fmt.Errorf("no ID is set") } - log.Printf("[DEBUG] cloudBackupSnapshot ID: %s", ids["snapshot_id"]) - requestParameters := &matlas.SnapshotReqPathParameters{ SnapshotID: ids["snapshot_id"], GroupID: ids["project_id"], ClusterName: ids["cluster_name"], } - - res, _, err := conn.CloudProviderSnapshots.GetOneCloudProviderSnapshot(context.Background(), requestParameters) + res, _, err := acc.Conn().CloudProviderSnapshots.GetOneCloudProviderSnapshot(context.Background(), requestParameters) if err == nil { *cloudBackupSnapshot = *res return nil @@ -107,28 +99,21 @@ func testAccCheckMongoDBAtlasCloudBackupSnapshotAttributes(cloudBackupSnapshot * } func testAccCheckMongoDBAtlasCloudBackupSnapshotDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_cloud_backup_snapshot" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - requestParameters := &matlas.SnapshotReqPathParameters{ SnapshotID: ids["snapshot_id"], GroupID: ids["project_id"], ClusterName: ids["cluster_name"], } - - res, _, _ := conn.CloudProviderSnapshots.GetOneCloudProviderSnapshot(context.Background(), requestParameters) - + res, _, _ := acc.Conn().CloudProviderSnapshots.GetOneCloudProviderSnapshot(context.Background(), requestParameters) if res != nil { return fmt.Errorf("cloudBackupSnapshot (%s) still exists", rs.Primary.Attributes["snapshot_id"]) } } - return nil } diff --git a/internal/service/cloudbackupsnapshotexportbucket/resource_cloud_backup_snapshot_export_bucket_test.go b/internal/service/cloudbackupsnapshotexportbucket/resource_cloud_backup_snapshot_export_bucket_test.go index aeea90181f..1c04dfc651 100644 --- a/internal/service/cloudbackupsnapshotexportbucket/resource_cloud_backup_snapshot_export_bucket_test.go +++ b/internal/service/cloudbackupsnapshotexportbucket/resource_cloud_backup_snapshot_export_bucket_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -70,20 +69,15 @@ func TestAccBackupRSBackupSnapshotExportBucket_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasBackupSnapshotExportBucketExists(resourceName string, snapshotExportBucket *matlas.CloudProviderSnapshotExportBucket) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - response, _, err := conn.CloudProviderSnapshotExportBuckets.Get(context.Background(), ids["project_id"], ids["id"]) + response, _, err := acc.Conn().CloudProviderSnapshotExportBuckets.Get(context.Background(), ids["project_id"], ids["id"]) if err == nil { *snapshotExportBucket = *response return nil @@ -94,21 +88,16 @@ func testAccCheckMongoDBAtlasBackupSnapshotExportBucketExists(resourceName strin } func testAccCheckMongoDBAtlasBackupSnapshotExportBucketDestroy(state *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range state.RootModule().Resources { if rs.Type != "mongodbatlas_cloud_backup_snapshot_export_bucket" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - snapshotExportBucket, _, err := conn.CloudProviderSnapshotExportBuckets.Get(context.Background(), ids["project_id"], ids["id"]) + snapshotExportBucket, _, err := acc.Conn().CloudProviderSnapshotExportBuckets.Get(context.Background(), ids["project_id"], ids["id"]) if err == nil && snapshotExportBucket != nil { return fmt.Errorf("snapshot export bucket (%s) still exists", ids["id"]) } } - return nil } @@ -118,9 +107,7 @@ func testAccCheckMongoDBAtlasBackupSnapshotExportBucketImportStateIDFunc(resourc if !ok { return "", fmt.Errorf("not found: %s", resourceName) } - ids := conversion.DecodeStateID(rs.Primary.ID) - return fmt.Sprintf("%s-%s", ids["project_id"], ids["id"]), nil } } diff --git a/internal/service/cloudbackupsnapshotexportjob/resource_cloud_backup_snapshot_export_job_test.go b/internal/service/cloudbackupsnapshotexportjob/resource_cloud_backup_snapshot_export_job_test.go index be8ad0d6d5..c863697c3e 100644 --- a/internal/service/cloudbackupsnapshotexportjob/resource_cloud_backup_snapshot_export_job_test.go +++ b/internal/service/cloudbackupsnapshotexportjob/resource_cloud_backup_snapshot_export_job_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -70,45 +69,34 @@ func TestAccBackupRSBackupSnapshotExportJob_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasBackupSnapshotExportJobExists(resourceName string, snapshotExportJob *matlas.CloudProviderSnapshotExportJob) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - response, _, err := conn.CloudProviderSnapshotExportJobs.Get(context.Background(), ids["project_id"], ids["cluster_name"], ids["export_job_id"]) + response, _, err := acc.Conn().CloudProviderSnapshotExportJobs.Get(context.Background(), ids["project_id"], ids["cluster_name"], ids["export_job_id"]) if err == nil { *snapshotExportJob = *response return nil } - return fmt.Errorf("snapshot export job (%s) does not exist", ids["export_job_id"]) } } func testAccCheckMongoDBAtlasBackupSnapshotExportJobDestroy(state *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range state.RootModule().Resources { if rs.Type != "mongodbatlas_cloud_backup_snapshot_export_job" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - snapshotExportBucket, _, err := conn.CloudProviderSnapshotExportJobs.Get(context.Background(), ids["project_id"], ids["cluster_name"], ids["export_job_id"]) + snapshotExportBucket, _, err := acc.Conn().CloudProviderSnapshotExportJobs.Get(context.Background(), ids["project_id"], ids["cluster_name"], ids["export_job_id"]) if err == nil && snapshotExportBucket != nil { return fmt.Errorf("snapshot export job (%s) still exists", ids["export_job_id"]) } } - return nil } @@ -118,9 +106,7 @@ func testAccCheckMongoDBAtlasBackupSnapshotExportJobImportStateIDFunc(resourceNa if !ok { return "", fmt.Errorf("not found: %s", resourceName) } - ids := conversion.DecodeStateID(rs.Primary.ID) - return fmt.Sprintf("%s-%s-%s", ids["project_id"], ids["cluster_name"], ids["export_job_id"]), nil } } diff --git a/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job_test.go b/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job_test.go index 260a55c858..b44b29a0db 100644 --- a/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job_test.go +++ b/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -115,32 +114,24 @@ func TestAccBackupRSCloudBackupSnapshotRestoreJobWithPointTime_basic(t *testing. func testAccCheckMongoDBAtlasCloudBackupSnapshotRestoreJobExists(resourceName string, cloudBackupSnapshotRestoreJob *matlas.CloudProviderSnapshotRestoreJob) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - ids := conversion.DecodeStateID(rs.Primary.ID) - if ids["snapshot_restore_job_id"] == "" { return fmt.Errorf("no ID is set") } - log.Printf("[DEBUG] cloudBackupSnapshotRestoreJob ID: %s", rs.Primary.Attributes["snapshot_restore_job_id"]) - requestParameters := &matlas.SnapshotReqPathParameters{ GroupID: ids["project_id"], ClusterName: ids["cluster_name"], JobID: ids["snapshot_restore_job_id"], } - - if snapshotRes, _, err := conn.CloudProviderSnapshotRestoreJobs.Get(context.Background(), requestParameters); err == nil { + if snapshotRes, _, err := acc.Conn().CloudProviderSnapshotRestoreJobs.Get(context.Background(), requestParameters); err == nil { *cloudBackupSnapshotRestoreJob = *snapshotRes return nil } - return fmt.Errorf("cloudBackupSnapshotRestoreJob (%s) does not exist", rs.Primary.Attributes["snapshot_restore_job_id"]) } } @@ -156,27 +147,21 @@ func testAccCheckMongoDBAtlasCloudBackupSnapshotRestoreJobAttributes(cloudBackup } func testAccCheckMongoDBAtlasCloudBackupSnapshotRestoreJobDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_cloud_backup_snapshot_restore_job" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - requestParameters := &matlas.SnapshotReqPathParameters{ GroupID: ids["project_id"], ClusterName: ids["cluster_name"], JobID: ids["snapshot_restore_job_id"], } - - res, _, _ := conn.CloudProviderSnapshotRestoreJobs.Get(context.Background(), requestParameters) + res, _, _ := acc.Conn().CloudProviderSnapshotRestoreJobs.Get(context.Background(), requestParameters) if res != nil { return fmt.Errorf("cloudBackupSnapshotRestoreJob (%s) still exists", rs.Primary.Attributes["snapshot_restore_job_id"]) } } - return nil } @@ -186,7 +171,6 @@ func testAccCheckMongoDBAtlasCloudBackupSnapshotRestoreJobImportStateIDFunc(reso if !ok { return "", fmt.Errorf("not found:: %s", resourceName) } - return fmt.Sprintf("%s-%s-%s", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"], rs.Primary.Attributes["snapshot_restore_job_id"]), nil } } diff --git a/internal/service/cloudprovideraccess/resource_cloud_provider_access_authorization_test.go b/internal/service/cloudprovideraccess/resource_cloud_provider_access_authorization_test.go index deb0aa2226..be8580165c 100644 --- a/internal/service/cloudprovideraccess/resource_cloud_provider_access_authorization_test.go +++ b/internal/service/cloudprovideraccess/resource_cloud_provider_access_authorization_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudprovideraccess" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" @@ -155,26 +154,20 @@ func testAccMongoDBAtlasCloudProviderAccessAuthorizationAzure(orgID, projectName } func testAccCheckMongoDBAtlasProviderAccessDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_cloud_provider_access" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - roles, _, err := conn.CloudProviderAccess.ListRoles(context.Background(), ids["project_id"]) - + roles, _, err := acc.Conn().CloudProviderAccess.ListRoles(context.Background(), ids["project_id"]) if err != nil { return fmt.Errorf(cloudprovideraccess.ErrorCloudProviderGetRead, err) } - var targetRole matlas.CloudProviderAccessRole // searching in roles for i := range roles.AWSIAMRoles { role := &(roles.AWSIAMRoles[i]) - if role.RoleID == ids["id"] && role.ProviderName == ids["provider_name"] { targetRole = *role } @@ -185,6 +178,5 @@ func testAccCheckMongoDBAtlasProviderAccessDestroy(s *terraform.State) error { return fmt.Errorf("error cloud Provider Access Role (%s) still exists", ids["id"]) } } - return nil } diff --git a/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup_test.go b/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup_test.go index 033dcd49f6..602c7fe0dc 100644 --- a/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup_test.go +++ b/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudprovideraccess" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" @@ -164,27 +163,20 @@ func testAccMongoDBAtlasCloudProviderAccessSetupAzure(orgID, projectName, atlasA func testAccCheckMongoDBAtlasProviderAccessExists(resourceName string, targetRole *matlas.CloudProviderAccessRole) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.Attributes["project_id"] == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) providerName := ids["provider_name"] id := ids["id"] - - roles, _, err := conn.CloudProviderAccess.ListRoles(context.Background(), ids["project_id"]) - + roles, _, err := acc.Conn().CloudProviderAccess.ListRoles(context.Background(), ids["project_id"]) if err != nil { return fmt.Errorf(cloudprovideraccess.ErrorCloudProviderGetRead, err) } - if providerName == "AWS" { for i := range roles.AWSIAMRoles { if roles.AWSIAMRoles[i].RoleID == id && roles.AWSIAMRoles[i].ProviderName == providerName { @@ -193,7 +185,6 @@ func testAccCheckMongoDBAtlasProviderAccessExists(resourceName string, targetRol } } } - if providerName == "AZURE" { for i := range roles.AzureServicePrincipals { if *roles.AzureServicePrincipals[i].AzureID == id && roles.AzureServicePrincipals[i].ProviderName == providerName { @@ -202,7 +193,6 @@ func testAccCheckMongoDBAtlasProviderAccessExists(resourceName string, targetRol } } } - return fmt.Errorf("error cloud Provider Access (%s) does not exist", ids["project_id"]) } } diff --git a/internal/service/cluster/resource_cluster_test.go b/internal/service/cluster/resource_cluster_test.go index a77d47bdb8..0cc1999534 100644 --- a/internal/service/cluster/resource_cluster_test.go +++ b/internal/service/cluster/resource_cluster_test.go @@ -14,7 +14,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/plancheck" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" clustersvc "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cluster" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/mwielbut/pointy" @@ -1552,26 +1551,19 @@ func testAccGetMongoDBAtlasMajorVersion() string { func testAccCheckMongoDBAtlasClusterExists(resourceName string, cluster *matlas.Cluster) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - log.Printf("[DEBUG] projectID: %s, name %s", ids["project_id"], ids["cluster_name"]) - - if clusterResp, _, err := conn.Clusters.Get(context.Background(), ids["project_id"], ids["cluster_name"]); err == nil { + if clusterResp, _, err := acc.Conn().Clusters.Get(context.Background(), ids["project_id"], ids["cluster_name"]); err == nil { *cluster = *clusterResp return nil } - return fmt.Errorf("cluster(%s:%s) does not exist", rs.Primary.Attributes["project_id"], rs.Primary.ID) } } diff --git a/internal/service/clusteroutagesimulation/resource_cluster_outage_simulation_test.go b/internal/service/clusteroutagesimulation/resource_cluster_outage_simulation_test.go index fee05b74db..6f392f047e 100644 --- a/internal/service/clusteroutagesimulation/resource_cluster_outage_simulation_test.go +++ b/internal/service/clusteroutagesimulation/resource_cluster_outage_simulation_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -151,19 +150,15 @@ func testAccDataSourceMongoDBAtlasClusterOutageSimulationConfigMultiRegion(proje } func testAccCheckMongoDBAtlasClusterOutageSimulationDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_cluster_outage_simulation" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - _, _, err := conn.ClusterOutageSimulation.GetOutageSimulation(context.Background(), ids["project_id"], ids["cluster_name"]) + _, _, err := acc.Conn().ClusterOutageSimulation.GetOutageSimulation(context.Background(), ids["project_id"], ids["cluster_name"]) if err == nil { return fmt.Errorf("cluster outage simulation for project (%s) and cluster (%s) still exists", ids["project_id"], ids["cluster_name"]) } } - return nil } diff --git a/internal/service/customdbrole/resource_custom_db_role_test.go b/internal/service/customdbrole/resource_custom_db_role_test.go index dc672eb080..5405ebdcfd 100644 --- a/internal/service/customdbrole/resource_custom_db_role_test.go +++ b/internal/service/customdbrole/resource_custom_db_role_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/plancheck" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/mwielbut/pointy" "github.com/spf13/cast" @@ -601,44 +600,33 @@ func TestAccConfigRSCustomDBRoles_UpdatedInheritRoles(t *testing.T) { func testAccCheckMongoDBAtlasCustomDBRolesExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - _, _, err := conn.CustomDBRoles.Get(context.Background(), ids["project_id"], ids["role_name"]) + _, _, err := acc.Conn().CustomDBRoles.Get(context.Background(), ids["project_id"], ids["role_name"]) if err != nil { return fmt.Errorf("custom DB Role (%s) does not exist", ids["role_name"]) } - return nil } } func testAccCheckMongoDBAtlasCustomDBRolesDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_custom_db_role" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - _, _, err := conn.CustomDBRoles.Get(context.Background(), ids["project_id"], ids["role_name"]) + _, _, err := acc.Conn().CustomDBRoles.Get(context.Background(), ids["project_id"], ids["role_name"]) if err == nil { return fmt.Errorf("custom DB Role (%s) still exists", ids["role_name"]) } } - return nil } @@ -648,7 +636,6 @@ func testAccCheckMongoDBAtlasCustomDBRolesImportStateIDFunc(resourceName string) if !ok { return "", fmt.Errorf("not found: %s", resourceName) } - return fmt.Sprintf("%s-%s", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["role_name"]), nil } } diff --git a/internal/service/customdnsconfigurationclusteraws/resource_custom_dns_configuration_cluster_aws_test.go b/internal/service/customdnsconfigurationclusteraws/resource_custom_dns_configuration_cluster_aws_test.go index d65e048a89..d56be8f5a7 100644 --- a/internal/service/customdnsconfigurationclusteraws/resource_custom_dns_configuration_cluster_aws_test.go +++ b/internal/service/customdnsconfigurationclusteraws/resource_custom_dns_configuration_cluster_aws_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -84,40 +83,32 @@ func TestAccConfigRSCustomDNSConfigurationAWS_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasCustomDNSConfigurationAWSExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - _, _, err := conn.CustomAWSDNS.Get(context.Background(), rs.Primary.ID) + _, _, err := acc.Conn().CustomAWSDNS.Get(context.Background(), rs.Primary.ID) if err == nil { return nil } - return fmt.Errorf("custom dns configuration cluster(%s) does not exist", rs.Primary.ID) } } func testAccCheckMongoDBAtlasCustomDNSConfigurationAWSDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_custom_dns_configuration_cluster_aws" { continue } // Try to find the Custom DNS Configuration for Atlas Clusters on AWS - resp, _, err := conn.CustomAWSDNS.Get(context.Background(), rs.Primary.ID) + resp, _, err := acc.Conn().CustomAWSDNS.Get(context.Background(), rs.Primary.ID) if err != nil && resp != nil && resp.Enabled { return fmt.Errorf("custom dns configuration cluster aws (%s) still enabled", rs.Primary.ID) } } - return nil } @@ -127,7 +118,6 @@ func testAccCheckMongoDBAtlasCustomDNSConfigurationAWSStateIDFunc(resourceName s if !ok { return "", fmt.Errorf("not found: %s", resourceName) } - return rs.Primary.ID, nil } } diff --git a/internal/service/datalakepipeline/data_source_data_lake_pipeline_test.go b/internal/service/datalakepipeline/data_source_data_lake_pipeline_test.go index b3305e2eea..3e4902a8e0 100644 --- a/internal/service/datalakepipeline/data_source_data_lake_pipeline_test.go +++ b/internal/service/datalakepipeline/data_source_data_lake_pipeline_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -42,8 +41,6 @@ func TestAccDataSourceClusterRSDataLakePipeline_basic(t *testing.T) { } func testAccCheckMongoDBAtlasDataLakePipelineDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_data_lake_pipeline" { continue @@ -51,12 +48,11 @@ func testAccCheckMongoDBAtlasDataLakePipelineDestroy(s *terraform.State) error { ids := conversion.DecodeStateID(rs.Primary.ID) // Try to find the data lake pipeline - _, _, err := conn.DataLakePipeline.Get(context.Background(), ids["project_id"], ids["name"]) + _, _, err := acc.Conn().DataLakePipeline.Get(context.Background(), ids["project_id"], ids["name"]) if err == nil { return fmt.Errorf("datalake (%s) still exists", ids["project_id"]) } } - return nil } diff --git a/internal/service/datalakepipeline/resource_data_lake_pipeline_test.go b/internal/service/datalakepipeline/resource_data_lake_pipeline_test.go index 4e079848c1..e83cbdfde5 100644 --- a/internal/service/datalakepipeline/resource_data_lake_pipeline_test.go +++ b/internal/service/datalakepipeline/resource_data_lake_pipeline_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -62,25 +61,19 @@ func testAccCheckMongoDBAtlasDataLakePipelineImportStateIDFunc(resourceName stri func testAccCheckMongoDBAtlasDataLakePipelineExists(resourceName string, pipeline *matlas.DataLakePipeline) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - response, _, err := conn.DataLakePipeline.Get(context.Background(), ids["project_id"], ids["name"]) + response, _, err := acc.Conn().DataLakePipeline.Get(context.Background(), ids["project_id"], ids["name"]) if err == nil { *pipeline = *response return nil } - return fmt.Errorf("DataLake pipeline (%s) does not exist", ids["name"]) } } diff --git a/internal/service/encryptionatrest/resource_encryption_at_rest_test.go b/internal/service/encryptionatrest/resource_encryption_at_rest_test.go index 60df1d594a..4f087faedb 100644 --- a/internal/service/encryptionatrest/resource_encryption_at_rest_test.go +++ b/internal/service/encryptionatrest/resource_encryption_at_rest_test.go @@ -13,7 +13,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/encryptionatrest" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mocksvc" @@ -569,35 +568,26 @@ func TestResourceMongoDBAtlasEncryptionAtRestCreateRefreshFunc(t *testing.T) { func testAccCheckMongoDBAtlasEncryptionAtRestExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - connV2 := acc.TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - if _, _, err := connV2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(context.Background(), rs.Primary.ID).Execute(); err == nil { + if _, _, err := acc.ConnV2().EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(context.Background(), rs.Primary.ID).Execute(); err == nil { return nil } - return fmt.Errorf("encryptionAtRest (%s) does not exist", rs.Primary.ID) } } func testAccCheckMongoDBAtlasEncryptionAtRestDestroy(s *terraform.State) error { - connV2 := acc.TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_encryption_at_rest" { continue } - - res, _, err := connV2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(context.Background(), rs.Primary.ID).Execute() - + res, _, err := acc.ConnV2().EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(context.Background(), rs.Primary.ID).Execute() if err != nil || (*res.AwsKms.Enabled != false && *res.AzureKeyVault.Enabled != false && diff --git a/internal/service/eventtrigger/resource_event_trigger_test.go b/internal/service/eventtrigger/resource_event_trigger_test.go index df8ae86f1a..801b0ebe38 100644 --- a/internal/service/eventtrigger/resource_event_trigger_test.go +++ b/internal/service/eventtrigger/resource_event_trigger_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/mwielbut/pointy" "go.mongodb.org/realm/realm" @@ -432,7 +431,7 @@ func TestEventTriggerFunction_basic(t *testing.T) { func testAccCheckMongoDBAtlasEventTriggerExists(resourceName string, eventTrigger *realm.EventTrigger) resource.TestCheckFunc { return func(s *terraform.State) error { ctx := context.Background() - conn, err := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).GetRealmClient(ctx) + conn, err := acc.MongoDBClient.GetRealmClient(ctx) if err != nil { return err } @@ -462,7 +461,7 @@ func testAccCheckMongoDBAtlasEventTriggerExists(resourceName string, eventTrigge func testAccCheckMongoDBAtlasEventTriggerDestroy(s *terraform.State) error { ctx := context.Background() - conn, err := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).GetRealmClient(ctx) + conn, err := acc.MongoDBClient.GetRealmClient(ctx) if err != nil { return err } diff --git a/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go index 4f447a24fe..f8393e09ff 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "go.mongodb.org/atlas-sdk/v20231115004/admin" ) @@ -81,23 +80,18 @@ func TestAccFederatedDatabaseInstanceDS_s3Bucket(t *testing.T) { func checkExists(resourceName string, dataFederatedInstance *admin.DataLakeTenant) resource.TestCheckFunc { return func(s *terraform.State) error { - connV2 := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).AtlasV2 - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.Attributes["project_id"] == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - if dataLakeResp, _, err := connV2.DataFederationApi.GetFederatedDatabase(context.Background(), ids["project_id"], ids["name"]).Execute(); err == nil { + if dataLakeResp, _, err := acc.ConnV2().DataFederationApi.GetFederatedDatabase(context.Background(), ids["project_id"], ids["name"]).Execute(); err == nil { *dataFederatedInstance = *dataLakeResp return nil } - return fmt.Errorf("federated database instance (%s) does not exist", ids["project_id"]) } } diff --git a/internal/service/federatedquerylimit/data_source_federated_query_limit_test.go b/internal/service/federatedquerylimit/data_source_federated_query_limit_test.go index ad6352f60f..60f30bd6a2 100644 --- a/internal/service/federatedquerylimit/data_source_federated_query_limit_test.go +++ b/internal/service/federatedquerylimit/data_source_federated_query_limit_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -198,24 +197,18 @@ resource "mongodbatlas_federated_query_limit" "test" { func testAccCheckMongoDBAtlasFederatedDatabaseDataSourceQueryLimitExists(resourceName string, queryLimit *matlas.DataFederationQueryLimit) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.Attributes["project_id"] == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - if queryLimitResp, _, err := conn.DataFederation.GetQueryLimit(context.Background(), ids["project_id"], ids["tenant_name"], ids["limit_name"]); err == nil { + if queryLimitResp, _, err := acc.Conn().DataFederation.GetQueryLimit(context.Background(), ids["project_id"], ids["tenant_name"], ids["limit_name"]); err == nil { *queryLimit = *queryLimitResp return nil } - return fmt.Errorf("federated database query limit for project (%s), tenant (%s) and limit (%s) does not exist", ids["project_id"], ids["tenant_name"], ids["limit_name"]) } } @@ -226,7 +219,6 @@ func testAccCheckMongoDBAtlasFederatedDabaseQueryLimitAttributes(queryLimit *mat if queryLimit.Name != limitName { return fmt.Errorf("bad data federated query limit name: %s", queryLimit.Name) } - return nil } } diff --git a/internal/service/federatedquerylimit/resource_federated_query_limit_test.go b/internal/service/federatedquerylimit/resource_federated_query_limit_test.go index b7669361d8..8974de3e71 100644 --- a/internal/service/federatedquerylimit/resource_federated_query_limit_test.go +++ b/internal/service/federatedquerylimit/resource_federated_query_limit_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -204,19 +203,15 @@ func testAccCheckMongoDBAtlasFederatedDatabaseQueryLimitImportStateIDFunc(resour } func testAccCheckMongoDBAtlasFederatedDatabaseQueryLimitDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_federated_query_limit" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - _, _, err := conn.DataFederation.GetQueryLimit(context.Background(), ids["project_id"], ids["tenant_name"], ids["limit_name"]) + _, _, err := acc.Conn().DataFederation.GetQueryLimit(context.Background(), ids["project_id"], ids["tenant_name"], ids["limit_name"]) if err == nil { return fmt.Errorf("federated database query limit (%s) for project (%s) and tenant (%s)still exists", ids["project_id"], ids["tenant_name"], ids["limit_name"]) } } - return nil } diff --git a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_providers_test.go b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_providers_test.go index 5e7bf5c59d..4b167adde1 100644 --- a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_providers_test.go +++ b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_providers_test.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -50,22 +49,17 @@ func testAccMongoDBAtlasDataSourceFederatedSettingsIdentityProvidersConfig(feder func testAccCheckMongoDBAtlasFederatedSettingsIdentityProvidersExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - connV2 := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).AtlasV2 - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - _, _, err := connV2.FederatedAuthenticationApi.ListIdentityProviders(context.Background(), rs.Primary.Attributes["federation_settings_id"]).Execute() + _, _, err := acc.ConnV2().FederatedAuthenticationApi.ListIdentityProviders(context.Background(), rs.Primary.Attributes["federation_settings_id"]).Execute() if err != nil { return fmt.Errorf("FederatedSettingsIdentityProviders (%s) does not exist", rs.Primary.ID) } - return nil } } diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go index 003a9b2922..5941fe3546 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "go.mongodb.org/atlas-sdk/v20231115004/admin" ) @@ -80,25 +79,20 @@ func TestAccFedRSFederatedSettingsIdentityProvider_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasFederatedSettingsIdentityProviderExists(resourceName string, federatedSettingsIdentityProvider *admin.FederationIdentityProvider, idpID string) resource.TestCheckFunc { return func(s *terraform.State) error { - connV2 := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).AtlasV2 - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - response, _, err := connV2.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), + response, _, err := acc.ConnV2().FederatedAuthenticationApi.GetIdentityProvider(context.Background(), rs.Primary.Attributes["federation_settings_id"], idpID).Execute() if err == nil { *federatedSettingsIdentityProvider = *response return nil } - return fmt.Errorf("identity provider (%s) does not exist", idpID) } } diff --git a/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_org_test.go b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_org_test.go index ac0b692355..d044aca945 100644 --- a/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_org_test.go +++ b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_org_test.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -51,22 +50,17 @@ func testAccMongoDBAtlasDataSourceFederatedSettingsOrganizationConfigConfig(fede func testAccCheckMongoDBAtlasFederatedSettingsOrganizationConfigExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - _, _, err := conn.FederatedSettings.ListConnectedOrgs(context.Background(), rs.Primary.Attributes["federation_settings_id"], nil) + _, _, err := acc.Conn().FederatedSettings.ListConnectedOrgs(context.Background(), rs.Primary.Attributes["federation_settings_id"], nil) if err != nil { return fmt.Errorf("FederatedSettingsConnectedOrganization (%s) does not exist", rs.Primary.ID) } - return nil } } diff --git a/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_orgs_test.go b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_orgs_test.go index 75fe206dcf..ca40fd7481 100644 --- a/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_orgs_test.go +++ b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_orgs_test.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -50,22 +49,17 @@ func testAccMongoDBAtlasDataSourceFederatedSettingsOrganizationConfigsConfig(fed func testAccCheckMongoDBAtlasFederatedSettingsOrganizationConfigsExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - _, _, err := conn.FederatedSettings.ListConnectedOrgs(context.Background(), rs.Primary.Attributes["federation_settings_id"], nil) + _, _, err := acc.Conn().FederatedSettings.ListConnectedOrgs(context.Background(), rs.Primary.Attributes["federation_settings_id"], nil) if err != nil { return fmt.Errorf("FederatedSettingsConnectedOrganization (%s) does not exist", rs.Primary.ID) } - return nil } } diff --git a/internal/service/federatedsettingsorgconfig/data_source_federated_settings_test.go b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_test.go index 04d4207f63..7346ff4d82 100644 --- a/internal/service/federatedsettingsorgconfig/data_source_federated_settings_test.go +++ b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_test.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -50,24 +49,18 @@ func testAccMongoDBAtlasDataSourceFederatedSettingsConfig(orgID string) string { func testAccCheckMongoDBAtlasFederatedSettingsExists(resourceName string, federatedSettings *matlas.FederatedSettings) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - federatedSettingsRes, _, err := conn.FederatedSettings.Get(context.Background(), rs.Primary.Attributes["org_id"]) + federatedSettingsRes, _, err := acc.Conn().FederatedSettings.Get(context.Background(), rs.Primary.Attributes["org_id"]) if err != nil { return fmt.Errorf("FederatedSettings (%s) does not exist", rs.Primary.ID) } - federatedSettings = federatedSettingsRes - return nil } } diff --git a/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org_test.go b/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org_test.go index 45be35ab18..810d737952 100644 --- a/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org_test.go +++ b/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -78,25 +77,20 @@ func TestAccFedRSFederatedSettingsOrganizationConfig_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasFederatedSettingsOrganizationConfigRExists(resourceName string, federatedSettingsIdentityProvider *matlas.FederatedSettingsConnectedOrganization) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - response, _, err := conn.FederatedSettings.GetConnectedOrg(context.Background(), + response, _, err := acc.Conn().FederatedSettings.GetConnectedOrg(context.Background(), rs.Primary.Attributes["federation_settings_id"], rs.Primary.Attributes["org_id"]) if err == nil { *federatedSettingsIdentityProvider = *response return nil } - return fmt.Errorf("connected org (%s) does not exist", rs.Primary.Attributes["org_id"]) } } diff --git a/internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mappings_test.go b/internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mappings_test.go index d18bd6b127..9bb905a7a1 100644 --- a/internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mappings_test.go +++ b/internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mappings_test.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -51,22 +50,17 @@ func testAccMongoDBAtlasDataSourceFederatedSettingsOrganizationRoleMappingsConfi func testAccCheckMongoDBAtlasFederatedSettingsOrganizationRoleMappingsExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - _, _, err := conn.FederatedSettings.ListRoleMappings(context.Background(), rs.Primary.Attributes["federation_settings_id"], rs.Primary.Attributes["org_id"], nil) + _, _, err := acc.Conn().FederatedSettings.ListRoleMappings(context.Background(), rs.Primary.Attributes["federation_settings_id"], rs.Primary.Attributes["org_id"], nil) if err != nil { return fmt.Errorf("FederatedSettingsOrganizationRoleMappings (%s) does not exist", rs.Primary.ID) } - return nil } } diff --git a/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping_test.go b/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping_test.go index f035053401..d4955e76cd 100644 --- a/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping_test.go +++ b/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -71,47 +70,36 @@ func TestAccFedRSFederatedSettingsOrganizationRoleMapping_importBasic(t *testing func testAccCheckMongoDBAtlasFederatedSettingsOrganizationRoleMappingExists(resourceName string, federatedSettingsOrganizationRoleMapping *matlas.FederatedSettingsOrganizationRoleMapping) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - response, _, err := conn.FederatedSettings.GetRoleMapping(context.Background(), + response, _, err := acc.Conn().FederatedSettings.GetRoleMapping(context.Background(), rs.Primary.Attributes["federation_settings_id"], rs.Primary.Attributes["org_id"], rs.Primary.Attributes["role_mapping_id"]) if err == nil { *federatedSettingsOrganizationRoleMapping = *response - return nil } - return fmt.Errorf("role mapping (%s) does not exist", rs.Primary.Attributes["role_mapping_id"]) } } func testAccCheckMongoDBAtlasFederatedSettingsOrganizationRoleMappingDestroy(state *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range state.RootModule().Resources { if rs.Type != "mongodbatlas_federated_settings_org_role_mapping" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - roleMapping, _, err := conn.FederatedSettings.GetRoleMapping(context.Background(), ids["federation_settings_id"], ids["org_id"], ids["role_mapping_id"]) + roleMapping, _, err := acc.Conn().FederatedSettings.GetRoleMapping(context.Background(), ids["federation_settings_id"], ids["org_id"], ids["role_mapping_id"]) if err == nil && roleMapping != nil { return fmt.Errorf("role mapping (%s) still exists", ids["okta_idp_id"]) } } - return nil } diff --git a/internal/service/globalclusterconfig/resource_global_cluster_config_test.go b/internal/service/globalclusterconfig/resource_global_cluster_config_test.go index 92bc497b16..4cf04b3acb 100644 --- a/internal/service/globalclusterconfig/resource_global_cluster_config_test.go +++ b/internal/service/globalclusterconfig/resource_global_cluster_config_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -210,28 +209,21 @@ func TestAccClusterRSGlobalCluster_database(t *testing.T) { func testAccCheckMongoDBAtlasGlobalClusterExists(resourceName string, globalConfig *matlas.GlobalCluster) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - globalConfigResp, _, err := conn.GlobalClusters.Get(context.Background(), ids["project_id"], ids["cluster_name"]) + globalConfigResp, _, err := acc.Conn().GlobalClusters.Get(context.Background(), ids["project_id"], ids["cluster_name"]) if err == nil { *globalConfig = *globalConfigResp - if len(globalConfig.CustomZoneMapping) > 0 || len(globalConfig.ManagedNamespaces) > 0 { return nil } } - return fmt.Errorf("global config for cluster(%s) does not exist", ids["cluster_name"]) } } @@ -242,9 +234,7 @@ func testAccCheckMongoDBAtlasGlobalClusterImportStateIDFunc(resourceName string) if !ok { return "", fmt.Errorf("not found: %s", resourceName) } - ids := conversion.DecodeStateID(rs.Primary.ID) - return fmt.Sprintf("%s-%s", ids["project_id"], ids["cluster_name"]), nil } } @@ -254,26 +244,22 @@ func testAccCheckMongoDBAtlasGlobalClusterAttributes(globalCluster *matlas.Globa if len(globalCluster.ManagedNamespaces) != managedNamespacesCount { return fmt.Errorf("bad managed namespaces: %v", globalCluster.ManagedNamespaces) } - return nil } } func testAccCheckMongoDBAtlasGlobalClusterDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_global_cluster_config" { continue } // Try to find the cluster - globalConfig, _, err := conn.GlobalClusters.Get(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"]) + globalConfig, _, err := acc.Conn().GlobalClusters.Get(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"]) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf("No cluster named %s exists in group %s", rs.Primary.Attributes["cluster_name"], rs.Primary.Attributes["project_id"])) { return nil } - return err } @@ -281,7 +267,6 @@ func testAccCheckMongoDBAtlasGlobalClusterDestroy(s *terraform.State) error { return fmt.Errorf("global cluster configuration for cluster(%s) still exists", rs.Primary.Attributes["cluster_name"]) } } - return nil } diff --git a/internal/service/ldapconfiguration/resource_ldap_configuration_test.go b/internal/service/ldapconfiguration/resource_ldap_configuration_test.go index b676ebd4be..daefd1aaa0 100644 --- a/internal/service/ldapconfiguration/resource_ldap_configuration_test.go +++ b/internal/service/ldapconfiguration/resource_ldap_configuration_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/spf13/cast" matlas "go.mongodb.org/atlas/mongodbatlas" @@ -144,24 +143,18 @@ func TestAccAdvRSLDAPConfiguration_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasLDAPConfigurationExists(resourceName string, ldapConf *matlas.LDAPConfiguration) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - ldapConfRes, _, err := conn.LDAPConfigurations.Get(context.Background(), rs.Primary.ID) + ldapConfRes, _, err := acc.Conn().LDAPConfigurations.Get(context.Background(), rs.Primary.ID) if err != nil { return fmt.Errorf("ldapConfiguration (%s) does not exist", rs.Primary.ID) } - ldapConf = ldapConfRes - return nil } } diff --git a/internal/service/ldapverify/resource_ldap_verify_test.go b/internal/service/ldapverify/resource_ldap_verify_test.go index 02a7636de7..47211dbca0 100644 --- a/internal/service/ldapverify/resource_ldap_verify_test.go +++ b/internal/service/ldapverify/resource_ldap_verify_test.go @@ -6,7 +6,6 @@ import ( "os" "testing" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/spf13/cast" @@ -139,42 +138,33 @@ func TestAccAdvRSLDAPVerify_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasLDAPVerifyExists(resourceName string, ldapConf *matlas.LDAPConfiguration) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - - ldapConfRes, _, err := conn.LDAPConfigurations.GetStatus(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["request_id"]) + ldapConfRes, _, err := acc.Conn().LDAPConfigurations.GetStatus(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["request_id"]) if err != nil { return fmt.Errorf("ldapVerify (%s) does not exist", rs.Primary.ID) } - ldapConf = ldapConfRes - return nil } } func testAccCheckMongoDBAtlasLDAPVerifyDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_ldap_verify" { continue } - _, _, err := conn.LDAPConfigurations.GetStatus(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["request_id"]) + _, _, err := acc.Conn().LDAPConfigurations.GetStatus(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["request_id"]) if err == nil { return fmt.Errorf("ldapVerify (%s) still exists", rs.Primary.ID) } } - return nil } @@ -184,7 +174,6 @@ func testAccCheckMongoDBAtlasLDAPVerifyImportStateIDFunc(resourceName string) re if !ok { return "", fmt.Errorf("not found: %s", resourceName) } - return fmt.Sprintf("%s-%s", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["request_id"]), nil } } diff --git a/internal/service/maintenancewindow/resource_maintenance_window_test.go b/internal/service/maintenancewindow/resource_maintenance_window_test.go index b8cb61cd1d..afd89a6cba 100644 --- a/internal/service/maintenancewindow/resource_maintenance_window_test.go +++ b/internal/service/maintenancewindow/resource_maintenance_window_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/spf13/cast" matlas "go.mongodb.org/atlas/mongodbatlas" @@ -149,26 +148,19 @@ func testAccMongoDBAtlasMaintenanceWindowConfigAutoDeferEnabled(orgID, projectNa func testAccCheckMongoDBAtlasMaintenanceWindowExists(resourceName string, maintenance *matlas.MaintenanceWindow) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - log.Printf("[DEBUG] projectID: %s", rs.Primary.ID) - - maintenanceWindow, _, err := conn.MaintenanceWindows.Get(context.Background(), rs.Primary.ID) + maintenanceWindow, _, err := acc.Conn().MaintenanceWindows.Get(context.Background(), rs.Primary.ID) if err != nil { return fmt.Errorf("maintenance Window (%s) does not exist", rs.Primary.ID) } - *maintenance = *maintenanceWindow - return nil } } diff --git a/internal/service/networkcontainer/resource_network_container_test.go b/internal/service/networkcontainer/resource_network_container_test.go index 11b590e446..6e07bd4451 100644 --- a/internal/service/networkcontainer/resource_network_container_test.go +++ b/internal/service/networkcontainer/resource_network_container_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -231,24 +230,18 @@ func testAccCheckMongoDBAtlasNetworkContainerImportStateIDFunc(resourceName stri func testAccCheckMongoDBAtlasNetworkContainerExists(resourceName string, container *matlas.Container) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - log.Printf("[DEBUG] projectID: %s", rs.Primary.Attributes["project_id"]) - - if containerResp, _, err := conn.Containers.Get(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["container_id"]); err == nil { + if containerResp, _, err := acc.Conn().Containers.Get(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["container_id"]); err == nil { *container = *containerResp return nil } - return fmt.Errorf("container(%s:%s) does not exist", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["container_id"]) } } @@ -258,27 +251,23 @@ func testAccCheckMongoDBAtlasNetworkContainerAttributes(container *matlas.Contai if container.ProviderName != providerName { return fmt.Errorf("bad provider name: %s", container.ProviderName) } - return nil } } func testAccCheckMongoDBAtlasNetworkContainerDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_container" { continue } // Try to find the container - _, _, err := conn.Containers.Get(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["container_id"]) + _, _, err := acc.Conn().Containers.Get(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["container_id"]) if err == nil { return fmt.Errorf("container (%s:%s) still exists", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["container_id"]) } } - return nil } diff --git a/internal/service/networkpeering/resource_network_peering_test.go b/internal/service/networkpeering/resource_network_peering_test.go index 5a97c913c4..52f9cf09f7 100644 --- a/internal/service/networkpeering/resource_network_peering_test.go +++ b/internal/service/networkpeering/resource_network_peering_test.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -228,27 +227,20 @@ func testAccCheckMongoDBAtlasNetworkPeeringImportStateIDFunc(resourceName string func testAccCheckMongoDBAtlasNetworkPeeringExists(resourceName string, peer *matlas.Peer) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) log.Printf("[DEBUG] projectID: %s", ids["project_id"]) - - if peerResp, _, err := conn.Peers.Get(context.Background(), ids["project_id"], ids["peer_id"]); err == nil { + if peerResp, _, err := acc.Conn().Peers.Get(context.Background(), ids["project_id"], ids["peer_id"]); err == nil { *peer = *peerResp peer.ProviderName = ids["provider_name"] - return nil } - return fmt.Errorf("peer(%s:%s) does not exist", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["peer_id"]) } } diff --git a/internal/service/onlinearchive/resource_online_archive_test.go b/internal/service/onlinearchive/resource_online_archive_test.go index 8bef4a75bf..b26dd98aec 100644 --- a/internal/service/onlinearchive/resource_online_archive_test.go +++ b/internal/service/onlinearchive/resource_online_archive_test.go @@ -15,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -242,35 +241,26 @@ func TestAccBackupRSOnlineArchiveInvalidProcessRegion(t *testing.T) { func populateWithSampleData(resourceName string, cluster *matlas.Cluster) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestMongoDBClient.(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - log.Printf("[DEBUG] projectID: %s, name %s", ids["project_id"], ids["cluster_name"]) - - clusterResp, _, err := conn.Clusters.Get(context.Background(), ids["project_id"], ids["cluster_name"]) - + clusterResp, _, err := acc.Conn().Clusters.Get(context.Background(), ids["project_id"], ids["cluster_name"]) if err != nil { return fmt.Errorf("cluster(%s:%s) does not exist %s", rs.Primary.Attributes["project_id"], rs.Primary.ID, err) } - *cluster = *clusterResp - job, _, err := conn.Clusters.LoadSampleDataset(context.Background(), ids["project_id"], ids["cluster_name"]) + job, _, err := acc.Conn().Clusters.LoadSampleDataset(context.Background(), ids["project_id"], ids["cluster_name"]) if err != nil { return fmt.Errorf("cluster(%s:%s) loading sample data set error %s", rs.Primary.Attributes["project_id"], rs.Primary.ID, err) } - ticker := time.NewTicker(30 * time.Second) JOB: @@ -279,7 +269,7 @@ func populateWithSampleData(resourceName string, cluster *matlas.Cluster) resour case <-time.After(20 * time.Second): log.Println("timeout elapsed ....") case <-ticker.C: - job, _, err = conn.Clusters.GetSampleDatasetStatus(context.Background(), ids["project_id"], job.ID) + job, _, err = acc.Conn().Clusters.GetSampleDatasetStatus(context.Background(), ids["project_id"], job.ID) fmt.Println("querying for job ") if job.State != "WORKING" { break JOB diff --git a/internal/service/organization/resource_organization_test.go b/internal/service/organization/resource_organization_test.go index 06ae7ac6ac..b01477d3d6 100644 --- a/internal/service/organization/resource_organization_test.go +++ b/internal/service/organization/resource_organization_test.go @@ -236,7 +236,7 @@ func getTestClientWithNewOrgCreds(rs *terraform.ResourceState) (*admin.APIClient cfg := config.Config{ PublicKey: rs.Primary.Attributes["public_key"], PrivateKey: rs.Primary.Attributes["private_key"], - BaseURL: acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Config.BaseURL, + BaseURL: acc.MongoDBClient.Config.BaseURL, } ctx := context.Background() diff --git a/internal/service/orginvitation/resource_org_invitation_test.go b/internal/service/orginvitation/resource_org_invitation_test.go index c0e20d14c7..ba8d2e00b6 100644 --- a/internal/service/orginvitation/resource_org_invitation_test.go +++ b/internal/service/orginvitation/resource_org_invitation_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -96,33 +95,25 @@ func TestAccConfigRSOrgInvitation_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasOrgInvitationExists(t *testing.T, resourceName string, invitation *matlas.Invitation) resource.TestCheckFunc { t.Helper() return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - ids := conversion.DecodeStateID(rs.Primary.ID) - orgID := ids["org_id"] username := ids["username"] invitationID := ids["invitation_id"] - if orgID == "" && username == "" && invitationID == "" { return fmt.Errorf("no ID is set") } - t.Logf("orgID: %s", orgID) t.Logf("username: %s", username) t.Logf("invitationID: %s", invitationID) - - invitationResp, _, err := conn.Organizations.Invitation(context.Background(), orgID, invitationID) + invitationResp, _, err := acc.Conn().Organizations.Invitation(context.Background(), orgID, invitationID) if err == nil { *invitation = *invitationResp return nil } - return fmt.Errorf("invitation(%s) does not exist", invitationID) } } diff --git a/internal/service/privateendpointregionalmode/data_source_private_endpoint_regional_mode_test.go b/internal/service/privateendpointregionalmode/data_source_private_endpoint_regional_mode_test.go index 4f8fe2fbf9..a1c113c23d 100644 --- a/internal/service/privateendpointregionalmode/data_source_private_endpoint_regional_mode_test.go +++ b/internal/service/privateendpointregionalmode/data_source_private_endpoint_regional_mode_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -34,14 +33,10 @@ func TestAccNetworkDSPrivateEndpointRegionalMode_basic(t *testing.T) { func testAccMongoDBAtlasPrivateEndpointRegionalModeUnmanagedResource(resourceName, projectID string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - - setting, _, err := conn.PrivateEndpoints.GetRegionalizedPrivateEndpointSetting(context.Background(), projectID) - + setting, _, err := acc.Conn().PrivateEndpoints.GetRegionalizedPrivateEndpointSetting(context.Background(), projectID) if err != nil || setting == nil { return fmt.Errorf("Could not get regionalized private endpoint setting for project_id (%s)", projectID) } - return resource.TestCheckResourceAttr(resourceName, "enabled", strconv.FormatBool(setting.Enabled))(s) } } diff --git a/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode_test.go b/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode_test.go index 077ca59605..bab8b35441 100644 --- a/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode_test.go +++ b/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedcluster" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -149,27 +148,18 @@ func testAccMongoDBAtlasPrivateEndpointRegionalModeConfig(resourceName, projectI func testAccCheckMongoDBAtlasPrivateEndpointRegionalModeExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - fmt.Printf("==========================================================================\n") - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] - if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - projectID := rs.Primary.ID - - _, _, err := conn.PrivateEndpoints.GetRegionalizedPrivateEndpointSetting(context.Background(), projectID) - + _, _, err := acc.Conn().PrivateEndpoints.GetRegionalizedPrivateEndpointSetting(context.Background(), projectID) if err == nil { return nil } - return fmt.Errorf("regional mode for project_id (%s) does not exist", projectID) } } @@ -177,61 +167,44 @@ func testAccCheckMongoDBAtlasPrivateEndpointRegionalModeExists(resourceName stri func testAccCheckMongoDBAtlasPrivateEndpointRegionalModeClustersUpToDate(projectID, clusterName, clusterResourceName string) resource.TestCheckFunc { resourceName := strings.Join([]string{"data", "mongodbatlas_cluster", clusterResourceName}, ".") return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] - if !ok { return fmt.Errorf("Could not find resource state for cluster (%s) on project (%s)", clusterName, projectID) } - var rsPrivateEndpointCount int var err error - if rsPrivateEndpointCount, err = strconv.Atoi(rs.Primary.Attributes["connection_strings.0.private_endpoint.#"]); err != nil { return fmt.Errorf("Connection strings private endpoint count is not a number") } - - c, _, _ := conn.Clusters.Get(context.Background(), projectID, clusterName) - + c, _, _ := acc.Conn().Clusters.Get(context.Background(), projectID, clusterName) fmt.Printf("testAccCheckMongoDBAtlasPrivateEndpointRegionalModeClustersUpToDate %#v \n", rs.Primary.Attributes) fmt.Printf("cluster.ConnectionStrings %#v \n", advancedcluster.FlattenConnectionStrings(c.ConnectionStrings)) - if rsPrivateEndpointCount != len(c.ConnectionStrings.PrivateEndpoint) { return fmt.Errorf("Cluster PrivateEndpoint count does not match resource") } - if rs.Primary.Attributes["connection_strings.0.standard"] != c.ConnectionStrings.Standard { return fmt.Errorf("Cluster standard connection_string does not match resource") } - if rs.Primary.Attributes["connection_strings.0.standard_srv"] != c.ConnectionStrings.StandardSrv { return fmt.Errorf("Cluster standard connection_string does not match resource") } - return nil } } func testAccCheckMongoDBAtlasPrivateEndpointRegionalModeDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_private_endpoint_regional_mode" { continue } - - setting, _, err := conn.PrivateEndpoints.GetRegionalizedPrivateEndpointSetting(context.Background(), rs.Primary.ID) - + setting, _, err := acc.Conn().PrivateEndpoints.GetRegionalizedPrivateEndpointSetting(context.Background(), rs.Primary.ID) if err != nil { return fmt.Errorf("Could not read regionalized private endpoint setting for project %q", rs.Primary.ID) } - if setting.Enabled != false { return fmt.Errorf("Regionalized private endpoint setting for project %q was not properly disabled", rs.Primary.ID) } } - return nil } diff --git a/internal/service/privatelinkendpoint/resource_privatelink_endpoint_test.go b/internal/service/privatelinkendpoint/resource_privatelink_endpoint_test.go index 6c2ea9d742..5d5b625353 100644 --- a/internal/service/privatelinkendpoint/resource_privatelink_endpoint_test.go +++ b/internal/service/privatelinkendpoint/resource_privatelink_endpoint_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -191,42 +190,32 @@ func testAccCheckMongoDBAtlasPrivateLinkEndpointImportStateIDFunc(resourceName s func testAccCheckMongoDBAtlasPrivateLinkEndpointExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - if _, _, err := conn.PrivateEndpoints.Get(context.Background(), ids["project_id"], ids["provider_name"], ids["private_link_id"]); err == nil { + if _, _, err := acc.Conn().PrivateEndpoints.Get(context.Background(), ids["project_id"], ids["provider_name"], ids["private_link_id"]); err == nil { return nil } - return fmt.Errorf("the MongoDB Private Endpoint(%s) for the project(%s) does not exist", rs.Primary.Attributes["private_link_id"], rs.Primary.Attributes["project_id"]) } } func testAccCheckMongoDBAtlasPrivateLinkEndpointDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_privatelink_endpoint" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - _, _, err := conn.PrivateEndpoints.Get(context.Background(), ids["project_id"], ids["provider_name"], ids["private_link_id"]) + _, _, err := acc.Conn().PrivateEndpoints.Get(context.Background(), ids["project_id"], ids["provider_name"], ids["private_link_id"]) if err == nil { return fmt.Errorf("the MongoDB Private Endpoint(%s) still exists", ids["private_link_id"]) } } - return nil } diff --git a/internal/service/privatelinkendpointserverless/resource_privatelink_endpoint_serverless_test.go b/internal/service/privatelinkendpointserverless/resource_privatelink_endpoint_serverless_test.go index 74ed77de68..ba78768836 100644 --- a/internal/service/privatelinkendpointserverless/resource_privatelink_endpoint_serverless_test.go +++ b/internal/service/privatelinkendpointserverless/resource_privatelink_endpoint_serverless_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -69,21 +68,16 @@ func TestAccServerlessPrivateLinkEndpoint_importBasic(t *testing.T) { } func testAccCheckMongoDBAtlasPrivateLinkEndpointServerlessDestroy(state *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range state.RootModule().Resources { if rs.Type != "mongodbatlas_privatelink_endpoint_serverless" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - privateLink, _, err := conn.ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) + privateLink, _, err := acc.Conn().ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) if err == nil && privateLink != nil { return fmt.Errorf("endpoint_id (%s) still exists", ids["endpoint_id"]) } } - return nil } @@ -102,24 +96,18 @@ func testAccMongoDBAtlasPrivateLinkEndpointServerlessConfig(orgID, projectName, func testAccCheckMongoDBAtlasPrivateLinkEndpointServerlessExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - _, _, err := conn.ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) + _, _, err := acc.Conn().ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) if err == nil { return nil } - return fmt.Errorf("endpoint_id (%s) does not exist", ids["endpoint_id"]) } } @@ -130,9 +118,7 @@ func testAccCheckMongoDBAtlasPrivateLinkEndpointServerlessImportStateIDFunc(reso if !ok { return "", fmt.Errorf("not found: %s", resourceName) } - ids := conversion.DecodeStateID(rs.Primary.ID) - return fmt.Sprintf("%s--%s--%s", ids["project_id"], ids["instance_name"], ids["endpoint_id"]), nil } } diff --git a/internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service_test.go b/internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service_test.go index 7a9e2ccc5f..29d9e3cf28 100644 --- a/internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service_test.go +++ b/internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -111,20 +110,15 @@ func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceImportStateIDFunc(resourc func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestMongoDBClient.(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - _, _, err := conn.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), ids["project_id"], ids["provider_name"], ids["private_link_id"], ids["endpoint_service_id"]) + _, _, err := acc.Conn().PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), ids["project_id"], ids["provider_name"], ids["private_link_id"], ids["endpoint_service_id"]) if err == nil { return nil } @@ -134,20 +128,16 @@ func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceExists(resourceName strin } func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceDestroy(s *terraform.State) error { - conn := acc.TestMongoDBClient.(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_privatelink_endpoint_service" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - _, _, err := conn.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), ids["project_id"], ids["provider_name"], ids["private_link_id"], ids["endpoint_service_id"]) + _, _, err := acc.Conn().PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), ids["project_id"], ids["provider_name"], ids["private_link_id"], ids["endpoint_service_id"]) if err == nil { return fmt.Errorf("the MongoDB Private Endpoint(%s) still exists", ids["endpoint_service_id"]) } } - return nil } diff --git a/internal/service/privatelinkendpointservicedatafederationonlinearchive/resource_privatelink_endpoint_service_data_federation_online_archive_test.go b/internal/service/privatelinkendpointservicedatafederationonlinearchive/resource_privatelink_endpoint_service_data_federation_online_archive_test.go index 76bd9e2f47..5982428bab 100644 --- a/internal/service/privatelinkendpointservicedatafederationonlinearchive/resource_privatelink_endpoint_service_data_federation_online_archive_test.go +++ b/internal/service/privatelinkendpointservicedatafederationonlinearchive/resource_privatelink_endpoint_service_data_federation_online_archive_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -61,46 +60,33 @@ func testAccCheckMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchi } func testAccCheckMongoDBAtlasPrivateEndpointServiceDataFederationOnlineArchiveDestroy(s *terraform.State) error { - client := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_privatelink_endpoint_service_data_federation_online_archive" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - _, _, err := client.DataLakes.GetPrivateLinkEndpoint(context.Background(), ids["project_id"], ids["endpoint_id"]) - + _, _, err := acc.Conn().DataLakes.GetPrivateLinkEndpoint(context.Background(), ids["project_id"], ids["endpoint_id"]) if err == nil { return fmt.Errorf("Private endpoint service data federation online archive still exists") } } - return nil } func testAccCheckMongoDBAtlasPrivateEndpointServiceDataFederationOnlineArchiveExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - client := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] - if !ok { return fmt.Errorf("Private endpoint service data federation online archive not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("Private endpoint service data federation online archive ID not set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - _, _, err := client.DataLakes.GetPrivateLinkEndpoint(context.Background(), ids["project_id"], ids["endpoint_id"]) - + _, _, err := acc.Conn().DataLakes.GetPrivateLinkEndpoint(context.Background(), ids["project_id"], ids["endpoint_id"]) if err != nil { return err } - return nil } } diff --git a/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless_test.go b/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless_test.go index b0ae6548b8..1e988a8db4 100644 --- a/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless_test.go +++ b/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -78,21 +77,16 @@ func TestAccServerlessPrivateLinkEndpointService_importBasic(t *testing.T) { } func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessDestroy(state *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range state.RootModule().Resources { if rs.Type != "mongodbatlas_privatelink_endpoint_service_serverless" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - privateLink, _, err := conn.ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) + privateLink, _, err := acc.Conn().ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) if err == nil && privateLink != nil { return fmt.Errorf("endpoint_id (%s) still exists", ids["endpoint_id"]) } } - return nil } @@ -153,24 +147,18 @@ func testAccMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(orgID, projec func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - _, _, err := conn.ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) + _, _, err := acc.Conn().ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) if err == nil { return nil } - return fmt.Errorf("endpoint_id (%s) does not exist", ids["endpoint_id"]) } } @@ -181,9 +169,7 @@ func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessImportStateIDFu if !ok { return "", fmt.Errorf("not found: %s", resourceName) } - ids := conversion.DecodeStateID(rs.Primary.ID) - return fmt.Sprintf("%s--%s--%s", ids["project_id"], ids["instance_name"], ids["endpoint_id"]), nil } } diff --git a/internal/service/projectapikey/resource_project_api_key_test.go b/internal/service/projectapikey/resource_project_api_key_test.go index 49dbb832c1..5cfc72e412 100644 --- a/internal/service/projectapikey/resource_project_api_key_test.go +++ b/internal/service/projectapikey/resource_project_api_key_test.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -303,14 +302,13 @@ func TestAccConfigRSProjectAPIKey_DeleteProjectAndAssignment(t *testing.T) { } func deleteAPIKeyManually(orgID, descriptionPrefix string) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - list, _, err := conn.APIKeys.List(context.Background(), orgID, &matlas.ListOptions{}) + list, _, err := acc.Conn().APIKeys.List(context.Background(), orgID, &matlas.ListOptions{}) if err != nil { return err } for _, key := range list { if strings.HasPrefix(key.Desc, descriptionPrefix) { - if _, err := conn.APIKeys.Delete(context.Background(), orgID, key.ID); err != nil { + if _, err := acc.Conn().APIKeys.Delete(context.Background(), orgID, key.ID); err != nil { return err } } @@ -319,27 +317,21 @@ func deleteAPIKeyManually(orgID, descriptionPrefix string) error { } func testAccCheckMongoDBAtlasProjectAPIKeyDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_project_api_key" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - projectAPIKeys, _, err := conn.ProjectAPIKeys.List(context.Background(), ids["project_id"], nil) + projectAPIKeys, _, err := acc.Conn().ProjectAPIKeys.List(context.Background(), ids["project_id"], nil) if err != nil { return nil } - for _, val := range projectAPIKeys { if val.ID == ids["api_key_id"] { return fmt.Errorf("Project API Key (%s) still exists", ids["role_name"]) } } } - return nil } diff --git a/internal/service/projectinvitation/resource_project_invitation_test.go b/internal/service/projectinvitation/resource_project_invitation_test.go index 3c32dbbccc..bc7eb5b936 100644 --- a/internal/service/projectinvitation/resource_project_invitation_test.go +++ b/internal/service/projectinvitation/resource_project_invitation_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -102,33 +101,25 @@ func TestAccProjectRSProjectInvitation_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasProjectInvitationExists(t *testing.T, resourceName string, invitation *matlas.Invitation) resource.TestCheckFunc { t.Helper() return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - ids := conversion.DecodeStateID(rs.Primary.ID) - projectID := ids["project_id"] username := ids["username"] invitationID := ids["invitation_id"] - if projectID == "" && username == "" && invitationID == "" { return fmt.Errorf("no ID is set") } - t.Logf("projectID: %s", projectID) t.Logf("username: %s", username) t.Logf("invitationID: %s", invitationID) - - invitationResp, _, err := conn.Projects.Invitation(context.Background(), projectID, invitationID) + invitationResp, _, err := acc.Conn().Projects.Invitation(context.Background(), projectID, invitationID) if err == nil { *invitation = *invitationResp return nil } - return fmt.Errorf("invitation(%s) does not exist", invitationID) } } @@ -138,7 +129,6 @@ func testAccCheckMongoDBAtlasProjectInvitationUsernameAttribute(invitation *matl if invitation.Username != username { return fmt.Errorf("bad name: %s", invitation.Username) } - return nil } } @@ -160,25 +150,20 @@ func testAccCheckMongoDBAtlasProjectInvitationRoleAttribute(invitation *matlas.I } func testAccCheckMongoDBAtlasProjectInvitationDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_invitations" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - projectID := ids["project_id"] invitationID := ids["invitation_id"] // Try to find the invitation - _, _, err := conn.Projects.Invitation(context.Background(), projectID, invitationID) + _, _, err := acc.Conn().Projects.Invitation(context.Background(), projectID, invitationID) if err == nil { return fmt.Errorf("invitation (%s) still exists", invitationID) } } - return nil } @@ -188,7 +173,6 @@ func testAccCheckMongoDBAtlasProjectInvitationStateIDFunc(resourceName string) r if !ok { return "", fmt.Errorf("not found: %s", resourceName) } - return fmt.Sprintf("%s-%s", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["username"]), nil } } diff --git a/internal/service/searchdeployment/resource_search_deployment_test.go b/internal/service/searchdeployment/resource_search_deployment_test.go index ab2bb8e6e2..6c13b9cfb7 100644 --- a/internal/service/searchdeployment/resource_search_deployment_test.go +++ b/internal/service/searchdeployment/resource_search_deployment_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -126,8 +125,7 @@ func checkExists(resourceName string) resource.TestCheckFunc { return fmt.Errorf("not found: %s", resourceName) } - connV2 := acc.TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - _, _, err := connV2.AtlasSearchApi.GetAtlasSearchDeployment(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"]).Execute() + _, _, err := acc.ConnV2().AtlasSearchApi.GetAtlasSearchDeployment(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"]).Execute() if err != nil { return fmt.Errorf("search deployment (%s:%s) does not exist", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"]) } @@ -142,10 +140,9 @@ func checkDestroy(state *terraform.State) error { if clusterDestroyedErr := acc.CheckDestroyTeamAdvancedCluster(state); clusterDestroyedErr != nil { return clusterDestroyedErr } - connV2 := acc.TestMongoDBClient.(*config.MongoDBClient).AtlasV2 for _, rs := range state.RootModule().Resources { if rs.Type == "mongodbatlas_search_deployment" { - _, _, err := connV2.AtlasSearchApi.GetAtlasSearchDeployment(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"]).Execute() + _, _, err := acc.ConnV2().AtlasSearchApi.GetAtlasSearchDeployment(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"]).Execute() if err == nil { return fmt.Errorf("search deployment (%s:%s) still exists", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"]) } diff --git a/internal/service/searchindex/resource_search_index_test.go b/internal/service/searchindex/resource_search_index_test.go index 8994ce44cb..d27449852f 100644 --- a/internal/service/searchindex/resource_search_index_test.go +++ b/internal/service/searchindex/resource_search_index_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -361,14 +360,11 @@ func checkExists(resourceName string) resource.TestCheckFunc { if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } ids := conversion.DecodeStateID(rs.Primary.ID) - - connV2 := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).AtlasV2 - _, _, err := connV2.AtlasSearchApi.GetAtlasSearchIndex(context.Background(), ids["project_id"], ids["cluster_name"], ids["index_id"]).Execute() + _, _, err := acc.ConnV2().AtlasSearchApi.GetAtlasSearchIndex(context.Background(), ids["project_id"], ids["cluster_name"], ids["index_id"]).Execute() if err != nil { return fmt.Errorf("index (%s) does not exist", ids["index_id"]) } diff --git a/internal/service/serverlessinstance/resource_serverless_instance_test.go b/internal/service/serverlessinstance/resource_serverless_instance_test.go index ded2e89b10..a3036df125 100644 --- a/internal/service/serverlessinstance/resource_serverless_instance_test.go +++ b/internal/service/serverlessinstance/resource_serverless_instance_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -159,45 +158,34 @@ func TestAccServerlessInstance_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasServerlessInstanceExists(resourceName string, serverlessInstance *matlas.Cluster) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - serverlessResponse, _, err := conn.ServerlessInstances.Get(context.Background(), ids["project_id"], ids["name"]) + serverlessResponse, _, err := acc.Conn().ServerlessInstances.Get(context.Background(), ids["project_id"], ids["name"]) if err == nil { *serverlessInstance = *serverlessResponse return nil } - return fmt.Errorf("serverless instance (%s) does not exist", ids["name"]) } } func testAccCheckMongoDBAtlasServerlessInstanceDestroy(state *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range state.RootModule().Resources { if rs.Type != "mongodbatlas_serverless_instance" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - serverlessInstance, _, err := conn.ServerlessInstances.Get(context.Background(), ids["project_id"], ids["name"]) + serverlessInstance, _, err := acc.Conn().ServerlessInstances.Get(context.Background(), ids["project_id"], ids["name"]) if err == nil && serverlessInstance != nil { return fmt.Errorf("serverless instance (%s) still exists", ids["name"]) } } - return nil } diff --git a/internal/service/streamconnection/resource_stream_connection_test.go b/internal/service/streamconnection/resource_stream_connection_test.go index bf3d6b3fe4..0e1d809472 100644 --- a/internal/service/streamconnection/resource_stream_connection_test.go +++ b/internal/service/streamconnection/resource_stream_connection_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -211,7 +210,6 @@ func checkStreamConnectionImportStateIDFunc(resourceName string) resource.Import func checkStreamConnectionExists() resource.TestCheckFunc { return func(s *terraform.State) error { - connV2 := acc.TestMongoDBClient.(*config.MongoDBClient).AtlasV2 for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_stream_connection" { continue @@ -219,7 +217,7 @@ func checkStreamConnectionExists() resource.TestCheckFunc { projectID := rs.Primary.Attributes["project_id"] instanceName := rs.Primary.Attributes["instance_name"] connectionName := rs.Primary.Attributes["connection_name"] - _, _, err := connV2.StreamsApi.GetStreamConnection(context.Background(), projectID, instanceName, connectionName).Execute() + _, _, err := acc.ConnV2().StreamsApi.GetStreamConnection(context.Background(), projectID, instanceName, connectionName).Execute() if err != nil { return fmt.Errorf("stream connection (%s:%s:%s) does not exist", projectID, instanceName, connectionName) } @@ -232,7 +230,6 @@ func CheckDestroyStreamConnection(state *terraform.State) error { if instanceDestroyedErr := acc.CheckDestroyStreamInstance(state); instanceDestroyedErr != nil { return instanceDestroyedErr } - connV2 := acc.TestMongoDBClient.(*config.MongoDBClient).AtlasV2 for _, rs := range state.RootModule().Resources { if rs.Type != "mongodbatlas_stream_connection" { continue @@ -240,7 +237,7 @@ func CheckDestroyStreamConnection(state *terraform.State) error { projectID := rs.Primary.Attributes["project_id"] instanceName := rs.Primary.Attributes["instance_name"] connectionName := rs.Primary.Attributes["connection_name"] - _, _, err := connV2.StreamsApi.GetStreamConnection(context.Background(), projectID, instanceName, connectionName).Execute() + _, _, err := acc.ConnV2().StreamsApi.GetStreamConnection(context.Background(), projectID, instanceName, connectionName).Execute() if err == nil { return fmt.Errorf("stream connection (%s:%s:%s) still exists", projectID, instanceName, connectionName) } diff --git a/internal/service/streaminstance/resource_stream_instance_test.go b/internal/service/streaminstance/resource_stream_instance_test.go index 131ef24435..de964af2ff 100644 --- a/internal/service/streaminstance/resource_stream_instance_test.go +++ b/internal/service/streaminstance/resource_stream_instance_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -64,10 +63,9 @@ func checkStreamInstanceImportStateIDFunc(resourceName string) resource.ImportSt func checkSearchInstanceExists() resource.TestCheckFunc { return func(s *terraform.State) error { - connV2 := acc.TestMongoDBClient.(*config.MongoDBClient).AtlasV2 for _, rs := range s.RootModule().Resources { if rs.Type == "mongodbatlas_stream_instance" { - _, _, err := connV2.StreamsApi.GetStreamInstance(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["instance_name"]).Execute() + _, _, err := acc.ConnV2().StreamsApi.GetStreamInstance(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["instance_name"]).Execute() if err != nil { return fmt.Errorf("stream instance (%s:%s) does not exist", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["instance_name"]) } diff --git a/internal/service/teams/resource_teams_test.go b/internal/service/teams/resource_teams_test.go index 24b5fa7294..e618bb9026 100644 --- a/internal/service/teams/resource_teams_test.go +++ b/internal/service/teams/resource_teams_test.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -116,31 +115,23 @@ func TestAccConfigRSTeam_importBasic(t *testing.T) { func testAccCheckMongoDBAtlasTeamExists(resourceName string, team *matlas.Team) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - ids := conversion.DecodeStateID(rs.Primary.ID) - orgID := ids["org_id"] id := ids["id"] - if orgID == "" && id == "" { return fmt.Errorf("no ID is set") } - log.Printf("[DEBUG] orgID: %s", orgID) log.Printf("[DEBUG] teamID: %s", id) - - teamResp, _, err := conn.Teams.Get(context.Background(), orgID, id) + teamResp, _, err := acc.Conn().Teams.Get(context.Background(), orgID, id) if err == nil { *team = *teamResp return nil } - return fmt.Errorf("team(%s) does not exist", id) } } @@ -150,7 +141,6 @@ func testAccCheckMongoDBAtlasTeamAttributes(team *matlas.Team, name string) reso if team.Name != name { return fmt.Errorf("bad name: %s", team.Name) } - return nil } } @@ -161,7 +151,6 @@ func testAccCheckMongoDBAtlasTeamStateIDFunc(resourceName string) resource.Impor if !ok { return "", fmt.Errorf("not found: %s", resourceName) } - return fmt.Sprintf("%s-%s", rs.Primary.Attributes["org_id"], rs.Primary.Attributes["team_id"]), nil } } diff --git a/internal/service/thirdpartyintegration/data_source_third_party_integration_test.go b/internal/service/thirdpartyintegration/data_source_third_party_integration_test.go index 50146c1a55..05da1abfb7 100644 --- a/internal/service/thirdpartyintegration/data_source_third_party_integration_test.go +++ b/internal/service/thirdpartyintegration/data_source_third_party_integration_test.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -249,24 +248,18 @@ func testGenString(length int, charSet string) string { func testAccCheckThirdPartyIntegrationExists(resourceName string, integration *matlas.ThirdPartyIntegration) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.Attributes["project_id"] == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - if integrationResponse, _, err := conn.Integrations.Get(context.Background(), ids["project_id"], ids["type"]); err == nil { + if integrationResponse, _, err := acc.Conn().Integrations.Get(context.Background(), ids["project_id"], ids["type"]); err == nil { *integration = *integrationResponse return nil } - return fmt.Errorf("third party integration (%s) does not exist", ids["project_id"]) } } diff --git a/internal/service/thirdpartyintegration/resource_third_party_integration_test.go b/internal/service/thirdpartyintegration/resource_third_party_integration_test.go index 8eea01b8c5..2546b146b5 100644 --- a/internal/service/thirdpartyintegration/resource_third_party_integration_test.go +++ b/internal/service/thirdpartyintegration/resource_third_party_integration_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -157,20 +156,16 @@ func TestAccConfigRSThirdPartyIntegration_updateBasic(t *testing.T) { } func testAccCheckMongoDBAtlasThirdPartyIntegrationDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_third_party_integration" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - _, _, err := conn.Integrations.Get(context.Background(), ids["project_id"], ids["type"]) - + _, _, err := acc.Conn().Integrations.Get(context.Background(), ids["project_id"], ids["type"]) if err == nil { return fmt.Errorf("third party integration service (%s) still exists", ids["type"]) } } - return nil } diff --git a/internal/service/x509authenticationdatabaseuser/resource_x509_authentication_database_user_test.go b/internal/service/x509authenticationdatabaseuser/resource_x509_authentication_database_user_test.go index 9194b026d5..2bd19af8ee 100644 --- a/internal/service/x509authenticationdatabaseuser/resource_x509_authentication_database_user_test.go +++ b/internal/service/x509authenticationdatabaseuser/resource_x509_authentication_database_user_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/spf13/cast" ) @@ -169,59 +168,44 @@ func testAccCheckMongoDBAtlasX509AuthDBUserImportStateIDFuncBasic(resourceName s func testAccCheckMongoDBAtlasX509AuthDBUserExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.Attributes["project_id"] == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) if ids["current_certificate"] != "" { - if _, _, err := conn.X509AuthDBUsers.GetUserCertificates(context.Background(), ids["project_id"], ids["username"], nil); err == nil { + if _, _, err := acc.Conn().X509AuthDBUsers.GetUserCertificates(context.Background(), ids["project_id"], ids["username"], nil); err == nil { return nil } - return fmt.Errorf("the X509 Authentication Database User(%s) does not exist in the project(%s)", ids["username"], ids["project_id"]) } - - if _, _, err := conn.X509AuthDBUsers.GetCurrentX509Conf(context.Background(), ids["project_id"]); err == nil { + if _, _, err := acc.Conn().X509AuthDBUsers.GetCurrentX509Conf(context.Background(), ids["project_id"]); err == nil { return nil } - return fmt.Errorf("the Customer X509 Authentication does not exist in the project(%s)", ids["project_id"]) } } func testAccCheckMongoDBAtlasX509AuthDBUserDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_x509_authentication_database_user" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - if ids["current_certificate"] != "" { - _, _, err := conn.X509AuthDBUsers.GetUserCertificates(context.Background(), ids["project_id"], ids["username"], nil) + _, _, err := acc.Conn().X509AuthDBUsers.GetUserCertificates(context.Background(), ids["project_id"], ids["username"], nil) if err == nil { - /* - There is no way to remove one user certificate so until this comes it will keep in this way - */ + // There is no way to remove one user certificate so until this comes it will keep in this way return nil } } - - if _, _, err := conn.X509AuthDBUsers.GetCurrentX509Conf(context.Background(), ids["project_id"]); err == nil { + if _, _, err := acc.Conn().X509AuthDBUsers.GetCurrentX509Conf(context.Background(), ids["project_id"]); err == nil { return nil } } - return nil } diff --git a/internal/testutil/acc/advanced_cluster.go b/internal/testutil/acc/advanced_cluster.go index d38eb73a60..35d30d77af 100644 --- a/internal/testutil/acc/advanced_cluster.go +++ b/internal/testutil/acc/advanced_cluster.go @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) var ( @@ -27,34 +26,28 @@ var ( ) func CheckClusterDestroy(s *terraform.State) error { - conn := TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_cluster" { continue } // Try to find the cluster - _, _, err := conn.Clusters.Get(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"]) - + _, _, err := Conn().Clusters.Get(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"]) if err == nil { return fmt.Errorf("cluster (%s:%s) still exists", rs.Primary.Attributes["cluster_name"], rs.Primary.ID) } } - return nil } func CheckDestroyTeamAdvancedCluster(s *terraform.State) error { - conn := TestMongoDBClient.(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_advanced_cluster" { continue } // Try to find the cluster - _, _, err := conn.AdvancedClusters.Get(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"]) + _, _, err := Conn().AdvancedClusters.Get(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["cluster_name"]) if err == nil { return fmt.Errorf("cluster (%s:%s) still exists", rs.Primary.Attributes["cluster_name"], rs.Primary.ID) diff --git a/internal/testutil/acc/database_user.go b/internal/testutil/acc/database_user.go index 80ef8b4d04..33c1e4325e 100644 --- a/internal/testutil/acc/database_user.go +++ b/internal/testutil/acc/database_user.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/databaseuser" "go.mongodb.org/atlas-sdk/v20231115004/admin" @@ -15,21 +14,16 @@ import ( func CheckDatabaseUserExists(resourceName string, dbUser *admin.CloudDatabaseUser) resource.TestCheckFunc { return func(s *terraform.State) error { - connV2 := TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.Attributes["project_id"] == "" { return fmt.Errorf("no project_id is set") } - if rs.Primary.Attributes["auth_database_name"] == "" { return fmt.Errorf("no auth_database_name is set") } - if rs.Primary.Attributes["username"] == "" { return fmt.Errorf("no username is set") } @@ -38,7 +32,7 @@ func CheckDatabaseUserExists(resourceName string, dbUser *admin.CloudDatabaseUse projectID := rs.Primary.Attributes["project_id"] username := rs.Primary.Attributes["username"] - if dbUserResp, _, err := connV2.DatabaseUsersApi.GetDatabaseUser(context.Background(), projectID, authDB, username).Execute(); err == nil { + if dbUserResp, _, err := ConnV2().DatabaseUsersApi.GetDatabaseUser(context.Background(), projectID, authDB, username).Execute(); err == nil { *dbUser = *dbUserResp return nil } @@ -59,8 +53,6 @@ func CheckDatabaseUserAttributes(dbUser *admin.CloudDatabaseUser, username strin } func CheckDestroyDatabaseUser(s *terraform.State) error { - connV2 := TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_database_user" { continue @@ -71,7 +63,7 @@ func CheckDestroyDatabaseUser(s *terraform.State) error { continue } // Try to find the database user - _, _, err = connV2.DatabaseUsersApi.GetDatabaseUser(context.Background(), projectID, authDatabaseName, username).Execute() + _, _, err = ConnV2().DatabaseUsersApi.GetDatabaseUser(context.Background(), projectID, authDatabaseName, username).Execute() if err == nil { return fmt.Errorf("database user (%s) still exists", projectID) } diff --git a/internal/testutil/acc/factory.go b/internal/testutil/acc/factory.go index ebc607f0f9..a28c5dfcaf 100644 --- a/internal/testutil/acc/factory.go +++ b/internal/testutil/acc/factory.go @@ -4,10 +4,12 @@ import ( "context" "os" + matlas "go.mongodb.org/atlas/mongodbatlas" + "github.com/hashicorp/terraform-plugin-go/tfprotov6" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/provider" + "go.mongodb.org/atlas-sdk/v20231115004/admin" ) const ( @@ -15,29 +17,32 @@ const ( ProviderNameMongoDBAtlas = "mongodbatlas" ) +// TestAccProviderV6Factories is used in all tests for ProtoV6ProviderFactories. var TestAccProviderV6Factories map[string]func() (tfprotov6.ProviderServer, error) -// TestAccProviderSdkV2 is only being used in tests obtaining client: .Meta().(*MongoDBClient) -// this provider instance has to be passed into mux server factory for its configure method to be invoked -var TestAccProviderSdkV2 *schema.Provider +// MongoDBClient is used to configure client required for Framework-based acceptance tests. +var MongoDBClient *config.MongoDBClient -// TestMongoDBClient is used to configure client required for Framework-based acceptance tests -var TestMongoDBClient any +func Conn() *matlas.Client { + return MongoDBClient.Atlas +} -func init() { - TestAccProviderSdkV2 = provider.NewSdkV2Provider() +func ConnV2() *admin.APIClient { + return MongoDBClient.AtlasV2 +} +func init() { TestAccProviderV6Factories = map[string]func() (tfprotov6.ProviderServer, error){ ProviderNameMongoDBAtlas: func() (tfprotov6.ProviderServer, error) { - return provider.MuxedProviderFactoryFn(TestAccProviderSdkV2)(), nil + return provider.MuxedProviderFactory()(), nil }, } - cfg := config.Config{ PublicKey: os.Getenv("MONGODB_ATLAS_PUBLIC_KEY"), PrivateKey: os.Getenv("MONGODB_ATLAS_PRIVATE_KEY"), BaseURL: os.Getenv("MONGODB_ATLAS_BASE_URL"), RealmBaseURL: os.Getenv("MONGODB_REALM_BASE_URL"), } - TestMongoDBClient, _ = cfg.NewClient(context.Background()) + client, _ := cfg.NewClient(context.Background()) + MongoDBClient = client.(*config.MongoDBClient) } diff --git a/internal/testutil/acc/federated.go b/internal/testutil/acc/federated.go index 90b6dcb5a3..c8ed915420 100644 --- a/internal/testutil/acc/federated.go +++ b/internal/testutil/acc/federated.go @@ -6,23 +6,18 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) func CheckDestroyFederatedDatabaseInstance(s *terraform.State) error { - connV2 := TestAccProviderSdkV2.Meta().(*config.MongoDBClient).AtlasV2 - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_federated_database_instance" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - _, _, err := connV2.DataFederationApi.GetFederatedDatabase(context.Background(), ids["project_id"], ids["name"]).Execute() + _, _, err := ConnV2().DataFederationApi.GetFederatedDatabase(context.Background(), ids["project_id"], ids["name"]).Execute() if err == nil { return fmt.Errorf("federated database instance (%s) still exists", ids["project_id"]) } } - return nil } diff --git a/internal/testutil/acc/ldap.go b/internal/testutil/acc/ldap.go index f4f1d7e57c..9f5ed4b05b 100644 --- a/internal/testutil/acc/ldap.go +++ b/internal/testutil/acc/ldap.go @@ -5,22 +5,17 @@ import ( "fmt" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) func CheckDestroyLDAPConfiguration(s *terraform.State) error { - conn := TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_ldap_configuration" { continue } - - _, _, err := conn.LDAPConfigurations.Get(context.Background(), rs.Primary.ID) + _, _, err := Conn().LDAPConfigurations.Get(context.Background(), rs.Primary.ID) if err == nil { return fmt.Errorf("ldapConfiguration (%s) still exists", rs.Primary.ID) } } - return nil } diff --git a/internal/testutil/acc/network_peering.go b/internal/testutil/acc/network_peering.go index 6feade264a..be1f2f9cfc 100644 --- a/internal/testutil/acc/network_peering.go +++ b/internal/testutil/acc/network_peering.go @@ -6,24 +6,18 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) func CheckDestroyNetworkPeering(s *terraform.State) error { - conn := TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_network_peering" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - _, _, err := conn.Peers.Get(context.Background(), ids["project_id"], ids["peer_id"]) - + _, _, err := Conn().Peers.Get(context.Background(), ids["project_id"], ids["peer_id"]) if err == nil { return fmt.Errorf("peer (%s) still exists", ids["peer_id"]) } } - return nil } diff --git a/internal/testutil/acc/org.go b/internal/testutil/acc/org.go index 68a21a8c99..cb79f12409 100644 --- a/internal/testutil/acc/org.go +++ b/internal/testutil/acc/org.go @@ -6,28 +6,22 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) func CheckDestroyOrgInvitation(s *terraform.State) error { - conn := TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_invitations" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - orgID := ids["org_id"] invitationID := ids["invitation_id"] // Try to find the invitation - _, _, err := conn.Organizations.Invitation(context.Background(), orgID, invitationID) + _, _, err := Conn().Organizations.Invitation(context.Background(), orgID, invitationID) if err == nil { return fmt.Errorf("invitation (%s) still exists", invitationID) } } - return nil } diff --git a/internal/testutil/acc/project.go b/internal/testutil/acc/project.go index cb31bc2600..b189cf03fb 100644 --- a/internal/testutil/acc/project.go +++ b/internal/testutil/acc/project.go @@ -8,30 +8,23 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20231115004/admin" ) func CheckProjectExists(resourceName string, project *admin.Group) resource.TestCheckFunc { return func(s *terraform.State) error { - connV2 := TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - log.Printf("[DEBUG] projectID: %s", rs.Primary.ID) - - if projectResp, _, err := connV2.ProjectsApi.GetProjectByName(context.Background(), rs.Primary.Attributes["name"]).Execute(); err == nil { + if projectResp, _, err := ConnV2().ProjectsApi.GetProjectByName(context.Background(), rs.Primary.Attributes["name"]).Execute(); err == nil { *project = *projectResp return nil } - return fmt.Errorf("project (%s) does not exist", rs.Primary.ID) } } @@ -47,14 +40,12 @@ func CheckProjectAttributes(project *admin.Group, projectName string) resource.T } func CheckDestroyProject(s *terraform.State) error { - conn := TestMongoDBClient.(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_project" { continue } - projectRes, _, _ := conn.Projects.GetOneProjectByName(context.Background(), rs.Primary.ID) + projectRes, _, _ := Conn().Projects.GetOneProjectByName(context.Background(), rs.Primary.ID) if projectRes != nil { return fmt.Errorf("project (%s) still exists", rs.Primary.ID) } diff --git a/internal/testutil/acc/project_ip_acces_list.go b/internal/testutil/acc/project_ip_acces_list.go index 6c519dcb21..179f00207f 100644 --- a/internal/testutil/acc/project_ip_acces_list.go +++ b/internal/testutil/acc/project_ip_acces_list.go @@ -7,49 +7,37 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) func CheckProjectIPAccessListExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - connV2 := TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) } - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - ids := conversion.DecodeStateID(rs.Primary.ID) - - _, _, err := connV2.ProjectIPAccessListApi.GetProjectIpList(context.Background(), ids["project_id"], ids["entry"]).Execute() + _, _, err := ConnV2().ProjectIPAccessListApi.GetProjectIpList(context.Background(), ids["project_id"], ids["entry"]).Execute() if err != nil { return fmt.Errorf("project ip access list entry (%s) does not exist", ids["entry"]) } - return nil } } func CheckDestroyProjectIPAccessList(s *terraform.State) error { - connV2 := TestMongoDBClient.(*config.MongoDBClient).AtlasV2 - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_project_ip_access_list" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - _, _, err := connV2.ProjectIPAccessListApi.GetProjectIpList(context.Background(), ids["project_id"], ids["entry"]).Execute() + _, _, err := ConnV2().ProjectIPAccessListApi.GetProjectIpList(context.Background(), ids["project_id"], ids["entry"]).Execute() if err == nil { return fmt.Errorf("project ip access list entry (%s) still exists", ids["entry"]) } } - return nil } diff --git a/internal/testutil/acc/search_index.go b/internal/testutil/acc/search_index.go index 45e1a3e1dc..e082d93e89 100644 --- a/internal/testutil/acc/search_index.go +++ b/internal/testutil/acc/search_index.go @@ -7,27 +7,21 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) func CheckDestroySearchIndex(state *terraform.State) error { if os.Getenv("MONGODB_ATLAS_CLUSTER_NAME") != "" { return nil } - conn := TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range state.RootModule().Resources { if rs.Type != "mongodbatlas_search_index" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - - searchIndex, _, err := conn.Search.GetIndex(context.Background(), ids["project_id"], ids["cluster_name"], ids["index_id"]) + searchIndex, _, err := Conn().Search.GetIndex(context.Background(), ids["project_id"], ids["cluster_name"], ids["index_id"]) if err == nil && searchIndex != nil { return fmt.Errorf("index id (%s) still exists", ids["index_id"]) } } - return nil } diff --git a/internal/testutil/acc/stream_instance.go b/internal/testutil/acc/stream_instance.go index ea4672c0a1..1589bece46 100644 --- a/internal/testutil/acc/stream_instance.go +++ b/internal/testutil/acc/stream_instance.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) func StreamInstanceConfig(orgID, projectName, instanceName, region, cloudProvider string) string { @@ -30,10 +29,9 @@ func CheckDestroyStreamInstance(state *terraform.State) error { if projectDestroyedErr := CheckDestroyProject(state); projectDestroyedErr != nil { return projectDestroyedErr } - connV2 := TestMongoDBClient.(*config.MongoDBClient).AtlasV2 for _, rs := range state.RootModule().Resources { if rs.Type == "mongodbatlas_stream_instance" { - _, _, err := connV2.StreamsApi.GetStreamInstance(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["instance_name"]).Execute() + _, _, err := ConnV2().StreamsApi.GetStreamInstance(context.Background(), rs.Primary.Attributes["project_id"], rs.Primary.Attributes["instance_name"]).Execute() if err == nil { return fmt.Errorf("stream instance (%s:%s) still exists", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["instance_name"]) } diff --git a/internal/testutil/acc/team.go b/internal/testutil/acc/team.go index 3ea63510f6..9b666a43cf 100644 --- a/internal/testutil/acc/team.go +++ b/internal/testutil/acc/team.go @@ -6,24 +6,19 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) func CheckDestroyTeam(s *terraform.State) error { - conn := TestMongoDBClient.(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_teams" { continue } - ids := conversion.DecodeStateID(rs.Primary.ID) - orgID := ids["org_id"] id := ids["id"] // Try to find the team - _, _, err := conn.Teams.Get(context.Background(), orgID, id) + _, _, err := Conn().Teams.Get(context.Background(), orgID, id) if err == nil { return fmt.Errorf("team (%s) still exists", id) } diff --git a/main.go b/main.go index 3795003820..04ba6bcda9 100644 --- a/main.go +++ b/main.go @@ -10,12 +10,10 @@ import ( func main() { var debugMode bool - flag.BoolVar(&debugMode, "debug", false, "set to true to run the provider with support for debuggers like delve") flag.Parse() var serveOpts []tf6server.ServeOpt - if debugMode { serveOpts = append(serveOpts, tf6server.WithManagedDebug()) }