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 57b6e1b42d..011e66cd24 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go @@ -14,37 +14,6 @@ import ( "go.mongodb.org/atlas-sdk/v20231115012/admin" ) -func TestAccFederatedDatabaseInstanceDS_basic(t *testing.T) { - var ( - resourceName = "data.mongodbatlas_federated_database_instance.test" - orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") - projectName = acc.RandomProjectName() - name = acc.RandomName() - federatedInstance = admin.DataLakeTenant{} - ) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheckBasic(t) }, - CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, - Steps: []resource.TestStep{ - { - ExternalProviders: acc.ExternalProvidersOnlyAWS(), - ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - Config: configFirstStepsDS(name, projectName, orgID), - Check: resource.ComposeTestCheckFunc( - checkExists(resourceName, &federatedInstance), - checkAttributes(&federatedInstance, name), - resource.TestCheckResourceAttrSet(resourceName, "project_id"), - resource.TestCheckResourceAttr(resourceName, "name", name), - resource.TestCheckResourceAttrSet(resourceName, "storage_stores.0.read_preference.0.tag_sets.#"), - resource.TestCheckResourceAttr(resourceName, "storage_stores.0.read_preference.0.tag_sets.#", "2"), - resource.TestCheckResourceAttr(resourceName, "storage_stores.0.read_preference.0.tag_sets.0.tags.#", "2"), - ), - }, - }, - }) -} - func TestAccFederatedDatabaseInstanceDS_s3Bucket(t *testing.T) { var ( resourceName = "data.mongodbatlas_federated_database_instance.test" @@ -264,105 +233,3 @@ data "mongodbatlas_federated_database_instance" "test" { } `, name, testS3Bucket) } - -func configFirstStepsDS(federatedInstanceName, projectName, orgID string) string { - return fmt.Sprintf(` - -resource "mongodbatlas_project" "test" { - name = %[2]q - org_id = %[3]q - } - -resource "mongodbatlas_federated_database_instance" "test" { - project_id = mongodbatlas_project.test.id - name = %[1]q - - storage_databases { - name = "VirtualDatabase0" - collections { - name = "VirtualCollection0" - data_sources { - collection = "listingsAndReviews" - database = "sample_airbnb" - store_name = "ClusterTest" - } - } - } - - storage_stores { - name = "ClusterTest" - cluster_name = "ClusterTest" - project_id = mongodbatlas_project.test.id - provider = "atlas" - read_preference { - mode = "secondary" - tag_sets { - tags { - name = "environment0" - value = "development0" - } - tags { - name = "application0" - value = "app0" - } - } - tag_sets { - tags { - name = "environment1" - value = "development1" - } - tags { - name = "application1" - value = "app1" - } - } - } - } - - storage_stores { - name = "dataStore0" - cluster_name = "ClusterTest" - project_id = mongodbatlas_project.test.id - provider = "atlas" - read_preference { - mode = "secondary" - tag_sets { - tags { - name = "environment0" - value = "development0" - } - tags { - name = "application0" - value = "app0" - } - } - tag_sets { - tags { - name = "environment1" - value = "development1" - } - tags { - name = "application1" - value = "app1" - } - } - tag_sets { - tags { - name = "environment0" - value = "development0" - } - tags { - name = "application0" - value = "app0" - } - } - } - } -} - -data "mongodbatlas_federated_database_instance" "test" { - project_id = mongodbatlas_federated_database_instance.test.project_id - name = mongodbatlas_federated_database_instance.test.name -} - `, federatedInstanceName, projectName, orgID) -} diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go index fe86f54544..00b80a4f7a 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go @@ -780,7 +780,7 @@ func flattenCloudProviderConfig(d *schema.ResourceData, cloudProviderConfig *adm } func flattenDataProcessRegion(processRegion *admin.DataLakeDataProcessRegion) []map[string]any { - if processRegion == nil || (processRegion.Region != "" && processRegion.CloudProvider != "") { + if processRegion == nil { return nil } diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance_test.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance_test.go index 2baaaa2da3..5217f807b0 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance_test.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance_test.go @@ -14,12 +14,27 @@ import ( func TestAccFederatedDatabaseInstance_basic(t *testing.T) { var ( - resourceName = "mongodbatlas_federated_database_instance.test" - orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") - projectName = acc.RandomProjectName() - name = acc.RandomName() + resourceName = "mongodbatlas_federated_database_instance.test" + dataSourceName = "data.mongodbatlas_federated_database_instance.test" + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acc.RandomProjectName() + name = acc.RandomName() ) + valueChecks := map[string]string{ + "name": name, + "data_process_region.0.cloud_provider": "AWS", + "data_process_region.0.region": "OREGON_USA", + "storage_stores.0.read_preference.0.tag_sets.#": "2", + "storage_stores.0.read_preference.0.tag_sets.0.tags.#": "2", + "storage_databases.0.collections.0.data_sources.0.database": "sample_airbnb", + } + setChecks := []string{"project_id", "storage_stores.0.read_preference.0.tag_sets.#"} + firstStepChecks := acc.AddAttrChecks(resourceName, nil, valueChecks) + firstStepChecks = acc.AddAttrSetChecks(resourceName, firstStepChecks, setChecks...) + firstStepChecks = acc.AddAttrChecks(dataSourceName, firstStepChecks, valueChecks) + firstStepChecks = acc.AddAttrSetChecks(dataSourceName, firstStepChecks, setChecks...) + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, @@ -27,14 +42,7 @@ func TestAccFederatedDatabaseInstance_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: configFirstSteps(name, projectName, orgID), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(resourceName, "project_id"), - resource.TestCheckResourceAttr(resourceName, "name", name), - resource.TestCheckResourceAttrSet(resourceName, "storage_stores.0.read_preference.0.tag_sets.#"), - resource.TestCheckResourceAttr(resourceName, "storage_stores.0.read_preference.0.tag_sets.#", "2"), - resource.TestCheckResourceAttr(resourceName, "storage_stores.0.read_preference.0.tag_sets.0.tags.#", "2"), - resource.TestCheckResourceAttr(resourceName, "storage_databases.0.collections.0.data_sources.0.database", "sample_airbnb"), - ), + Check: resource.ComposeTestCheckFunc(firstStepChecks...), }, { Config: configFirstStepsUpdate(name, projectName, orgID), @@ -489,6 +497,11 @@ resource "mongodbatlas_federated_database_instance" "test" { } } } + +data "mongodbatlas_federated_database_instance" "test" { + project_id = mongodbatlas_federated_database_instance.test.project_id + name = mongodbatlas_federated_database_instance.test.name +} `, federatedInstanceName, projectName, orgID) }