From f562923bad8e5eec21f96593ed6ed9a7eabe81ef Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 4 Dec 2023 15:19:42 +0100 Subject: [PATCH] feat: Migrates some resources to new file structure (#1702) * cloud_provider_access * cloud_provider_access GH action * federated_database_instance * federated_query_limit * federated_settings_identity_provider * federated_settings_org_config and federated_settings_org_role_mapping * GH action --- .github/workflows/acceptance-tests.yml | 7 +-- internal/provider/provider_sdk2.go | 48 +++++++++++-------- .../data_source_cloud_provider_access.go | 4 +- ...data_source_cloud_provider_access_setup.go | 4 +- .../resource_cloud_provider_access.go | 4 +- ...rce_cloud_provider_access_authorization.go | 4 +- ...loud_provider_access_authorization_test.go | 2 +- .../resource_cloud_provider_access_setup.go | 4 +- ...source_cloud_provider_access_setup_test.go | 2 +- .../resource_cloud_provider_access_test.go | 8 ++-- ...data_source_federated_database_instance.go | 4 +- ...source_federated_database_instance_test.go | 6 +-- ...ata_source_federated_database_instances.go | 4 +- ...ource_federated_database_instances_test.go | 4 +- .../resource_federated_database_instance.go | 4 +- ...source_federated_database_instance_test.go | 28 ++--------- .../data_source_federated_query_limit.go | 4 +- .../data_source_federated_query_limit_test.go | 2 +- .../data_source_federated_query_limits.go | 4 +- ...data_source_federated_query_limits_test.go | 2 +- .../resource_federated_query_limit.go | 4 +- .../resource_federated_query_limit_test.go | 2 +- ...ce_federated_settings_identity_provider.go | 4 +- ...derated_settings_identity_provider_test.go | 2 +- ...e_federated_settings_identity_providers.go | 18 +++---- ...erated_settings_identity_providers_test.go | 2 +- ...ce_federated_settings_identity_provider.go | 4 +- ...derated_settings_identity_provider_test.go | 2 +- .../data_source_federated_settings.go | 4 +- ...source_federated_settings_connected_org.go | 9 ++-- ...e_federated_settings_connected_org_test.go | 2 +- ...ource_federated_settings_connected_orgs.go | 11 +++-- ..._federated_settings_connected_orgs_test.go | 2 +- .../data_source_federated_settings_test.go | 2 +- ...source_federated_settings_connected_org.go | 4 +- ...e_federated_settings_connected_org_test.go | 2 +- ...rce_federated_settings_org_role_mapping.go | 7 +-- ...ederated_settings_org_role_mapping_test.go | 2 +- ...ce_federated_settings_org_role_mappings.go | 7 +-- ...derated_settings_org_role_mappings_test.go | 2 +- ...rce_federated_settings_org_role_mapping.go | 4 +- ...ederated_settings_org_role_mapping_test.go | 2 +- internal/testutil/acc/federated.go | 28 +++++++++++ .../resource_online_archive_migration_test.go | 2 +- 44 files changed, 146 insertions(+), 131 deletions(-) rename {mongodbatlas => internal/service/cloudprovideraccess}/data_source_cloud_provider_access.go (98%) rename {mongodbatlas => internal/service/cloudprovideraccess}/data_source_cloud_provider_access_setup.go (96%) rename {mongodbatlas => internal/service/cloudprovideraccess}/resource_cloud_provider_access.go (99%) rename {mongodbatlas => internal/service/cloudprovideraccess}/resource_cloud_provider_access_authorization.go (99%) rename {mongodbatlas => internal/service/cloudprovideraccess}/resource_cloud_provider_access_authorization_test.go (99%) rename {mongodbatlas => internal/service/cloudprovideraccess}/resource_cloud_provider_access_setup.go (98%) rename {mongodbatlas => internal/service/cloudprovideraccess}/resource_cloud_provider_access_setup_test.go (99%) rename {mongodbatlas => internal/service/cloudprovideraccess}/resource_cloud_provider_access_test.go (95%) rename {mongodbatlas => internal/service/federateddatabaseinstance}/data_source_federated_database_instance.go (99%) rename {mongodbatlas => internal/service/federateddatabaseinstance}/data_source_federated_database_instance_test.go (98%) rename {mongodbatlas => internal/service/federateddatabaseinstance}/data_source_federated_database_instances.go (98%) rename {mongodbatlas => internal/service/federateddatabaseinstance}/data_source_federated_database_instances_test.go (98%) rename {mongodbatlas => internal/service/federateddatabaseinstance}/resource_federated_database_instance.go (99%) rename {mongodbatlas => internal/service/federateddatabaseinstance}/resource_federated_database_instance_test.go (94%) rename {mongodbatlas => internal/service/federatedquerylimit}/data_source_federated_query_limit.go (96%) rename {mongodbatlas => internal/service/federatedquerylimit}/data_source_federated_query_limit_test.go (99%) rename {mongodbatlas => internal/service/federatedquerylimit}/data_source_federated_query_limits.go (96%) rename {mongodbatlas => internal/service/federatedquerylimit}/data_source_federated_query_limits_test.go (99%) rename {mongodbatlas => internal/service/federatedquerylimit}/resource_federated_query_limit.go (98%) rename {mongodbatlas => internal/service/federatedquerylimit}/resource_federated_query_limit_test.go (99%) rename {mongodbatlas => internal/service/federatedsettingsidentityprovider}/data_source_federated_settings_identity_provider.go (98%) rename {mongodbatlas => internal/service/federatedsettingsidentityprovider}/data_source_federated_settings_identity_provider_test.go (97%) rename {mongodbatlas => internal/service/federatedsettingsidentityprovider}/data_source_federated_settings_identity_providers.go (95%) rename {mongodbatlas => internal/service/federatedsettingsidentityprovider}/data_source_federated_settings_identity_providers_test.go (98%) rename {mongodbatlas => internal/service/federatedsettingsidentityprovider}/resource_federated_settings_identity_provider.go (99%) rename {mongodbatlas => internal/service/federatedsettingsidentityprovider}/resource_federated_settings_identity_provider_test.go (99%) rename {mongodbatlas => internal/service/federatedsettingsorgconfig}/data_source_federated_settings.go (97%) rename mongodbatlas/data_source_federated_settings_connected_organization.go => internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_org.go (91%) rename mongodbatlas/data_source_federated_settings_connected_organization_test.go => internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_org_test.go (98%) rename mongodbatlas/data_source_federated_settings_connected_organizations.go => internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_orgs.go (90%) rename mongodbatlas/data_source_federated_settings_connected_organizations_test.go => internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_orgs_test.go (98%) rename {mongodbatlas => internal/service/federatedsettingsorgconfig}/data_source_federated_settings_test.go (98%) rename mongodbatlas/resource_federated_settings_connected_organization.go => internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org.go (98%) rename mongodbatlas/resource_federated_settings_connected_organization_test.go => internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org_test.go (99%) rename mongodbatlas/data_source_federated_settings_organization_role_mapping.go => internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mapping.go (88%) rename mongodbatlas/data_source_federated_settings_organization_role_mapping_test.go => internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mapping_test.go (97%) rename mongodbatlas/data_source_federated_settings_organization_role_mappings.go => internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mappings.go (91%) rename mongodbatlas/data_source_federated_settings_organization_role_mappings_test.go => internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mappings_test.go (98%) rename mongodbatlas/resource_federated_settings_organization_role_mapping.go => internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping.go (99%) rename mongodbatlas/resource_federated_settings_organization_role_mapping_test.go => internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping_test.go (99%) create mode 100644 internal/testutil/acc/federated.go diff --git a/.github/workflows/acceptance-tests.yml b/.github/workflows/acceptance-tests.yml index 0d7ac38c72..ce3788483e 100644 --- a/.github/workflows/acceptance-tests.yml +++ b/.github/workflows/acceptance-tests.yml @@ -89,7 +89,7 @@ jobs: - 'mongodbatlas/**_privatelink**.go' - 'mongodbatlas/**_private_endpoint**.go' federation: - - 'mongodbatlas/**_federated_database_instance**.go' + - 'internal/service/federateddatabaseinstance/*.go' config: - 'internal/service/alertconfiguration/*.go' - 'internal/service/atlasuser/*.go' @@ -97,8 +97,7 @@ jobs: - 'internal/service/projectapikey/*.go' - 'mongodbatlas/data_source_accesslist_api_key*.go' - 'mongodbatlas/data_source_api_key*.go' - - 'mongodbatlas/data_source_cloud_provider_access_setup*.go' - - 'mongodbatlas/data_source_cloud_provider_access*.go' + - 'internal/service/cloudprovideraccess/*.go' - 'mongodbatlas/data_source_custom_db_role*.go' - 'mongodbatlas/data_source_custom_dns_configuration_cluster_aws*.go' - 'mongodbatlas/data_source_maintenance_window*.go' @@ -108,8 +107,6 @@ jobs: - 'mongodbatlas/data_source_team*.go' - 'mongodbatlas/data_source_third_party_integration*.go' - 'mongodbatlas/resource_api_key*.go' - - 'mongodbatlas/resource_cloud_provider_access_setup*.go' - - 'mongodbatlas/resource_cloud_provider_access*.go' - 'mongodbatlas/resource_custom_db_role*.go' - 'mongodbatlas/resource_custom_dns_configuration_cluster_aws*.go' - 'mongodbatlas/resource_maintenance_window*.go' diff --git a/internal/provider/provider_sdk2.go b/internal/provider/provider_sdk2.go index c9dd77b65c..6101e825b4 100644 --- a/internal/provider/provider_sdk2.go +++ b/internal/provider/provider_sdk2.go @@ -20,7 +20,13 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudbackupsnapshotexportbucket" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudbackupsnapshotexportjob" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudbackupsnapshotrestorejob" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudprovideraccess" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cluster" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federateddatabaseinstance" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedquerylimit" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsidentityprovider" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsorgconfig" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsorgrolemapping" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/projectapikey" "github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas" "github.com/mwielbut/pointy" @@ -139,8 +145,8 @@ func getDataSourcesMap() map[string]*schema.Resource { "mongodbatlas_privatelink_endpoints_service_serverless": mongodbatlas.DataSourcePrivateLinkEndpointsServiceServerless(), "mongodbatlas_third_party_integration": mongodbatlas.DataSourceThirdPartyIntegration(), "mongodbatlas_third_party_integrations": mongodbatlas.DataSourceThirdPartyIntegrations(), - "mongodbatlas_cloud_provider_access": mongodbatlas.DataSourceCloudProviderAccessList(), - "mongodbatlas_cloud_provider_access_setup": mongodbatlas.DataSourceCloudProviderAccessSetup(), + "mongodbatlas_cloud_provider_access": cloudprovideraccess.DataSource(), + "mongodbatlas_cloud_provider_access_setup": cloudprovideraccess.DataSourceSetup(), "mongodbatlas_custom_dns_configuration_cluster_aws": mongodbatlas.DataSourceCustomDNSConfigurationAWS(), "mongodbatlas_online_archive": mongodbatlas.DataSourceOnlineArchive(), "mongodbatlas_online_archives": mongodbatlas.DataSourceOnlineArchives(), @@ -168,17 +174,17 @@ func getDataSourcesMap() map[string]*schema.Resource { "mongodbatlas_cloud_backup_snapshot_export_jobs": cloudbackupsnapshotexportjob.PluralDataSource(), "mongodbatlas_cloud_backup_snapshot_restore_job": cloudbackupsnapshotrestorejob.DataSource(), "mongodbatlas_cloud_backup_snapshot_restore_jobs": cloudbackupsnapshotrestorejob.PluralDataSource(), - "mongodbatlas_federated_settings": mongodbatlas.DataSourceFederatedSettings(), - "mongodbatlas_federated_settings_identity_provider": mongodbatlas.DataSourceFederatedSettingsIdentityProvider(), - "mongodbatlas_federated_settings_identity_providers": mongodbatlas.DataSourceFederatedSettingsIdentityProviders(), - "mongodbatlas_federated_settings_org_config": mongodbatlas.DataSourceFederatedSettingsOrganizationConfig(), - "mongodbatlas_federated_settings_org_configs": mongodbatlas.DataSourceFederatedSettingsOrganizationConfigs(), - "mongodbatlas_federated_settings_org_role_mapping": mongodbatlas.DataSourceFederatedSettingsOrganizationRoleMapping(), - "mongodbatlas_federated_settings_org_role_mappings": mongodbatlas.DataSourceFederatedSettingsOrganizationRoleMappings(), - "mongodbatlas_federated_database_instance": mongodbatlas.DataSourceFederatedDatabaseInstance(), - "mongodbatlas_federated_database_instances": mongodbatlas.DataSourceFederatedDatabaseInstances(), - "mongodbatlas_federated_query_limit": mongodbatlas.DataSourceFederatedDatabaseQueryLimit(), - "mongodbatlas_federated_query_limits": mongodbatlas.DataSourceFederatedDatabaseQueryLimits(), + "mongodbatlas_federated_settings_identity_provider": federatedsettingsidentityprovider.DataSource(), + "mongodbatlas_federated_settings_identity_providers": federatedsettingsidentityprovider.PluralDataSource(), + "mongodbatlas_federated_settings": federatedsettingsorgconfig.DataSourceSettings(), + "mongodbatlas_federated_settings_org_config": federatedsettingsorgconfig.DataSource(), + "mongodbatlas_federated_settings_org_configs": federatedsettingsorgconfig.PluralDataSource(), + "mongodbatlas_federated_settings_org_role_mapping": federatedsettingsorgrolemapping.DataSource(), + "mongodbatlas_federated_settings_org_role_mappings": federatedsettingsorgrolemapping.PluralDataSource(), + "mongodbatlas_federated_database_instance": federateddatabaseinstance.DataSource(), + "mongodbatlas_federated_database_instances": federateddatabaseinstance.PluralDataSource(), + "mongodbatlas_federated_query_limit": federatedquerylimit.DataSource(), + "mongodbatlas_federated_query_limits": federatedquerylimit.PluralDataSource(), "mongodbatlas_serverless_instance": mongodbatlas.DataSourceServerlessInstance(), "mongodbatlas_serverless_instances": mongodbatlas.DataSourceServerlessInstances(), "mongodbatlas_cluster_outage_simulation": mongodbatlas.DataSourceClusterOutageSimulation(), @@ -213,13 +219,13 @@ func getResourcesMap() map[string]*schema.Resource { "mongodbatlas_privatelink_endpoint_service": mongodbatlas.ResourcePrivateEndpointServiceLink(), "mongodbatlas_privatelink_endpoint_service_serverless": mongodbatlas.ResourcePrivateLinkEndpointServiceServerless(), "mongodbatlas_third_party_integration": mongodbatlas.ResourceThirdPartyIntegration(), - "mongodbatlas_cloud_provider_access": mongodbatlas.ResourceCloudProviderAccess(), "mongodbatlas_online_archive": mongodbatlas.ResourceOnlineArchive(), "mongodbatlas_custom_dns_configuration_cluster_aws": mongodbatlas.ResourceCustomDNSConfiguration(), "mongodbatlas_ldap_configuration": mongodbatlas.ResourceLDAPConfiguration(), "mongodbatlas_ldap_verify": mongodbatlas.ResourceLDAPVerify(), - "mongodbatlas_cloud_provider_access_setup": mongodbatlas.ResourceCloudProviderAccessSetup(), - "mongodbatlas_cloud_provider_access_authorization": mongodbatlas.ResourceCloudProviderAccessAuthorization(), + "mongodbatlas_cloud_provider_access": cloudprovideraccess.Resource(), + "mongodbatlas_cloud_provider_access_setup": cloudprovideraccess.ResourceSetup(), + "mongodbatlas_cloud_provider_access_authorization": cloudprovideraccess.ResourceAuthorization(), "mongodbatlas_search_index": mongodbatlas.ResourceSearchIndex(), "mongodbatlas_data_lake_pipeline": mongodbatlas.ResourceDataLakePipeline(), "mongodbatlas_event_trigger": mongodbatlas.ResourceEventTriggers(), @@ -232,11 +238,11 @@ func getResourcesMap() map[string]*schema.Resource { "mongodbatlas_cloud_backup_snapshot_export_bucket": cloudbackupsnapshotexportbucket.Resource(), "mongodbatlas_cloud_backup_snapshot_export_job": cloudbackupsnapshotexportjob.Resource(), "mongodbatlas_cloud_backup_snapshot_restore_job": cloudbackupsnapshotrestorejob.Resource(), - "mongodbatlas_federated_settings_org_config": mongodbatlas.ResourceFederatedSettingsOrganizationConfig(), - "mongodbatlas_federated_settings_org_role_mapping": mongodbatlas.ResourceFederatedSettingsOrganizationRoleMapping(), - "mongodbatlas_federated_settings_identity_provider": mongodbatlas.ResourceFederatedSettingsIdentityProvider(), - "mongodbatlas_federated_database_instance": mongodbatlas.ResourceFederatedDatabaseInstance(), - "mongodbatlas_federated_query_limit": mongodbatlas.ResourceFederatedDatabaseQueryLimit(), + "mongodbatlas_federated_settings_org_config": federatedsettingsorgconfig.Resource(), + "mongodbatlas_federated_settings_org_role_mapping": federatedsettingsorgrolemapping.Resource(), + "mongodbatlas_federated_settings_identity_provider": federatedsettingsidentityprovider.Resource(), + "mongodbatlas_federated_database_instance": federateddatabaseinstance.Resource(), + "mongodbatlas_federated_query_limit": federatedquerylimit.Resource(), "mongodbatlas_serverless_instance": mongodbatlas.ResourceServerlessInstance(), "mongodbatlas_cluster_outage_simulation": mongodbatlas.ResourceClusterOutageSimulation(), } diff --git a/mongodbatlas/data_source_cloud_provider_access.go b/internal/service/cloudprovideraccess/data_source_cloud_provider_access.go similarity index 98% rename from mongodbatlas/data_source_cloud_provider_access.go rename to internal/service/cloudprovideraccess/data_source_cloud_provider_access.go index 88ccb3721e..ab726bf487 100644 --- a/mongodbatlas/data_source_cloud_provider_access.go +++ b/internal/service/cloudprovideraccess/data_source_cloud_provider_access.go @@ -1,4 +1,4 @@ -package mongodbatlas +package cloudprovideraccess import ( "context" @@ -12,7 +12,7 @@ import ( matlas "go.mongodb.org/atlas/mongodbatlas" ) -func DataSourceCloudProviderAccessList() *schema.Resource { +func DataSource() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasCloudProviderAccessRead, DeprecationMessage: fmt.Sprintf(constant.DeprecationResourceByDateWithReplacement, "v1.14.0", "mongodbatlas_cloud_provider_access_setup"), diff --git a/mongodbatlas/data_source_cloud_provider_access_setup.go b/internal/service/cloudprovideraccess/data_source_cloud_provider_access_setup.go similarity index 96% rename from mongodbatlas/data_source_cloud_provider_access_setup.go rename to internal/service/cloudprovideraccess/data_source_cloud_provider_access_setup.go index e0fc5ee9e1..777dae8c67 100644 --- a/mongodbatlas/data_source_cloud_provider_access_setup.go +++ b/internal/service/cloudprovideraccess/data_source_cloud_provider_access_setup.go @@ -1,4 +1,4 @@ -package mongodbatlas +package cloudprovideraccess import ( "context" @@ -11,7 +11,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) -func DataSourceCloudProviderAccessSetup() *schema.Resource { +func DataSourceSetup() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasCloudProviderAccessSetupRead, Schema: map[string]*schema.Schema{ diff --git a/mongodbatlas/resource_cloud_provider_access.go b/internal/service/cloudprovideraccess/resource_cloud_provider_access.go similarity index 99% rename from mongodbatlas/resource_cloud_provider_access.go rename to internal/service/cloudprovideraccess/resource_cloud_provider_access.go index 64cd72ca78..1568a2a89b 100644 --- a/mongodbatlas/resource_cloud_provider_access.go +++ b/internal/service/cloudprovideraccess/resource_cloud_provider_access.go @@ -1,4 +1,4 @@ -package mongodbatlas +package cloudprovideraccess import ( "context" @@ -23,7 +23,7 @@ const ( ErrorCloudProviderGetRead = "error reading cloud provider access %s" ) -func ResourceCloudProviderAccess() *schema.Resource { +func Resource() *schema.Resource { return &schema.Resource{ CreateContext: resourceMongoDBAtlasCloudProviderAccessCreate, ReadContext: resourceMongoDBAtlasCloudProviderAccessRead, diff --git a/mongodbatlas/resource_cloud_provider_access_authorization.go b/internal/service/cloudprovideraccess/resource_cloud_provider_access_authorization.go similarity index 99% rename from mongodbatlas/resource_cloud_provider_access_authorization.go rename to internal/service/cloudprovideraccess/resource_cloud_provider_access_authorization.go index bf672dc020..1e03af0871 100644 --- a/mongodbatlas/resource_cloud_provider_access_authorization.go +++ b/internal/service/cloudprovideraccess/resource_cloud_provider_access_authorization.go @@ -1,4 +1,4 @@ -package mongodbatlas +package cloudprovideraccess import ( "context" @@ -19,7 +19,7 @@ import ( A cloud provider access authorization */ -func ResourceCloudProviderAccessAuthorization() *schema.Resource { +func ResourceAuthorization() *schema.Resource { return &schema.Resource{ ReadContext: resourceMongoDBAtlasCloudProviderAccessAuthorizationRead, CreateContext: resourceMongoDBAtlasCloudProviderAccessAuthorizationCreate, diff --git a/mongodbatlas/resource_cloud_provider_access_authorization_test.go b/internal/service/cloudprovideraccess/resource_cloud_provider_access_authorization_test.go similarity index 99% rename from mongodbatlas/resource_cloud_provider_access_authorization_test.go rename to internal/service/cloudprovideraccess/resource_cloud_provider_access_authorization_test.go index b0d49661af..8fb4b7fd7d 100644 --- a/mongodbatlas/resource_cloud_provider_access_authorization_test.go +++ b/internal/service/cloudprovideraccess/resource_cloud_provider_access_authorization_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package cloudprovideraccess_test import ( "fmt" diff --git a/mongodbatlas/resource_cloud_provider_access_setup.go b/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup.go similarity index 98% rename from mongodbatlas/resource_cloud_provider_access_setup.go rename to internal/service/cloudprovideraccess/resource_cloud_provider_access_setup.go index 103a33009d..005575acb9 100644 --- a/mongodbatlas/resource_cloud_provider_access_setup.go +++ b/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup.go @@ -1,4 +1,4 @@ -package mongodbatlas +package cloudprovideraccess import ( "context" @@ -20,7 +20,7 @@ import ( -> The delete deletes and deauthorize the role */ -func ResourceCloudProviderAccessSetup() *schema.Resource { +func ResourceSetup() *schema.Resource { return &schema.Resource{ ReadContext: resourceMongoDBAtlasCloudProviderAccessSetupRead, CreateContext: resourceMongoDBAtlasCloudProviderAccessSetupCreate, diff --git a/mongodbatlas/resource_cloud_provider_access_setup_test.go b/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup_test.go similarity index 99% rename from mongodbatlas/resource_cloud_provider_access_setup_test.go rename to internal/service/cloudprovideraccess/resource_cloud_provider_access_setup_test.go index 8dbd83da05..fc506f793c 100644 --- a/mongodbatlas/resource_cloud_provider_access_setup_test.go +++ b/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package cloudprovideraccess_test import ( "fmt" diff --git a/mongodbatlas/resource_cloud_provider_access_test.go b/internal/service/cloudprovideraccess/resource_cloud_provider_access_test.go similarity index 95% rename from mongodbatlas/resource_cloud_provider_access_test.go rename to internal/service/cloudprovideraccess/resource_cloud_provider_access_test.go index 811fea1aae..7559a36279 100644 --- a/mongodbatlas/resource_cloud_provider_access_test.go +++ b/internal/service/cloudprovideraccess/resource_cloud_provider_access_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package cloudprovideraccess_test import ( "context" @@ -11,8 +11,8 @@ 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" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudprovideraccess" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -104,7 +104,7 @@ func testAccCheckMongoDBAtlasProviderAccessDestroy(s *terraform.State) error { roles, _, err := conn.CloudProviderAccess.ListRoles(context.Background(), ids["project_id"]) if err != nil { - return fmt.Errorf(mongodbatlas.ErrorCloudProviderGetRead, err) + return fmt.Errorf(cloudprovideraccess.ErrorCloudProviderGetRead, err) } var targetRole matlas.CloudProviderAccessRole @@ -147,7 +147,7 @@ func testAccCheckMongoDBAtlasProviderAccessExists(resourceName string, targetRol roles, _, err := conn.CloudProviderAccess.ListRoles(context.Background(), ids["project_id"]) if err != nil { - return fmt.Errorf(mongodbatlas.ErrorCloudProviderGetRead, err) + return fmt.Errorf(cloudprovideraccess.ErrorCloudProviderGetRead, err) } if providerName == "AWS" { diff --git a/mongodbatlas/data_source_federated_database_instance.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go similarity index 99% rename from mongodbatlas/data_source_federated_database_instance.go rename to internal/service/federateddatabaseinstance/data_source_federated_database_instance.go index c054f06515..6aa8c171f2 100644 --- a/mongodbatlas/data_source_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federateddatabaseinstance import ( "context" @@ -11,7 +11,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) -func DataSourceFederatedDatabaseInstance() *schema.Resource { +func DataSource() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasFederatedDatabaseInstanceRead, Schema: map[string]*schema.Schema{ diff --git a/mongodbatlas/data_source_federated_database_instance_test.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go similarity index 98% rename from mongodbatlas/data_source_federated_database_instance_test.go rename to internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go index 7a6a5fdcca..59b5b57915 100644 --- a/mongodbatlas/data_source_federated_database_instance_test.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federateddatabaseinstance_test import ( "context" @@ -27,7 +27,7 @@ func TestAccDataSourceFederatedDatabaseInstance_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, - CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseInstanceDestroy, + CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, Steps: []resource.TestStep{ { ExternalProviders: map[string]resource.ExternalProvider{ @@ -68,7 +68,7 @@ func TestAccDataSourceFederatedDatabaseInstance_S3Bucket(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, - CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseInstanceDestroy, + CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, Steps: []resource.TestStep{ { ExternalProviders: map[string]resource.ExternalProvider{ diff --git a/mongodbatlas/data_source_federated_database_instances.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go similarity index 98% rename from mongodbatlas/data_source_federated_database_instances.go rename to internal/service/federateddatabaseinstance/data_source_federated_database_instances.go index 256a6ae73d..9cb193728f 100644 --- a/mongodbatlas/data_source_federated_database_instances.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federateddatabaseinstance import ( "context" @@ -12,7 +12,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) -func DataSourceFederatedDatabaseInstances() *schema.Resource { +func PluralDataSource() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasFederatedDatabaseInstancesRead, Schema: map[string]*schema.Schema{ diff --git a/mongodbatlas/data_source_federated_database_instances_test.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instances_test.go similarity index 98% rename from mongodbatlas/data_source_federated_database_instances_test.go rename to internal/service/federateddatabaseinstance/data_source_federated_database_instances_test.go index 3f0f1b3dce..84f85df717 100644 --- a/mongodbatlas/data_source_federated_database_instances_test.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instances_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federateddatabaseinstance_test import ( "fmt" @@ -26,7 +26,7 @@ func TestAccDataSourceFederatedDatabaseInstances_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, - CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseInstanceDestroy, + CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, Steps: []resource.TestStep{ { ExternalProviders: map[string]resource.ExternalProvider{ diff --git a/mongodbatlas/resource_federated_database_instance.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go similarity index 99% rename from mongodbatlas/resource_federated_database_instance.go rename to internal/service/federateddatabaseinstance/resource_federated_database_instance.go index 1cfb686e08..e7053d9b26 100644 --- a/mongodbatlas/resource_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federateddatabaseinstance import ( "context" @@ -24,7 +24,7 @@ const ( errorFederatedDatabaseInstanceSetting = "error setting `%s` for MongoDB Atlas Federated Database Instace (%s): %s" ) -func ResourceFederatedDatabaseInstance() *schema.Resource { +func Resource() *schema.Resource { return &schema.Resource{ CreateContext: resourceMongoDBFederatedDatabaseInstanceCreate, ReadContext: resourceMongoDBAFederatedDatabaseInstanceRead, diff --git a/mongodbatlas/resource_federated_database_instance_test.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance_test.go similarity index 94% rename from mongodbatlas/resource_federated_database_instance_test.go rename to internal/service/federateddatabaseinstance/resource_federated_database_instance_test.go index d05bdc28d7..48da4aa70e 100644 --- a/mongodbatlas/resource_federated_database_instance_test.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance_test.go @@ -1,7 +1,6 @@ -package mongodbatlas_test +package federateddatabaseinstance_test import ( - "context" "fmt" "os" "testing" @@ -10,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" ) @@ -24,7 +22,7 @@ func TestAccFederatedDatabaseInstance_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, - CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseInstanceDestroy, + CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, Steps: []resource.TestStep{ { ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, @@ -76,7 +74,7 @@ func TestAccFederatedDatabaseInstance_S3bucket(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, - CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseInstanceDestroy, + CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, Steps: []resource.TestStep{ { ExternalProviders: map[string]resource.ExternalProvider{ @@ -113,7 +111,7 @@ func TestAccFederatedDatabaseInstance_atlasCluster(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, - CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseInstanceDestroy, + CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, Steps: []resource.TestStep{ { ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, @@ -266,24 +264,6 @@ func testAccCheckMongoDBAtlasFederatedDatabaseInstanceImportStateIDFunc(resource } } -func testAccCheckMongoDBAtlasFederatedDatabaseInstanceDestroy(s *terraform.State) error { - connV2 := acc.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() - if err == nil { - return fmt.Errorf("federated database instance (%s) still exists", ids["project_id"]) - } - } - - return nil -} - func testAccMongoDBAtlasFederatedDatabaseInstanceConfigS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, dataLakeRegion string) string { stepConfig := testAccMongoDBAtlasFederatedDatabaseInstanceConfigFirstSteps3Bucket(name, testS3Bucket) return fmt.Sprintf(` diff --git a/mongodbatlas/data_source_federated_query_limit.go b/internal/service/federatedquerylimit/data_source_federated_query_limit.go similarity index 96% rename from mongodbatlas/data_source_federated_query_limit.go rename to internal/service/federatedquerylimit/data_source_federated_query_limit.go index 5ac30e0b02..9b4cb2b5ca 100644 --- a/mongodbatlas/data_source_federated_query_limit.go +++ b/internal/service/federatedquerylimit/data_source_federated_query_limit.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedquerylimit import ( "context" @@ -10,7 +10,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) -func DataSourceFederatedDatabaseQueryLimit() *schema.Resource { +func DataSource() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasFederatedDatabaseQueryLimitRead, Schema: schemaMongoDBAtlasFederatedDatabaseQueryLimitDataSource(), diff --git a/mongodbatlas/data_source_federated_query_limit_test.go b/internal/service/federatedquerylimit/data_source_federated_query_limit_test.go similarity index 99% rename from mongodbatlas/data_source_federated_query_limit_test.go rename to internal/service/federatedquerylimit/data_source_federated_query_limit_test.go index a34386e7aa..595639b403 100644 --- a/mongodbatlas/data_source_federated_query_limit_test.go +++ b/internal/service/federatedquerylimit/data_source_federated_query_limit_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedquerylimit_test import ( "context" diff --git a/mongodbatlas/data_source_federated_query_limits.go b/internal/service/federatedquerylimit/data_source_federated_query_limits.go similarity index 96% rename from mongodbatlas/data_source_federated_query_limits.go rename to internal/service/federatedquerylimit/data_source_federated_query_limits.go index bfd57cbab0..34cf1a370f 100644 --- a/mongodbatlas/data_source_federated_query_limits.go +++ b/internal/service/federatedquerylimit/data_source_federated_query_limits.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedquerylimit import ( "context" @@ -11,7 +11,7 @@ import ( matlas "go.mongodb.org/atlas/mongodbatlas" ) -func DataSourceFederatedDatabaseQueryLimits() *schema.Resource { +func PluralDataSource() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasFederatedDatabaseQueryLimitsRead, Schema: map[string]*schema.Schema{ diff --git a/mongodbatlas/data_source_federated_query_limits_test.go b/internal/service/federatedquerylimit/data_source_federated_query_limits_test.go similarity index 99% rename from mongodbatlas/data_source_federated_query_limits_test.go rename to internal/service/federatedquerylimit/data_source_federated_query_limits_test.go index 25634fd292..8c2dee4eef 100644 --- a/mongodbatlas/data_source_federated_query_limits_test.go +++ b/internal/service/federatedquerylimit/data_source_federated_query_limits_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedquerylimit_test import ( "fmt" diff --git a/mongodbatlas/resource_federated_query_limit.go b/internal/service/federatedquerylimit/resource_federated_query_limit.go similarity index 98% rename from mongodbatlas/resource_federated_query_limit.go rename to internal/service/federatedquerylimit/resource_federated_query_limit.go index 928f230408..483f9e4ac6 100644 --- a/mongodbatlas/resource_federated_query_limit.go +++ b/internal/service/federatedquerylimit/resource_federated_query_limit.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedquerylimit import ( "context" @@ -22,7 +22,7 @@ const ( errorFederatedDatabaseQueryLimit = "error setting `%s` for Atlas Federated Database Query Limit (%s): %s" ) -func ResourceFederatedDatabaseQueryLimit() *schema.Resource { +func Resource() *schema.Resource { return &schema.Resource{ CreateContext: resourceMongoDBFederatedDatabaseQueryLimitCreate, ReadContext: resourceMongoDBFederatedDatabaseQueryLimitRead, diff --git a/mongodbatlas/resource_federated_query_limit_test.go b/internal/service/federatedquerylimit/resource_federated_query_limit_test.go similarity index 99% rename from mongodbatlas/resource_federated_query_limit_test.go rename to internal/service/federatedquerylimit/resource_federated_query_limit_test.go index 25b7761c03..ffce6da79d 100644 --- a/mongodbatlas/resource_federated_query_limit_test.go +++ b/internal/service/federatedquerylimit/resource_federated_query_limit_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedquerylimit_test import ( "context" diff --git a/mongodbatlas/data_source_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go similarity index 98% rename from mongodbatlas/data_source_federated_settings_identity_provider.go rename to internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go index 201b3b1713..3a15ea3456 100644 --- a/mongodbatlas/data_source_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedsettingsidentityprovider import ( "context" @@ -10,7 +10,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) -func DataSourceFederatedSettingsIdentityProvider() *schema.Resource { +func DataSource() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasFederatedSettingsIdentityProviderRead, Schema: map[string]*schema.Schema{ diff --git a/mongodbatlas/data_source_federated_settings_identity_provider_test.go b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider_test.go similarity index 97% rename from mongodbatlas/data_source_federated_settings_identity_provider_test.go rename to internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider_test.go index 860eca914f..b2e0293c61 100644 --- a/mongodbatlas/data_source_federated_settings_identity_provider_test.go +++ b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedsettingsidentityprovider_test import ( "fmt" diff --git a/mongodbatlas/data_source_federated_settings_identity_providers.go b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_providers.go similarity index 95% rename from mongodbatlas/data_source_federated_settings_identity_providers.go rename to internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_providers.go index b8c38b363f..2b5c50b801 100644 --- a/mongodbatlas/data_source_federated_settings_identity_providers.go +++ b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_providers.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedsettingsidentityprovider import ( "context" @@ -14,7 +14,7 @@ import ( matlas "go.mongodb.org/atlas/mongodbatlas" ) -func DataSourceFederatedSettingsIdentityProviders() *schema.Resource { +func PluralDataSource() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasFederatedSettingsIdentityProvidersRead, Schema: map[string]*schema.Schema{ @@ -287,7 +287,7 @@ func flattenAssociatedOrgs(associatedOrgs []*matlas.AssociatedOrgs) []map[string "identity_provider_id": associatedOrgs[i].IdentityProviderID, "org_id": associatedOrgs[i].OrgID, "post_auth_role_grants": associatedOrgs[i].PostAuthRoleGrants, - "role_mappings": flattenRoleMappings(associatedOrgs[i].RoleMappings), + "role_mappings": FlattenRoleMappings(associatedOrgs[i].RoleMappings), "user_conflicts": nil, } } else { @@ -297,8 +297,8 @@ func flattenAssociatedOrgs(associatedOrgs []*matlas.AssociatedOrgs) []map[string "identity_provider_id": associatedOrgs[i].IdentityProviderID, "org_id": associatedOrgs[i].OrgID, "post_auth_role_grants": associatedOrgs[i].PostAuthRoleGrants, - "role_mappings": flattenRoleMappings(associatedOrgs[i].RoleMappings), - "user_conflicts": flattenUserConflicts(*associatedOrgs[i].UserConflicts), + "role_mappings": FlattenRoleMappings(associatedOrgs[i].RoleMappings), + "user_conflicts": FlattenUserConflicts(*associatedOrgs[i].UserConflicts), } } } @@ -306,7 +306,7 @@ func flattenAssociatedOrgs(associatedOrgs []*matlas.AssociatedOrgs) []map[string return associatedOrgsMap } -func flattenUserConflicts(userConflicts matlas.UserConflicts) []map[string]any { +func FlattenUserConflicts(userConflicts matlas.UserConflicts) []map[string]any { var userConflictsMap []map[string]any if len(userConflicts) == 0 { @@ -388,7 +388,7 @@ func (ra roleMappingsByGroupName) Less(i, j int) bool { return ra[i].ExternalGroupName < ra[j].ExternalGroupName } -func flattenRoleMappings(roleMappings []*matlas.RoleMappings) []map[string]any { +func FlattenRoleMappings(roleMappings []*matlas.RoleMappings) []map[string]any { sort.Sort(roleMappingsByGroupName(roleMappings)) var roleMappingsMap []map[string]any @@ -400,7 +400,7 @@ func flattenRoleMappings(roleMappings []*matlas.RoleMappings) []map[string]any { roleMappingsMap[i] = map[string]any{ "external_group_name": roleMappings[i].ExternalGroupName, "id": roleMappings[i].ID, - "role_assignments": flattenRoleAssignments(roleMappings[i].RoleAssignments), + "role_assignments": FlattenRoleAssignments(roleMappings[i].RoleAssignments), } } } @@ -408,7 +408,7 @@ func flattenRoleMappings(roleMappings []*matlas.RoleMappings) []map[string]any { return roleMappingsMap } -func flattenRoleAssignments(roleAssignments []*matlas.RoleAssignments) []map[string]any { +func FlattenRoleAssignments(roleAssignments []*matlas.RoleAssignments) []map[string]any { sort.Sort(mRoleAssignment(roleAssignments)) var roleAssignmentsMap []map[string]any diff --git a/mongodbatlas/data_source_federated_settings_identity_providers_test.go b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_providers_test.go similarity index 98% rename from mongodbatlas/data_source_federated_settings_identity_providers_test.go rename to internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_providers_test.go index 181950573c..3552712982 100644 --- a/mongodbatlas/data_source_federated_settings_identity_providers_test.go +++ b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_providers_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedsettingsidentityprovider_test import ( "context" diff --git a/mongodbatlas/resource_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go similarity index 99% rename from mongodbatlas/resource_federated_settings_identity_provider.go rename to internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go index 3271e8c827..c25e89bbb1 100644 --- a/mongodbatlas/resource_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedsettingsidentityprovider import ( "context" @@ -14,7 +14,7 @@ import ( "github.com/spf13/cast" ) -func ResourceFederatedSettingsIdentityProvider() *schema.Resource { +func Resource() *schema.Resource { return &schema.Resource{ CreateContext: resourceMongoDBAtlasFederatedSettingsIdentityProviderRead, ReadContext: resourceMongoDBAtlasFederatedSettingsIdentityProviderRead, diff --git a/mongodbatlas/resource_federated_settings_identity_provider_test.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go similarity index 99% rename from mongodbatlas/resource_federated_settings_identity_provider_test.go rename to internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go index 781c203d6f..24e41c5a8e 100644 --- a/mongodbatlas/resource_federated_settings_identity_provider_test.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedsettingsidentityprovider_test import ( "context" diff --git a/mongodbatlas/data_source_federated_settings.go b/internal/service/federatedsettingsorgconfig/data_source_federated_settings.go similarity index 97% rename from mongodbatlas/data_source_federated_settings.go rename to internal/service/federatedsettingsorgconfig/data_source_federated_settings.go index f6cb390bc6..74c009821b 100644 --- a/mongodbatlas/data_source_federated_settings.go +++ b/internal/service/federatedsettingsorgconfig/data_source_federated_settings.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedsettingsorgconfig import ( "context" @@ -11,7 +11,7 @@ import ( matlas "go.mongodb.org/atlas/mongodbatlas" ) -func DataSourceFederatedSettings() *schema.Resource { +func DataSourceSettings() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasFederatedSettingsRead, Schema: map[string]*schema.Schema{ diff --git a/mongodbatlas/data_source_federated_settings_connected_organization.go b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_org.go similarity index 91% rename from mongodbatlas/data_source_federated_settings_connected_organization.go rename to internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_org.go index bb6cc43d7e..363f023eef 100644 --- a/mongodbatlas/data_source_federated_settings_connected_organization.go +++ b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_org.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedsettingsorgconfig import ( "context" @@ -8,9 +8,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsidentityprovider" ) -func DataSourceFederatedSettingsOrganizationConfig() *schema.Resource { +func DataSource() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasFederatedSettingsOrganizationConfigRead, Schema: map[string]*schema.Schema{ @@ -152,7 +153,7 @@ func dataSourceMongoDBAtlasFederatedSettingsOrganizationConfigRead(ctx context.C return diag.FromErr(fmt.Errorf("error setting `post_auth_role_grants` for federatedSettings IdentityProviders: %s", err)) } - if err := d.Set("role_mappings", flattenRoleMappings(federatedSettingsConnectedOrganization.RoleMappings)); err != nil { + if err := d.Set("role_mappings", federatedsettingsidentityprovider.FlattenRoleMappings(federatedSettingsConnectedOrganization.RoleMappings)); err != nil { return diag.FromErr(fmt.Errorf("error setting `role_mappings` for federatedSettings IdentityProviders: %s", err)) } if federatedSettingsConnectedOrganization.UserConflicts == nil { @@ -160,7 +161,7 @@ func dataSourceMongoDBAtlasFederatedSettingsOrganizationConfigRead(ctx context.C return diag.FromErr(fmt.Errorf("error setting `user_conflicts` for federatedSettings IdentityProviders: %s", err)) } } else { - if err := d.Set("user_conflicts", flattenUserConflicts(*federatedSettingsConnectedOrganization.UserConflicts)); err != nil { + if err := d.Set("user_conflicts", federatedsettingsidentityprovider.FlattenUserConflicts(*federatedSettingsConnectedOrganization.UserConflicts)); err != nil { return diag.FromErr(fmt.Errorf("error setting `user_conflicts` for federatedSettings IdentityProviders: %s", err)) } } diff --git a/mongodbatlas/data_source_federated_settings_connected_organization_test.go b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_org_test.go similarity index 98% rename from mongodbatlas/data_source_federated_settings_connected_organization_test.go rename to internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_org_test.go index 0f04f87e69..ac0b692355 100644 --- a/mongodbatlas/data_source_federated_settings_connected_organization_test.go +++ b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_org_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedsettingsorgconfig_test import ( "context" diff --git a/mongodbatlas/data_source_federated_settings_connected_organizations.go b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_orgs.go similarity index 90% rename from mongodbatlas/data_source_federated_settings_connected_organizations.go rename to internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_orgs.go index 9badb0fae9..8044facccc 100644 --- a/mongodbatlas/data_source_federated_settings_connected_organizations.go +++ b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_orgs.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedsettingsorgconfig import ( "context" @@ -8,10 +8,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsidentityprovider" matlas "go.mongodb.org/atlas/mongodbatlas" ) -func DataSourceFederatedSettingsOrganizationConfigs() *schema.Resource { +func PluralDataSource() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasFederatedSettingsOrganizationConfigsRead, Schema: map[string]*schema.Schema{ @@ -171,7 +172,7 @@ func flattenFederatedSettingsOrganizationConfigs(federatedSettingsConnectedOrgan "identity_provider_id": federatedSettingsConnectedOrganizations.Results[i].IdentityProviderID, "org_id": federatedSettingsConnectedOrganizations.Results[i].OrgID, "post_auth_role_grants": federatedSettingsConnectedOrganizations.Results[i].PostAuthRoleGrants, - "role_mappings": flattenRoleMappings(federatedSettingsConnectedOrganizations.Results[i].RoleMappings), + "role_mappings": federatedsettingsidentityprovider.FlattenRoleMappings(federatedSettingsConnectedOrganizations.Results[i].RoleMappings), "user_conflicts": nil, } } else { @@ -181,8 +182,8 @@ func flattenFederatedSettingsOrganizationConfigs(federatedSettingsConnectedOrgan "identity_provider_id": federatedSettingsConnectedOrganizations.Results[i].IdentityProviderID, "org_id": federatedSettingsConnectedOrganizations.Results[i].OrgID, "post_auth_role_grants": federatedSettingsConnectedOrganizations.Results[i].PostAuthRoleGrants, - "role_mappings": flattenRoleMappings(federatedSettingsConnectedOrganizations.Results[i].RoleMappings), - "user_conflicts": flattenUserConflicts(*federatedSettingsConnectedOrganizations.Results[i].UserConflicts), + "role_mappings": federatedsettingsidentityprovider.FlattenRoleMappings(federatedSettingsConnectedOrganizations.Results[i].RoleMappings), + "user_conflicts": federatedsettingsidentityprovider.FlattenUserConflicts(*federatedSettingsConnectedOrganizations.Results[i].UserConflicts), } } } diff --git a/mongodbatlas/data_source_federated_settings_connected_organizations_test.go b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_orgs_test.go similarity index 98% rename from mongodbatlas/data_source_federated_settings_connected_organizations_test.go rename to internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_orgs_test.go index d01f9e373b..75fe206dcf 100644 --- a/mongodbatlas/data_source_federated_settings_connected_organizations_test.go +++ b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_connected_orgs_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedsettingsorgconfig_test import ( "context" diff --git a/mongodbatlas/data_source_federated_settings_test.go b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_test.go similarity index 98% rename from mongodbatlas/data_source_federated_settings_test.go rename to internal/service/federatedsettingsorgconfig/data_source_federated_settings_test.go index 9a0e5096fb..04d4207f63 100644 --- a/mongodbatlas/data_source_federated_settings_test.go +++ b/internal/service/federatedsettingsorgconfig/data_source_federated_settings_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedsettingsorgconfig_test import ( "context" diff --git a/mongodbatlas/resource_federated_settings_connected_organization.go b/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org.go similarity index 98% rename from mongodbatlas/resource_federated_settings_connected_organization.go rename to internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org.go index 8827ed0a34..e7b2c11517 100644 --- a/mongodbatlas/resource_federated_settings_connected_organization.go +++ b/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedsettingsorgconfig import ( "context" @@ -14,7 +14,7 @@ import ( "github.com/spf13/cast" ) -func ResourceFederatedSettingsOrganizationConfig() *schema.Resource { +func Resource() *schema.Resource { return &schema.Resource{ CreateContext: resourceMongoDBAtlasFederatedSettingsOrganizationConfigRead, ReadContext: resourceMongoDBAtlasFederatedSettingsOrganizationConfigRead, diff --git a/mongodbatlas/resource_federated_settings_connected_organization_test.go b/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org_test.go similarity index 99% rename from mongodbatlas/resource_federated_settings_connected_organization_test.go rename to internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org_test.go index 7f1deab9b1..45be35ab18 100644 --- a/mongodbatlas/resource_federated_settings_connected_organization_test.go +++ b/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedsettingsorgconfig_test import ( "context" diff --git a/mongodbatlas/data_source_federated_settings_organization_role_mapping.go b/internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mapping.go similarity index 88% rename from mongodbatlas/data_source_federated_settings_organization_role_mapping.go rename to internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mapping.go index 72dfff9617..a1a8bbc021 100644 --- a/mongodbatlas/data_source_federated_settings_organization_role_mapping.go +++ b/internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mapping.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedsettingsorgrolemapping import ( "context" @@ -8,9 +8,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsidentityprovider" ) -func DataSourceFederatedSettingsOrganizationRoleMapping() *schema.Resource { +func DataSource() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasFederatedSettingsOrganizationRoleMappingRead, Schema: map[string]*schema.Schema{ @@ -89,7 +90,7 @@ func dataSourceMongoDBAtlasFederatedSettingsOrganizationRoleMappingRead(ctx cont return diag.FromErr(fmt.Errorf("error setting `result` for federatedSettings Role Mapping: %s", err)) } - if err := d.Set("role_assignments", flattenRoleAssignments(federatedSettingsOrganizationRoleMapping.RoleAssignments)); err != nil { + if err := d.Set("role_assignments", federatedsettingsidentityprovider.FlattenRoleAssignments(federatedSettingsOrganizationRoleMapping.RoleAssignments)); err != nil { return diag.FromErr(fmt.Errorf("error setting `result` for federatedSettings Role Mapping: %s", err)) } diff --git a/mongodbatlas/data_source_federated_settings_organization_role_mapping_test.go b/internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mapping_test.go similarity index 97% rename from mongodbatlas/data_source_federated_settings_organization_role_mapping_test.go rename to internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mapping_test.go index f710ec206d..c10a186778 100644 --- a/mongodbatlas/data_source_federated_settings_organization_role_mapping_test.go +++ b/internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mapping_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedsettingsorgrolemapping_test import ( "fmt" diff --git a/mongodbatlas/data_source_federated_settings_organization_role_mappings.go b/internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mappings.go similarity index 91% rename from mongodbatlas/data_source_federated_settings_organization_role_mappings.go rename to internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mappings.go index 97c90e26c2..d9370a2753 100644 --- a/mongodbatlas/data_source_federated_settings_organization_role_mappings.go +++ b/internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mappings.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedsettingsorgrolemapping import ( "context" @@ -8,10 +8,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsidentityprovider" matlas "go.mongodb.org/atlas/mongodbatlas" ) -func DataSourceFederatedSettingsOrganizationRoleMappings() *schema.Resource { +func PluralDataSource() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceMongoDBAtlasFederatedSettingsOrganizationRoleMappingsRead, Schema: map[string]*schema.Schema{ @@ -115,7 +116,7 @@ func flattenFederatedSettingsOrganizationRoleMappings(federatedSettingsOrganizat federatedSettingsOrganizationRoleMappingMap[i] = map[string]any{ "external_group_name": federatedSettingsOrganizationRoleMapping.Results[i].ExternalGroupName, "id": federatedSettingsOrganizationRoleMapping.Results[i].ID, - "role_assignments": flattenRoleAssignments(federatedSettingsOrganizationRoleMapping.Results[i].RoleAssignments), + "role_assignments": federatedsettingsidentityprovider.FlattenRoleAssignments(federatedSettingsOrganizationRoleMapping.Results[i].RoleAssignments), } } } diff --git a/mongodbatlas/data_source_federated_settings_organization_role_mappings_test.go b/internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mappings_test.go similarity index 98% rename from mongodbatlas/data_source_federated_settings_organization_role_mappings_test.go rename to internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mappings_test.go index cb052957c1..d18bd6b127 100644 --- a/mongodbatlas/data_source_federated_settings_organization_role_mappings_test.go +++ b/internal/service/federatedsettingsorgrolemapping/data_source_federated_settings_org_role_mappings_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedsettingsorgrolemapping_test import ( "context" diff --git a/mongodbatlas/resource_federated_settings_organization_role_mapping.go b/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping.go similarity index 99% rename from mongodbatlas/resource_federated_settings_organization_role_mapping.go rename to internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping.go index 0738b8b1df..82afa12051 100644 --- a/mongodbatlas/resource_federated_settings_organization_role_mapping.go +++ b/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping.go @@ -1,4 +1,4 @@ -package mongodbatlas +package federatedsettingsorgrolemapping import ( "context" @@ -16,7 +16,7 @@ import ( matlas "go.mongodb.org/atlas/mongodbatlas" ) -func ResourceFederatedSettingsOrganizationRoleMapping() *schema.Resource { +func Resource() *schema.Resource { return &schema.Resource{ CreateContext: resourceMongoDBAtlasFederatedSettingsOrganizationRoleMappingCreate, ReadContext: resourceMongoDBAtlasFederatedSettingsOrganizationRoleMappingRead, diff --git a/mongodbatlas/resource_federated_settings_organization_role_mapping_test.go b/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping_test.go similarity index 99% rename from mongodbatlas/resource_federated_settings_organization_role_mapping_test.go rename to internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping_test.go index f02864a159..f035053401 100644 --- a/mongodbatlas/resource_federated_settings_organization_role_mapping_test.go +++ b/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping_test.go @@ -1,4 +1,4 @@ -package mongodbatlas_test +package federatedsettingsorgrolemapping_test import ( "context" diff --git a/internal/testutil/acc/federated.go b/internal/testutil/acc/federated.go new file mode 100644 index 0000000000..90b6dcb5a3 --- /dev/null +++ b/internal/testutil/acc/federated.go @@ -0,0 +1,28 @@ +package acc + +import ( + "context" + "fmt" + + "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() + if err == nil { + return fmt.Errorf("federated database instance (%s) still exists", ids["project_id"]) + } + } + + return nil +} diff --git a/mongodbatlas/resource_online_archive_migration_test.go b/mongodbatlas/resource_online_archive_migration_test.go index 659ff8f198..8d808c64c2 100644 --- a/mongodbatlas/resource_online_archive_migration_test.go +++ b/mongodbatlas/resource_online_archive_migration_test.go @@ -27,7 +27,7 @@ func TestAccMigrationBackupRSOnlineArchiveWithNoChangeBetweenVersions(t *testing resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasicMigration(t) }, - CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseInstanceDestroy, + CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, Steps: []resource.TestStep{ { ExternalProviders: map[string]resource.ExternalProvider{