diff --git a/.github/workflows/acceptance-tests-runner.yml b/.github/workflows/acceptance-tests-runner.yml index 8a9566d3e3..0dca792900 100644 --- a/.github/workflows/acceptance-tests-runner.yml +++ b/.github/workflows/acceptance-tests-runner.yml @@ -55,6 +55,9 @@ on: aws_secret_name: type: string required: true + aws_region_federation: + type: string + required: true secrets: # all secrets are passed explicitly in this workflow mongodb_atlas_public_key: required: true @@ -72,8 +75,8 @@ on: required: true aws_secret_access_key: required: true - - + aws_s3_bucket_federation: + required: true env: # CI: true # GH does this automatically @@ -428,7 +431,6 @@ jobs: AWS_SECURITY_GROUP_2: ${{ vars.AWS_SECURITY_GROUP_2 }} AWS_VPC_CIDR_BLOCK: ${{ vars.AWS_VPC_CIDR_BLOCK }} AWS_VPC_ID: ${{ vars.AWS_VPC_ID }} - TEST_REGEX: "^TestAccProject" run: make testacc serverless: @@ -504,6 +506,10 @@ jobs: terraform_wrapper: false - name: Acceptance Tests env: + AWS_S3_BUCKET: ${{ secrets.aws_s3_bucket_federation }} + AWS_REGION: ${{ vars.aws_region_federation }} + AWS_ACCESS_KEY_ID: ${{ secrets.aws_access_key_id }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.aws_secret_access_key }} MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.mongodb_atlas_public_key }} MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.mongodb_atlas_private_key }} MONGODB_ATLAS_ORG_ID: ${{ inputs.mongodb_atlas_org_id }} diff --git a/.github/workflows/acceptance-tests.yml b/.github/workflows/acceptance-tests.yml index 90f151e03d..854f82eee2 100644 --- a/.github/workflows/acceptance-tests.yml +++ b/.github/workflows/acceptance-tests.yml @@ -50,11 +50,13 @@ jobs: aws_account_id: ${{ secrets.AWS_ACCOUNT_ID }} aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws_s3_bucket_federation: ${{ secrets.AWS_S3_BUCKET_FEDERATION }} with: terraform_version: ${{ inputs.terraform_version || vars.TF_VERSION_LATEST }} ref: ${{ inputs.ref }} test_group: ${{ inputs.test_group }} atlas_cloud_env: ${{ inputs.atlas_cloud_env }} + aws_region_federation: ${{ vars.AWS_REGION_FEDERATION }} mongodb_atlas_org_id: ${{ inputs.atlas_cloud_env == 'qa' && vars.MONGODB_ATLAS_ORG_ID_CLOUD_QA || vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }} mongodb_atlas_org_id_network: ${{ inputs.atlas_cloud_env == 'qa' && vars.MONGODB_ATLAS_ORG_ID_CLOUD_QA || vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV_NETWORK }} mongodb_atlas_project_id_network: ${{ inputs.atlas_cloud_env == 'qa' && vars.MONGODB_ATLAS_PROJECT_ID_CLOUD_QA || vars.MONGODB_ATLAS_PROJECT_ID_CLOUD_DEV_NETWORK }} @@ -65,4 +67,4 @@ jobs: azure_atlas_app_id: ${{ inputs.atlas_cloud_env == 'qa' && vars.AZURE_ATLAS_APP_ID_QA || vars.AZURE_ATLAS_APP_ID }} azure_service_principal_id: ${{ inputs.atlas_cloud_env == 'qa' && vars.AZURE_SERVICE_PRINCIPAL_ID_QA || vars.AZURE_SERVICE_PRINCIPAL_ID }} azure_tenant_id: ${{ inputs.atlas_cloud_env == 'qa' && vars.AZURE_TENANT_ID_QA || vars.AZURE_TENANT_ID }} - aws_secret_name: ${{ inputs.atlas_cloud_env == 'qa' && vars.AWS_SECRET_NAME_QA || vars.AWS_SECRET_NAME }} \ No newline at end of file + aws_secret_name: ${{ inputs.atlas_cloud_env == 'qa' && vars.AWS_SECRET_NAME_QA || vars.AWS_SECRET_NAME }} diff --git a/.github/workflows/migration-tests.yml b/.github/workflows/migration-tests.yml index bdfe620c97..cbd2d7956b 100644 --- a/.github/workflows/migration-tests.yml +++ b/.github/workflows/migration-tests.yml @@ -61,6 +61,7 @@ jobs: advanced_cluster: ${{ steps.filter.outputs.advanced_cluster == 'true' || env.mustTrigger == 'true' }} backup_online_archive: ${{ steps.filter.outputs.backup_online_archive == 'true' || env.mustTrigger == 'true' }} stream: ${{ steps.filter.outputs.stream == 'true' || env.mustTrigger == 'true' }} + federation: ${{ steps.filter.outputs.federation == 'true' || env.mustTrigger == 'true' }} steps: - uses: actions/checkout@v4 - uses: dorny/paths-filter@v2 @@ -83,7 +84,9 @@ jobs: stream: - 'internal/service/streaminstance/*.go' - 'internal/service/streamconnection/*.go' - + federation: + - 'internal/service/federateddatabaseinstance/*.go' + project: needs: [ change-detection, get-provider-version ] if: ${{ needs.change-detection.outputs.project == 'true' || inputs.test_group == 'project' }} @@ -225,3 +228,31 @@ jobs: MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }} TEST_REGEX: "^TestAccMigrationStream" run: make testacc + federation: + needs: [ change-detection, get-provider-version ] + if: ${{ needs.change-detection.outputs.federation == 'true' || inputs.test_group == 'federation' }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + - uses: hashicorp/setup-terraform@v3 + with: + terraform_version: ${{ env.terraform_version }} + terraform_wrapper: false + - name: Migration Tests + env: + AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_FEDERATION }} + AWS_REGION: ${{ vars.AWS_REGION_FEDERATION }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }} + MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }} + MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }} + MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }} + MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }} + TEST_REGEX: "^TestAccMigrationFederatedDatabaseInstance" + run: make testacc diff --git a/internal/service/cloudbackupsnapshotexportbucket/data_source_cloud_backup_snapshot_export_bucket_test.go b/internal/service/cloudbackupsnapshotexportbucket/data_source_cloud_backup_snapshot_export_bucket_test.go index dcff093b35..81f70e0916 100644 --- a/internal/service/cloudbackupsnapshotexportbucket/data_source_cloud_backup_snapshot_export_bucket_test.go +++ b/internal/service/cloudbackupsnapshotexportbucket/data_source_cloud_backup_snapshot_export_bucket_test.go @@ -20,7 +20,7 @@ func TestAccBackupDSCloudBackupSnapshotExportBucket_basic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t) }, + PreCheck: func() { acc.PreCheck(t); acc.PreCheckS3Bucket(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, Steps: []resource.TestStep{ { diff --git a/internal/service/cloudbackupsnapshotexportbucket/data_source_cloud_backup_snapshot_export_buckets_test.go b/internal/service/cloudbackupsnapshotexportbucket/data_source_cloud_backup_snapshot_export_buckets_test.go index df8593d802..e8888bd168 100644 --- a/internal/service/cloudbackupsnapshotexportbucket/data_source_cloud_backup_snapshot_export_buckets_test.go +++ b/internal/service/cloudbackupsnapshotexportbucket/data_source_cloud_backup_snapshot_export_buckets_test.go @@ -19,7 +19,7 @@ func TestAccBackupDSCloudBackupSnapshotExportBuckets_basic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t) }, + PreCheck: func() { acc.PreCheck(t); acc.PreCheckS3Bucket(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, Steps: []resource.TestStep{ { 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 13a33cb2f4..aeea90181f 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 @@ -24,7 +24,7 @@ func TestAccBackupRSBackupSnapshotExportBucket_basic(t *testing.T) { iamRoleID = os.Getenv("IAM_ROLE_ID") ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t) }, + PreCheck: func() { acc.PreCheck(t); acc.PreCheckS3Bucket(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, CheckDestroy: testAccCheckMongoDBAtlasBackupSnapshotExportBucketDestroy, Steps: []resource.TestStep{ @@ -51,7 +51,7 @@ func TestAccBackupRSBackupSnapshotExportBucket_importBasic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t) }, + PreCheck: func() { acc.PreCheck(t); acc.PreCheckS3Bucket(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, CheckDestroy: testAccCheckMongoDBAtlasBackupSnapshotExportBucketDestroy, Steps: []resource.TestStep{ diff --git a/internal/service/cloudbackupsnapshotexportjob/data_source_cloud_backup_snapshot_export_job_test.go b/internal/service/cloudbackupsnapshotexportjob/data_source_cloud_backup_snapshot_export_job_test.go index 9ba8851f0d..dce691da8e 100644 --- a/internal/service/cloudbackupsnapshotexportjob/data_source_cloud_backup_snapshot_export_job_test.go +++ b/internal/service/cloudbackupsnapshotexportjob/data_source_cloud_backup_snapshot_export_job_test.go @@ -20,7 +20,7 @@ func TestAccBackupDSCloudBackupSnapshotExportJob_basic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t) }, + PreCheck: func() { acc.PreCheck(t); acc.PreCheckS3Bucket(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, Steps: []resource.TestStep{ { diff --git a/internal/service/cloudbackupsnapshotexportjob/data_source_cloud_backup_snapshot_export_jobs_test.go b/internal/service/cloudbackupsnapshotexportjob/data_source_cloud_backup_snapshot_export_jobs_test.go index b30a323fd2..aed28efa3f 100644 --- a/internal/service/cloudbackupsnapshotexportjob/data_source_cloud_backup_snapshot_export_jobs_test.go +++ b/internal/service/cloudbackupsnapshotexportjob/data_source_cloud_backup_snapshot_export_jobs_test.go @@ -19,7 +19,7 @@ func TestAccBackupDSCloudBackupSnapshotExportJobs_basic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t) }, + PreCheck: func() { acc.PreCheck(t); acc.PreCheckS3Bucket(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, Steps: []resource.TestStep{ { 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 7ab2382a84..be8ad0d6d5 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 @@ -24,7 +24,7 @@ func TestAccBackupRSBackupSnapshotExportJob_basic(t *testing.T) { iamRoleID = os.Getenv("IAM_ROLE_ID") ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t) }, + PreCheck: func() { acc.PreCheck(t); acc.PreCheckS3Bucket(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, CheckDestroy: testAccCheckMongoDBAtlasBackupSnapshotExportJobDestroy, Steps: []resource.TestStep{ @@ -51,7 +51,7 @@ func TestAccBackupRSBackupSnapshotExportJob_importBasic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t) }, + PreCheck: func() { acc.PreCheck(t); acc.PreCheckS3Bucket(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, CheckDestroy: testAccCheckMongoDBAtlasBackupSnapshotExportJobDestroy, Steps: []resource.TestStep{ 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 d1645ebeac..4f447a24fe 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go @@ -16,7 +16,7 @@ import ( "go.mongodb.org/atlas-sdk/v20231115004/admin" ) -func TestAccDataSourceFederatedDatabaseInstance_basic(t *testing.T) { +func TestAccFederatedDatabaseInstanceDS_basic(t *testing.T) { var ( resourceName = "data.mongodbatlas_federated_database_instance.test" orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") @@ -32,10 +32,10 @@ func TestAccDataSourceFederatedDatabaseInstance_basic(t *testing.T) { { ExternalProviders: acc.ExternalProvidersOnlyAWS(), ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - Config: testAccMongoDBAtlasFederatedDatabaseInstanceConfigDataSourceFirstSteps(name, projectName, orgID), + Config: configFirstStepsDS(name, projectName, orgID), Check: resource.ComposeTestCheckFunc( - testAccCheckMongoDBAtlasFederatedDatabaseDataSourceInstanceExists(resourceName, &federatedInstance), - testAccCheckMongoDBAtlasFederatedDabaseInstanceAttributes(&federatedInstance, name), + 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.#"), @@ -47,31 +47,30 @@ func TestAccDataSourceFederatedDatabaseInstance_basic(t *testing.T) { }) } -func TestAccDataSourceFederatedDatabaseInstance_S3Bucket(t *testing.T) { - acc.SkipTestExtCred(t) +func TestAccFederatedDatabaseInstanceDS_s3Bucket(t *testing.T) { var ( resourceName = "data.mongodbatlas_federated_database_instance.test" orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") projectName = acctest.RandomWithPrefix("test-acc") name = acctest.RandomWithPrefix("test-acc") policyName = acctest.RandomWithPrefix("test-acc") - roleName = acctest.RandomWithPrefix("test-acc") + roleName = acctest.RandomWithPrefix("mongodb-atlas-test-acc-fed") testS3Bucket = os.Getenv("AWS_S3_BUCKET") region = "VIRGINIA_USA" federatedInstance = admin.DataLakeTenant{} ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheckBasic(t) }, + PreCheck: func() { acc.PreCheckBasic(t); acc.PreCheckS3Bucket(t) }, CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, Steps: []resource.TestStep{ { ExternalProviders: acc.ExternalProvidersOnlyAWS(), ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - Config: testAccMongoDBAtlasFederatedDatabaseInstanceDataSourceConfigS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, region), + Config: configDSWithS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, region), Check: resource.ComposeTestCheckFunc( - testAccCheckMongoDBAtlasFederatedDatabaseDataSourceInstanceExists(resourceName, &federatedInstance), - testAccCheckMongoDBAtlasFederatedDabaseInstanceAttributes(&federatedInstance, name), + checkExists(resourceName, &federatedInstance), + checkAttributes(&federatedInstance, name), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttr(resourceName, "name", name), ), @@ -80,7 +79,7 @@ func TestAccDataSourceFederatedDatabaseInstance_S3Bucket(t *testing.T) { }) } -func testAccCheckMongoDBAtlasFederatedDatabaseDataSourceInstanceExists(resourceName string, dataFederatedInstance *admin.DataLakeTenant) resource.TestCheckFunc { +func checkExists(resourceName string, dataFederatedInstance *admin.DataLakeTenant) resource.TestCheckFunc { return func(s *terraform.State) error { connV2 := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).AtlasV2 @@ -103,7 +102,7 @@ func testAccCheckMongoDBAtlasFederatedDatabaseDataSourceInstanceExists(resourceN } } -func testAccCheckMongoDBAtlasFederatedDabaseInstanceAttributes(dataFederatedInstance *admin.DataLakeTenant, name string) resource.TestCheckFunc { +func checkAttributes(dataFederatedInstance *admin.DataLakeTenant, name string) resource.TestCheckFunc { return func(s *terraform.State) error { log.Printf("[DEBUG] difference dataFederatedInstance.Name: %s , username : %s", dataFederatedInstance.GetName(), name) if dataFederatedInstance.GetName() != name { @@ -113,8 +112,8 @@ func testAccCheckMongoDBAtlasFederatedDabaseInstanceAttributes(dataFederatedInst } } -func testAccMongoDBAtlasFederatedDatabaseInstanceDataSourceConfigS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, dataLakeRegion string) string { - stepConfig := testAccMongoDBAtlasFederatedDatabaseInstanceConfigDataSourceFirstStepS3Bucket(name, testS3Bucket) +func configDSWithS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, dataLakeRegion string) string { + stepConfig := configDSFirstStepS3Bucket(name, testS3Bucket) return fmt.Sprintf(` resource "aws_iam_role_policy" "test_policy" { name = %[1]q @@ -181,7 +180,7 @@ resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" { %s `, policyName, roleName, projectName, orgID, stepConfig) } -func testAccMongoDBAtlasFederatedDatabaseInstanceConfigDataSourceFirstStepS3Bucket(name, testS3Bucket string) string { +func configDSFirstStepS3Bucket(name, testS3Bucket string) string { return fmt.Sprintf(` resource "mongodbatlas_federated_database_instance" "test" { project_id = mongodbatlas_project.test.id @@ -273,7 +272,7 @@ data "mongodbatlas_federated_database_instance" "test" { `, name, testS3Bucket) } -func testAccMongoDBAtlasFederatedDatabaseInstanceConfigDataSourceFirstSteps(federatedInstanceName, projectName, orgID string) string { +func configFirstStepsDS(federatedInstanceName, projectName, orgID string) string { return fmt.Sprintf(` resource "mongodbatlas_project" "test" { diff --git a/internal/service/federateddatabaseinstance/data_source_federated_database_instances_test.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instances_test.go index 5f0690df00..81cf3c512c 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instances_test.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instances_test.go @@ -10,8 +10,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) -func TestAccDataSourceFederatedDatabaseInstances_basic(t *testing.T) { - acc.SkipTestExtCred(t) +func TestAccFederatedDatabaseInstanceDSPlural_basic(t *testing.T) { var ( resourceName = "data.mongodbatlas_federated_database_instances.test" orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") @@ -19,19 +18,19 @@ func TestAccDataSourceFederatedDatabaseInstances_basic(t *testing.T) { firstName = acctest.RandomWithPrefix("test-acc") secondName = acctest.RandomWithPrefix("test-acc") policyName = acctest.RandomWithPrefix("test-acc") - roleName = acctest.RandomWithPrefix("test-acc") + roleName = acctest.RandomWithPrefix("mongodb-atlas-test-acc-fed") testS3Bucket = os.Getenv("AWS_S3_BUCKET") region = "VIRGINIA_USA" ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheckBasic(t) }, + PreCheck: func() { acc.PreCheckBasic(t); acc.PreCheckS3Bucket(t) }, CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, Steps: []resource.TestStep{ { ExternalProviders: acc.ExternalProvidersOnlyAWS(), ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - Config: testAccMongoDBAtlasFederatedDatabaseInstancesDataSourceConfig(policyName, roleName, projectName, orgID, firstName, secondName, testS3Bucket, region), + Config: configDSPlural(policyName, roleName, projectName, orgID, firstName, secondName, testS3Bucket, region), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "results.#"), @@ -41,8 +40,8 @@ func TestAccDataSourceFederatedDatabaseInstances_basic(t *testing.T) { }) } -func testAccMongoDBAtlasFederatedDatabaseInstancesDataSourceConfig(policyName, roleName, projectName, orgID, firstName, secondName, testS3Bucket, dataLakeRegion string) string { - stepConfig := testAccMongoDBAtlasFederatedDatabaseInstancesConfigDataSourceFirstStep(firstName, secondName, testS3Bucket) +func configDSPlural(policyName, roleName, projectName, orgID, firstName, secondName, testS3Bucket, dataLakeRegion string) string { + stepConfig := configDSPluralFirstStep(firstName, secondName, testS3Bucket) return fmt.Sprintf(` resource "aws_iam_role_policy" "test_policy" { name = %[1]q @@ -109,7 +108,7 @@ resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" { %s `, policyName, roleName, projectName, orgID, stepConfig) } -func testAccMongoDBAtlasFederatedDatabaseInstancesConfigDataSourceFirstStep(firstName, secondName, testS3Bucket string) string { +func configDSPluralFirstStep(firstName, secondName, testS3Bucket string) string { return fmt.Sprintf(` resource "mongodbatlas_federated_database_instance" "test" { project_id = mongodbatlas_project.test.id diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go index d5a507a725..ef8c466d2d 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go @@ -26,17 +26,18 @@ const ( func Resource() *schema.Resource { return &schema.Resource{ - CreateContext: resourceMongoDBFederatedDatabaseInstanceCreate, - ReadContext: resourceMongoDBAFederatedDatabaseInstanceRead, - UpdateContext: resourceMongoDBFederatedDatabaseInstanceUpdate, - DeleteContext: resourceMongoDBAtlasFederatedDatabaseInstanceDelete, + CreateContext: resourceCreate, + ReadContext: resourceRead, + UpdateContext: resourceUpdate, + DeleteContext: resourceDelete, Importer: &schema.ResourceImporter{ - StateContext: resourceMongoDBAtlasFederatedDatabaseInstanceImportState, + StateContext: resourceImport, }, Schema: map[string]*schema.Schema{ "project_id": { Type: schema.TypeString, Required: true, + ForceNew: true, }, "name": { Type: schema.TypeString, @@ -56,6 +57,7 @@ func Resource() *schema.Resource { "cloud_provider_config": { Type: schema.TypeList, MaxItems: 1, + Computed: true, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -94,6 +96,7 @@ func Resource() *schema.Resource { "data_process_region": { Type: schema.TypeList, MaxItems: 1, + Computed: true, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -117,20 +120,24 @@ func Resource() *schema.Resource { func schemaFederatedDatabaseInstanceDatabases() *schema.Schema { return &schema.Schema{ Type: schema.TypeSet, + Computed: true, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, + Computed: true, Optional: true, }, "collections": { Type: schema.TypeSet, + Computed: true, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, + Computed: true, Optional: true, }, "data_sources": { @@ -140,46 +147,57 @@ func schemaFederatedDatabaseInstanceDatabases() *schema.Schema { Schema: map[string]*schema.Schema{ "store_name": { Type: schema.TypeString, + Computed: true, Optional: true, }, "dataset_name": { Type: schema.TypeString, + Computed: true, Optional: true, }, "default_format": { Type: schema.TypeString, + Computed: true, Optional: true, }, "path": { Type: schema.TypeString, + Computed: true, Optional: true, }, "allow_insecure": { Type: schema.TypeBool, + Computed: true, Optional: true, }, "database": { Type: schema.TypeString, + Computed: true, Optional: true, }, "database_regex": { Type: schema.TypeString, + Computed: true, Optional: true, }, "collection": { Type: schema.TypeString, + Computed: true, Optional: true, }, "collection_regex": { Type: schema.TypeString, + Computed: true, Optional: true, }, "provenance_field_name": { Type: schema.TypeString, + Computed: true, Optional: true, }, "urls": { Type: schema.TypeList, + Computed: true, Optional: true, Elem: &schema.Schema{ Type: schema.TypeString, @@ -193,6 +211,7 @@ func schemaFederatedDatabaseInstanceDatabases() *schema.Schema { }, "views": { Type: schema.TypeSet, + Computed: true, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -229,64 +248,79 @@ func schemaFederatedDatabaseInstanceStores() *schema.Schema { Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, + Computed: true, Optional: true, }, "provider": { Type: schema.TypeString, + Computed: true, Optional: true, }, "region": { Type: schema.TypeString, + Computed: true, Optional: true, }, "bucket": { Type: schema.TypeString, + Computed: true, Optional: true, }, "cluster_name": { Type: schema.TypeString, + Computed: true, Optional: true, }, "cluster_id": { Type: schema.TypeString, + Computed: true, Optional: true, Deprecated: fmt.Sprintf(constant.DeprecationParamByDate, "September 2024"), }, "project_id": { Type: schema.TypeString, + Computed: true, Optional: true, }, "prefix": { Type: schema.TypeString, + Computed: true, Optional: true, }, "delimiter": { Type: schema.TypeString, + Computed: true, Optional: true, }, "include_tags": { Type: schema.TypeBool, + Computed: true, Optional: true, }, "allow_insecure": { Type: schema.TypeBool, + Computed: true, Optional: true, }, "additional_storage_classes": { Type: schema.TypeList, + Computed: true, Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, }, "public": { Type: schema.TypeString, + Computed: true, Optional: true, }, "default_format": { Type: schema.TypeString, + Computed: true, Optional: true, }, "urls": { Type: schema.TypeList, + Computed: true, Optional: true, Elem: &schema.Schema{ Type: schema.TypeString, @@ -295,19 +329,23 @@ func schemaFederatedDatabaseInstanceStores() *schema.Schema { "read_preference": { Type: schema.TypeList, MaxItems: 1, + Computed: true, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "mode": { Type: schema.TypeString, + Computed: true, Optional: true, }, "max_staleness_seconds": { Type: schema.TypeInt, + Computed: true, Optional: true, }, "tag_sets": { Type: schema.TypeList, + Computed: true, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -318,10 +356,12 @@ func schemaFederatedDatabaseInstanceStores() *schema.Schema { Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, + Computed: true, Optional: true, }, "value": { Type: schema.TypeString, + Computed: true, Optional: true, }, }, @@ -338,7 +378,7 @@ func schemaFederatedDatabaseInstanceStores() *schema.Schema { } } -func resourceMongoDBFederatedDatabaseInstanceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { +func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { connV2 := meta.(*config.MongoDBClient).AtlasV2 projectID := d.Get("project_id").(string) @@ -358,10 +398,10 @@ func resourceMongoDBFederatedDatabaseInstanceCreate(ctx context.Context, d *sche "name": name, })) - return resourceMongoDBAFederatedDatabaseInstanceRead(ctx, d, meta) + return resourceRead(ctx, d, meta) } -func resourceMongoDBAFederatedDatabaseInstanceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { +func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { connV2 := meta.(*config.MongoDBClient).AtlasV2 ids := conversion.DecodeStateID(d.Id()) projectID := ids["project_id"] @@ -409,7 +449,7 @@ func resourceMongoDBAFederatedDatabaseInstanceRead(ctx context.Context, d *schem return nil } -func resourceMongoDBFederatedDatabaseInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { +func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { connV2 := meta.(*config.MongoDBClient).AtlasV2 ids := conversion.DecodeStateID(d.Id()) @@ -432,10 +472,10 @@ func resourceMongoDBFederatedDatabaseInstanceUpdate(ctx context.Context, d *sche return diag.FromErr(fmt.Errorf(errorFederatedDatabaseInstanceUpdate, name, err)) } - return resourceMongoDBAFederatedDatabaseInstanceRead(ctx, d, meta) + return resourceRead(ctx, d, meta) } -func resourceMongoDBAtlasFederatedDatabaseInstanceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { +func resourceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { connV2 := meta.(*config.MongoDBClient).AtlasV2 ids := conversion.DecodeStateID(d.Id()) @@ -449,7 +489,7 @@ func resourceMongoDBAtlasFederatedDatabaseInstanceDelete(ctx context.Context, d return nil } -func resourceMongoDBAtlasFederatedDatabaseInstanceImportState(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { +func resourceImport(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { connV2 := meta.(*config.MongoDBClient).AtlasV2 projectID, name, s3Bucket, err := splitDataFederatedInstanceImportID(d.Id()) @@ -528,17 +568,16 @@ func resourceMongoDBAtlasFederatedDatabaseInstanceImportState(ctx context.Contex func newDataFederationStorage(d *schema.ResourceData) *admin.DataLakeStorage { return &admin.DataLakeStorage{ - Databases: conversion.NonEmptyToPtr(newDataFederationDatabase(d)), - Stores: conversion.NonEmptyToPtr(newStores(d)), + Databases: newDataFederationDatabase(d), + Stores: newStores(d), } } -func newStores(d *schema.ResourceData) []admin.DataLakeStoreSettings { +func newStores(d *schema.ResourceData) *[]admin.DataLakeStoreSettings { storesFromConf := d.Get("storage_stores").(*schema.Set).List() if len(storesFromConf) == 0 { - return nil + return new([]admin.DataLakeStoreSettings) } - stores := make([]admin.DataLakeStoreSettings, len(storesFromConf)) for i, storeFromConf := range storesFromConf { storeFromConfMap := storeFromConf.(map[string]any) @@ -552,25 +591,22 @@ func newStores(d *schema.ResourceData) []admin.DataLakeStoreSettings { Prefix: conversion.StringPtr(storeFromConfMap["prefix"].(string)), Delimiter: conversion.StringPtr(storeFromConfMap["delimiter"].(string)), IncludeTags: conversion.Pointer(storeFromConfMap["include_tags"].(bool)), - AdditionalStorageClasses: conversion.NonEmptyToPtr(newAdditionalStorageClasses(storeFromConfMap["additional_storage_classes"].([]any))), + AdditionalStorageClasses: newAdditionalStorageClasses(storeFromConfMap["additional_storage_classes"].([]any)), ReadPreference: newReadPreference(storeFromConfMap), } } - - return stores + return &stores } -func newAdditionalStorageClasses(additionalStorageClassesFromConfig []any) []string { +func newAdditionalStorageClasses(additionalStorageClassesFromConfig []any) *[]string { if len(additionalStorageClassesFromConfig) == 0 { - return nil + return new([]string) } - additionalStorageClasses := make([]string, len(additionalStorageClassesFromConfig)) for i, additionalStorageClassFromConfig := range additionalStorageClassesFromConfig { additionalStorageClasses[i] = additionalStorageClassFromConfig.(string) } - - return additionalStorageClasses + return &additionalStorageClasses } func newReadPreference(storeFromConfMap map[string]any) *admin.DataLakeAtlasStoreReadPreference { @@ -582,83 +618,72 @@ func newReadPreference(storeFromConfMap map[string]any) *admin.DataLakeAtlasStor return &admin.DataLakeAtlasStoreReadPreference{ Mode: conversion.StringPtr(readPreferenceFromConfMap["mode"].(string)), MaxStalenessSeconds: conversion.IntPtr(readPreferenceFromConfMap["max_staleness_seconds"].(int)), - TagSets: conversion.NonEmptyToPtr(newTagSets(readPreferenceFromConfMap)), + TagSets: newTagSets(readPreferenceFromConfMap), } } -func newTagSets(readPreferenceFromConfMap map[string]any) [][]admin.DataLakeAtlasStoreReadPreferenceTag { - var res [][]admin.DataLakeAtlasStoreReadPreferenceTag - +func newTagSets(readPreferenceFromConfMap map[string]any) *[][]admin.DataLakeAtlasStoreReadPreferenceTag { tagSetsFromConf, ok := readPreferenceFromConfMap["tag_sets"].([]any) if !ok || len(tagSetsFromConf) == 0 { - return nil + return new([][]admin.DataLakeAtlasStoreReadPreferenceTag) } - + var res [][]admin.DataLakeAtlasStoreReadPreferenceTag for ts := 0; ts < len(tagSetsFromConf); ts++ { tagSetFromConfMap := tagSetsFromConf[ts].(map[string]any) tagsFromConfigMap := tagSetFromConfMap["tags"].([]any) var atlastags []admin.DataLakeAtlasStoreReadPreferenceTag - for t := 0; t < len(tagsFromConfigMap); t++ { tagFromConfMap := tagsFromConfigMap[t].(map[string]any) - atlastags = append(atlastags, admin.DataLakeAtlasStoreReadPreferenceTag{ Name: conversion.StringPtr(tagFromConfMap["name"].(string)), Value: conversion.StringPtr(tagFromConfMap["value"].(string)), }) } - res = append(res, atlastags) } - return res + return &res } -func newDataFederationDatabase(d *schema.ResourceData) []admin.DataLakeDatabaseInstance { +func newDataFederationDatabase(d *schema.ResourceData) *[]admin.DataLakeDatabaseInstance { storageDBsFromConf := d.Get("storage_databases").(*schema.Set).List() if len(storageDBsFromConf) == 0 { - return nil + return new([]admin.DataLakeDatabaseInstance) } - dbs := make([]admin.DataLakeDatabaseInstance, len(storageDBsFromConf)) for i, storageDBFromConf := range storageDBsFromConf { storageDBFromConfMap := storageDBFromConf.(map[string]any) - dbs[i] = admin.DataLakeDatabaseInstance{ Name: conversion.StringPtr(storageDBFromConfMap["name"].(string)), MaxWildcardCollections: conversion.IntPtr(storageDBFromConfMap["max_wildcard_collections"].(int)), - Collections: conversion.NonEmptyToPtr(newDataFederationCollections(storageDBFromConfMap)), + Collections: newDataFederationCollections(storageDBFromConfMap), } } - - return dbs + return &dbs } -func newDataFederationCollections(storageDBFromConfMap map[string]any) []admin.DataLakeDatabaseCollection { +func newDataFederationCollections(storageDBFromConfMap map[string]any) *[]admin.DataLakeDatabaseCollection { collectionsFromConf := storageDBFromConfMap["collections"].(*schema.Set).List() if len(collectionsFromConf) == 0 { - return nil + return new([]admin.DataLakeDatabaseCollection) } - collections := make([]admin.DataLakeDatabaseCollection, len(collectionsFromConf)) for i, collectionFromConf := range collectionsFromConf { collections[i] = admin.DataLakeDatabaseCollection{ Name: conversion.StringPtr(collectionFromConf.(map[string]any)["name"].(string)), - DataSources: conversion.NonEmptyToPtr(newDataFederationDataSource(collectionFromConf.(map[string]any))), + DataSources: newDataFederationDataSource(collectionFromConf.(map[string]any)), } } - - return collections + return &collections } -func newDataFederationDataSource(collectionFromConf map[string]any) []admin.DataLakeDatabaseDataSourceSettings { +func newDataFederationDataSource(collectionFromConf map[string]any) *[]admin.DataLakeDatabaseDataSourceSettings { dataSourcesFromConf := collectionFromConf["data_sources"].(*schema.Set).List() if len(dataSourcesFromConf) == 0 { - return nil + return new([]admin.DataLakeDatabaseDataSourceSettings) } dataSources := make([]admin.DataLakeDatabaseDataSourceSettings, len(dataSourcesFromConf)) for i, dataSourceFromConf := range dataSourcesFromConf { dataSourceFromConfMap := dataSourceFromConf.(map[string]any) - dataSources[i] = admin.DataLakeDatabaseDataSourceSettings{ AllowInsecure: conversion.Pointer(dataSourceFromConfMap["allow_insecure"].(bool)), Database: conversion.StringPtr(dataSourceFromConfMap["database"].(string)), @@ -670,24 +695,21 @@ func newDataFederationDataSource(collectionFromConf map[string]any) []admin.Data ProvenanceFieldName: conversion.StringPtr(dataSourceFromConfMap["provenance_field_name"].(string)), StoreName: conversion.StringPtr(dataSourceFromConfMap["store_name"].(string)), DatasetName: conversion.StringPtr(dataSourceFromConfMap["dataset_name"].(string)), - Urls: conversion.NonEmptyToPtr(newUrls(dataSourceFromConfMap["urls"].([]any))), + Urls: newUrls(dataSourceFromConfMap["urls"].([]any)), } } - - return dataSources + return &dataSources } -func newUrls(urlsFromConfig []any) []string { +func newUrls(urlsFromConfig []any) *[]string { if len(urlsFromConfig) == 0 { - return nil + return new([]string) } - urls := make([]string, len(urlsFromConfig)) for i, urlFromConfig := range urlsFromConfig { urls[i] = urlFromConfig.(string) } - - return urls + return &urls } func newCloudProviderConfig(d *schema.ResourceData) *admin.DataLakeCloudProviderConfig { diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance_migration_test.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance_migration_test.go new file mode 100644 index 0000000000..95a1c27ac6 --- /dev/null +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance_migration_test.go @@ -0,0 +1,49 @@ +package federateddatabaseinstance_test + +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/plancheck" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig" +) + +func TestAccMigrationFederatedDatabaseInstance_basic(t *testing.T) { + var ( + resourceName = "mongodbatlas_federated_database_instance.test" + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") + name = acctest.RandomWithPrefix("test-acc") + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { mig.PreCheckBasic(t) }, + CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, + Steps: []resource.TestStep{ + { + ExternalProviders: mig.ExternalProviders(), + 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"), + ), + }, + { + ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, + Config: configFirstSteps(name, projectName, orgID), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + }, + }) +} diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance_test.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance_test.go index e55410f558..c8e9d3c329 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance_test.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance_test.go @@ -27,7 +27,7 @@ func TestAccFederatedDatabaseInstance_basic(t *testing.T) { CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasFederatedDatabaseInstanceConfigFirstSteps(name, projectName, orgID), + Config: configFirstSteps(name, projectName, orgID), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttr(resourceName, "name", name), @@ -38,7 +38,7 @@ func TestAccFederatedDatabaseInstance_basic(t *testing.T) { ), }, { - Config: testAccMongoDBAtlasFederatedDatabaseInstanceConfigFirstStepsUpdate(name, projectName, orgID), + Config: configFirstStepsUpdate(name, projectName, orgID), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttr(resourceName, "name", name), @@ -50,14 +50,14 @@ func TestAccFederatedDatabaseInstance_basic(t *testing.T) { }, { ResourceName: resourceName, - ImportStateIdFunc: testAccCheckMongoDBAtlasFederatedDatabaseInstanceImportStateIDFunc(resourceName), + ImportStateIdFunc: importStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"storage_stores.0.allow_insecure", "storage_stores.0.include_tags", "storage_stores.0.read_preference.0.max_staleness_seconds", "storage_stores.1.allow_insecure", "storage_stores.1.include_tags", "storage_stores.1.read_preference.0.max_staleness_seconds"}, }, { - Config: testAccMongoDBAtlasFederatedDatabaseInstanceConfigFirstStepsUpdate(name, projectName, orgID), + Config: configFirstStepsUpdate(name, projectName, orgID), ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ acc.DebugPlan(), @@ -69,27 +69,26 @@ func TestAccFederatedDatabaseInstance_basic(t *testing.T) { }) } -func TestAccFederatedDatabaseInstance_S3bucket(t *testing.T) { - acc.SkipTestExtCred(t) +func TestAccFederatedDatabaseInstance_s3bucket(t *testing.T) { var ( resourceName = "mongodbatlas_federated_database_instance.test" orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") projectName = acctest.RandomWithPrefix("test-acc") name = acctest.RandomWithPrefix("test-acc") policyName = acctest.RandomWithPrefix("test-acc") - roleName = acctest.RandomWithPrefix("test-acc") + roleName = acctest.RandomWithPrefix("mongodb-atlas-test-acc-fed") testS3Bucket = os.Getenv("AWS_S3_BUCKET") region = "VIRGINIA_USA" ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheckBasic(t) }, + PreCheck: func() { acc.PreCheckBasic(t); acc.PreCheckS3Bucket(t) }, CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance, Steps: []resource.TestStep{ { ExternalProviders: acc.ExternalProvidersOnlyAWS(), ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - Config: testAccMongoDBAtlasFederatedDatabaseInstanceConfigS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, region), + Config: configWithS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, region), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttr(resourceName, "name", name), @@ -98,7 +97,7 @@ func TestAccFederatedDatabaseInstance_S3bucket(t *testing.T) { { ResourceName: resourceName, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - ImportStateIdFunc: testAccCheckMongoDBAtlasFederatedDatabaseInstanceImportStateIDFuncS3Bucket(resourceName, testS3Bucket), + ImportStateIdFunc: importStateIDFuncS3Bucket(resourceName, testS3Bucket), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +119,7 @@ func TestAccFederatedDatabaseInstance_atlasCluster(t *testing.T) { Steps: []resource.TestStep{ { ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - Config: testAccMongoDBAtlasFederatedDatabaseInstanceAtlasProviderConfig(projectName, orgID, name), + Config: configWithCluster(projectName, orgID, name), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttr(resourceName, "name", name), @@ -133,7 +132,7 @@ func TestAccFederatedDatabaseInstance_atlasCluster(t *testing.T) { }) } -func testAccMongoDBAtlasFederatedDatabaseInstanceAtlasProviderConfig(projectName, orgID, name string) string { +func configWithCluster(projectName, orgID, name string) string { return fmt.Sprintf(` resource "mongodbatlas_project" "project-tf" { name = %[1]q @@ -243,7 +242,7 @@ func testAccMongoDBAtlasFederatedDatabaseInstanceAtlasProviderConfig(projectName `, projectName, orgID, name) } -func testAccCheckMongoDBAtlasFederatedDatabaseInstanceImportStateIDFuncS3Bucket(resourceName, s3Bucket string) resource.ImportStateIdFunc { +func importStateIDFuncS3Bucket(resourceName, s3Bucket string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -256,7 +255,7 @@ func testAccCheckMongoDBAtlasFederatedDatabaseInstanceImportStateIDFuncS3Bucket( } } -func testAccCheckMongoDBAtlasFederatedDatabaseInstanceImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func importStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -269,8 +268,8 @@ func testAccCheckMongoDBAtlasFederatedDatabaseInstanceImportStateIDFunc(resource } } -func testAccMongoDBAtlasFederatedDatabaseInstanceConfigS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, dataLakeRegion string) string { - stepConfig := testAccMongoDBAtlasFederatedDatabaseInstanceConfigFirstSteps3Bucket(name, testS3Bucket) +func configWithS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, dataLakeRegion string) string { + stepConfig := configFirstStepS3Bucket(name, testS3Bucket) return fmt.Sprintf(` resource "aws_iam_role_policy" "test_policy" { name = %[1]q @@ -337,7 +336,8 @@ resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" { %s `, policyName, roleName, projectName, orgID, stepConfig) } -func testAccMongoDBAtlasFederatedDatabaseInstanceConfigFirstSteps3Bucket(name, testS3Bucket string) string { + +func configFirstStepS3Bucket(name, testS3Bucket string) string { return fmt.Sprintf(` resource "mongodbatlas_federated_database_instance" "test" { project_id = mongodbatlas_project.test.id @@ -399,7 +399,7 @@ resource "mongodbatlas_federated_database_instance" "test" { `, name, testS3Bucket) } -func testAccMongoDBAtlasFederatedDatabaseInstanceConfigFirstSteps(federatedInstanceName, projectName, orgID string) string { +func configFirstSteps(federatedInstanceName, projectName, orgID string) string { return fmt.Sprintf(` resource "mongodbatlas_project" "test" { @@ -486,7 +486,7 @@ resource "mongodbatlas_federated_database_instance" "test" { `, federatedInstanceName, projectName, orgID) } -func testAccMongoDBAtlasFederatedDatabaseInstanceConfigFirstStepsUpdate(federatedInstanceName, projectName, orgID string) string { +func configFirstStepsUpdate(federatedInstanceName, projectName, orgID string) string { return fmt.Sprintf(` resource "mongodbatlas_project" "test" { 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 3a5d8effca..ad6352f60f 100644 --- a/internal/service/federatedquerylimit/data_source_federated_query_limit_test.go +++ b/internal/service/federatedquerylimit/data_source_federated_query_limit_test.go @@ -33,7 +33,7 @@ func TestAccDataSourceFederatedDatabaseQueryLimit_basic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t) }, + PreCheck: func() { acc.PreCheck(t); acc.PreCheckS3Bucket(t) }, CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseQueryLimitDestroy, Steps: []resource.TestStep{ { diff --git a/internal/service/federatedquerylimit/data_source_federated_query_limits_test.go b/internal/service/federatedquerylimit/data_source_federated_query_limits_test.go index 8c55d1903d..bd08afea4f 100644 --- a/internal/service/federatedquerylimit/data_source_federated_query_limits_test.go +++ b/internal/service/federatedquerylimit/data_source_federated_query_limits_test.go @@ -24,7 +24,7 @@ func TestAccDataSourceFederatedDatabaseQueryLimits_basic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t) }, + PreCheck: func() { acc.PreCheck(t); acc.PreCheckS3Bucket(t) }, CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseQueryLimitDestroy, Steps: []resource.TestStep{ { diff --git a/internal/service/federatedquerylimit/resource_federated_query_limit_test.go b/internal/service/federatedquerylimit/resource_federated_query_limit_test.go index c1c3c25b94..b7669361d8 100644 --- a/internal/service/federatedquerylimit/resource_federated_query_limit_test.go +++ b/internal/service/federatedquerylimit/resource_federated_query_limit_test.go @@ -29,7 +29,7 @@ func TestAccFederatedDatabaseQueryLimit_basic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t) }, + PreCheck: func() { acc.PreCheck(t); acc.PreCheckS3Bucket(t) }, CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseQueryLimitDestroy, Steps: []resource.TestStep{ { diff --git a/internal/testutil/acc/pre_check.go b/internal/testutil/acc/pre_check.go index af6454b6a2..c4881dc97a 100644 --- a/internal/testutil/acc/pre_check.go +++ b/internal/testutil/acc/pre_check.go @@ -229,3 +229,10 @@ func PreCheckPrivateEndpointServiceDataFederationOnlineArchiveRun(tb testing.TB) tb.Skip("`MONGODB_ATLAS_PRIVATE_ENDPOINT_ID` must be set for Private Endpoint Service Data Federation and Online Archive acceptance testing") } } + +func PreCheckS3Bucket(tb testing.TB) { + tb.Helper() + if os.Getenv("AWS_S3_BUCKET") == "" { + tb.Fatal("`AWS_S3_BUCKET` must be set ") + } +}