From 0861142694494374cc6c1f06615702e27ec74ed6 Mon Sep 17 00:00:00 2001 From: Andrea Angiolillo Date: Fri, 23 Jun 2023 10:52:17 +0200 Subject: [PATCH] INTMDB-879: [Terraform] Improve acceptance test setup to run in parallel & against cloud-dev - Config (#1263) --- .github/workflows/acceptance-tests.yml | 98 ++++++--- .../workflows/automated-test-acceptances.yml | 31 +-- ...ce_mongodbatlas_accesslist_api_key_test.go | 6 +- ...e_mongodbatlas_accesslist_api_keys_test.go | 6 +- ...e_mongodbatlas_alert_configuration_test.go | 43 ++-- ..._mongodbatlas_alert_configurations_test.go | 20 +- .../data_source_mongodbatlas_api_key_test.go | 6 +- .../data_source_mongodbatlas_api_keys_test.go | 6 +- ...batlas_cloud_provider_access_setup_test.go | 26 +-- ...mongodbatlas_cloud_provider_access_test.go | 20 +- ...source_mongodbatlas_custom_db_role_test.go | 27 +-- ...ource_mongodbatlas_custom_db_roles_test.go | 28 +-- ...stom_dns_configuration_cluster_aws_test.go | 20 +- ..._source_mongodbatlas_database_user_test.go | 21 +- ...source_mongodbatlas_database_users_test.go | 36 ++-- ..._source_mongodbatlas_event_trigger_test.go | 2 +- ...source_mongodbatlas_event_triggers_test.go | 4 +- ...ce_mongodbatlas_maintenance_window_test.go | 24 ++- .../data_source_mongodbatlas_org_id_test.go | 4 +- ...source_mongodbatlas_org_invitation_test.go | 4 +- ...a_source_mongodbatlas_organization_test.go | 2 +- ..._source_mongodbatlas_organizations_test.go | 4 +- ...ource_mongodbatlas_project_api_key_test.go | 26 +-- ...urce_mongodbatlas_project_api_keys_test.go | 30 +-- ...a_source_mongodbatlas_search_index_test.go | 54 ----- ...source_mongodbatlas_search_indexes_test.go | 104 ---------- .../data_source_mongodbatlas_team_test.go | 8 +- ...ngodbatlas_third_party_integration_test.go | 2 +- ...godbatlas_third_party_integrations_test.go | 2 +- ...e_mongodbatlas_alert_configuration_test.go | 186 +++++++++++------- .../resource_mongodbatlas_api_key_test.go | 10 +- ...batlas_cloud_provider_access_setup_test.go | 26 ++- ...mongodbatlas_cloud_provider_access_test.go | 36 ++-- ...source_mongodbatlas_custom_db_role_test.go | 160 +++++++-------- ...stom_dns_configuration_cluster_aws_test.go | 31 +-- ...esource_mongodbatlas_database_user_test.go | 26 +-- ...esource_mongodbatlas_event_trigger_test.go | 16 +- ...ce_mongodbatlas_maintenance_window_test.go | 84 ++++---- ...source_mongodbatlas_org_invitation_test.go | 7 +- ...resource_mongodbatlas_organization_test.go | 4 +- ...ource_mongodbatlas_project_api_key_test.go | 59 +++--- ...resource_mongodbatlas_search_index_test.go | 92 +++++++-- .../resource_mongodbatlas_team_test.go | 26 ++- ...ngodbatlas_third_party_integration_test.go | 6 +- 44 files changed, 713 insertions(+), 720 deletions(-) delete mode 100644 mongodbatlas/data_source_mongodbatlas_search_index_test.go delete mode 100644 mongodbatlas/data_source_mongodbatlas_search_indexes_test.go diff --git a/.github/workflows/acceptance-tests.yml b/.github/workflows/acceptance-tests.yml index 28b949d88b..a66e759a1b 100644 --- a/.github/workflows/acceptance-tests.yml +++ b/.github/workflows/acceptance-tests.yml @@ -27,6 +27,7 @@ jobs: project: ${{ steps.filter.outputs.project }} serverless: ${{ steps.filter.outputs.serverless }} network: ${{ steps.filter.outputs.network }} + config: ${{ steps.filter.outputs.config }} steps: - uses: actions/checkout@v3 if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'}} @@ -57,7 +58,20 @@ jobs: network: - 'mongodbatlas/**_network**.go' - 'mongodbatlas/**_privatelink**.go' - - 'mongodbatlas/**_private_endpoint**.go' + - 'mongodbatlas/**_private_endpoint**.go' + config: + - 'mongodbatlas/**_accesslist**.go' + - 'mongodbatlas/**_alert_configuration**.go' + - 'mongodbatlas/**_api_key**.go' + - 'mongodbatlas/**_cloud_provider**.go' + - 'mongodbatlas/**_custom_**.go' + - 'mongodbatlas/**_database_user**.go' + - 'mongodbatlas/**_maintenance**.go' + - 'mongodbatlas/**_org_**.go' + - 'mongodbatlas/**_organization**.go' + - 'mongodbatlas/**_project**.go' + - 'mongodbatlas/**_search_**.go' + - 'mongodbatlas/**_team_**.go' cluster_outage_simulation: needs: [ change-detection ] @@ -236,35 +250,37 @@ jobs: TF_LOG: ${{ vars.LOG_LEVEL }} TF_ACC: 1 PARALLEL_GO_TEST: 20 + CI: true TEST_REGEX: "^TestAccBackupRSCloudBackupSchedule" run: make testacc project: - needs: [ change-detection ] - if: ${{ needs.change-detection.outputs.project == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" - - name: Acceptance Tests - env: - MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }} - MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }} - MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }} - MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }} - MONGODB_ATLAS_PROJECT_OWNER_ID: ${{ vars.MONGODB_ATLAS_PROJECT_OWNER_ID }} - MONGODB_ATLAS_API_KEYS_IDS: ${{ vars.MONGODB_ATLAS_API_KEYS_IDS }} - MONGODB_ATLAS_TEAMS_IDS: ${{ vars.MONGODB_ATLAS_TEAMS_IDS }} - SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }} - ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }} - TF_LOG: ${{ vars.LOG_LEVEL }} - TF_ACC: 1 - PARALLEL_GO_TEST: 20 - TEST_REGEX: "^TestAccProject" - run: make testacc + needs: [ change-detection ] + if: ${{ needs.change-detection.outputs.project == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.20" + - name: Acceptance Tests + env: + MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }} + MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }} + MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }} + MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }} + MONGODB_ATLAS_PROJECT_OWNER_ID: ${{ vars.MONGODB_ATLAS_PROJECT_OWNER_ID }} + MONGODB_ATLAS_API_KEYS_IDS: ${{ vars.MONGODB_ATLAS_API_KEYS_IDS }} + MONGODB_ATLAS_TEAMS_IDS: ${{ vars.MONGODB_ATLAS_TEAMS_IDS }} + SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }} + ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }} + TF_LOG: ${{ vars.LOG_LEVEL }} + TF_ACC: 1 + PARALLEL_GO_TEST: 20 + CI: true + TEST_REGEX: "^TestAccProject" + run: make testacc serverless: needs: [ change-detection ] if: ${{ needs.change-detection.outputs.serverless == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }} @@ -287,6 +303,7 @@ jobs: TF_LOG: ${{ vars.LOG_LEVEL }} TF_ACC: 1 PARALLEL_GO_TEST: 20 + CI: true TEST_REGEX: "^TestAccServerless" run: make testacc network: @@ -315,5 +332,32 @@ jobs: TF_LOG: ${{ vars.LOG_LEVEL }} TF_ACC: 1 PARALLEL_GO_TEST: 20 + CI: true TEST_REGEX: "^TestAccNetwork" run: make testacc + config: + needs: [ change-detection ] + if: ${{ needs.change-detection.outputs.config == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.20" + - name: Acceptance Tests + env: + MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV_NETWORK }} + MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV_NETWORK }} + MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV_NETWORK }} + MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }} + SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }} + MONGODB_ATLAS_USERNAME_CLOUD_DEV: ${{ vars.MONGODB_ATLAS_USERNAME_CLOUD_DEV }} + ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }} + TF_LOG: ${{ vars.LOG_LEVEL }} + TF_ACC: 1 + PARALLEL_GO_TEST: 20 + CI: true + TEST_REGEX: "^TestAccConfig" + run: make testacc diff --git a/.github/workflows/automated-test-acceptances.yml b/.github/workflows/automated-test-acceptances.yml index d75dcc8ab2..2242a63b8d 100644 --- a/.github/workflows/automated-test-acceptances.yml +++ b/.github/workflows/automated-test-acceptances.yml @@ -55,36 +55,6 @@ jobs: TEST_REGEX: "^TestAccAdv" run: make testacc - acceptance-tests-config: - if: ${{ github.event.label.name == 'run-testacc' || github.event.label.name == 'run-testacc-project-config' || github.ref == 'refs/heads/master' }} - needs: [ authorize ] - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" - - name: Acceptance Tests - env: - MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY }} - MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY }} - MONGODB_ATLAS_PROJECT_ID: ${{ secrets.MONGODB_ATLAS_PROJECT_ID }} - MONGODB_ATLAS_ORG_ID: ${{ secrets.MONGODB_ATLAS_ORG_ID }} - MONGODB_ATLAS_DB_USERNAME: ${{ secrets.MONGODB_ATLAS_DB_USERNAME }} - MONGODB_ATLAS_TEAMS_IDS: ${{ secrets.MONGODB_ATLAS_TEAMS_IDS }} - CA_CERT: ${{ secrets.CA_CERT }} - MONGODB_ATLAS_API_KEYS_IDS: ${{ secrets.MONGODB_ATLAS_API_KEYS_IDS }} - MONGODB_ATLAS_NETWORK_PROJECT_ID: ${{ secrets.MONGODB_ATLAS_NETWORK_PROJECT_ID }} - SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }} - SKIP_TEST: ${{ vars.SKIP_TEST }} - AWS_REGION: ${{ vars.AWS_REGION }} - MONGODB_ATLAS_ENABLE_BETA: ${{ vars.MONGODB_ATLAS_ENABLE_BETA }} - ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }} - TEST_REGEX: "^TestAccConfig" - run: make testacc - acceptance-tests-gov: if: ${{ github.event.label.name == 'run-testacc-gov' }} needs: [ authorize ] @@ -107,6 +77,7 @@ jobs: CA_CERT: ${{ secrets.CA_CERT }} MONGODB_ATLAS_API_KEYS_IDS: ${{ secrets.MONGODB_ATLAS_API_KEYS_IDS }} MONGODB_ATLAS_PROJECT_OWNER_ID_GOV: ${{ secrets.MONGODB_ATLAS_PROJECT_OWNER_ID_GOV }} + MONGODB_ATLAS_USERNAME_CLOUD_DEV: ${{ vars.MONGODB_ATLAS_USERNAME_CLOUD_DEV }} SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }} SKIP_TEST: ${{ vars.SKIP_TEST }} AWS_REGION: ${{ vars.AWS_REGION_GOV }} diff --git a/mongodbatlas/data_source_mongodbatlas_accesslist_api_key_test.go b/mongodbatlas/data_source_mongodbatlas_accesslist_api_key_test.go index a406efc70b..0c05ff271a 100644 --- a/mongodbatlas/data_source_mongodbatlas_accesslist_api_key_test.go +++ b/mongodbatlas/data_source_mongodbatlas_accesslist_api_key_test.go @@ -16,10 +16,10 @@ func TestAccConfigDSAccesslistAPIKey_basic(t *testing.T) { description := fmt.Sprintf("test-acc-accesslist-api_key-%s", acctest.RandString(5)) ipAddress := fmt.Sprintf("179.154.226.%d", acctest.RandIntRange(0, 255)) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, - //CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy, + CheckDestroy: testAccCheckMongoDBAtlasAccessListAPIKeyDestroy, Steps: []resource.TestStep{ { Config: testAccDSMongoDBAtlasAccesslistAPIKeyConfig(orgID, description, ipAddress), diff --git a/mongodbatlas/data_source_mongodbatlas_accesslist_api_keys_test.go b/mongodbatlas/data_source_mongodbatlas_accesslist_api_keys_test.go index 26e1542c79..60836ed773 100644 --- a/mongodbatlas/data_source_mongodbatlas_accesslist_api_keys_test.go +++ b/mongodbatlas/data_source_mongodbatlas_accesslist_api_keys_test.go @@ -16,10 +16,10 @@ func TestAccConfigDSAccesslistAPIKeys_basic(t *testing.T) { description := fmt.Sprintf("test-acc-accesslist-api_keys-%s", acctest.RandString(5)) ipAddress := fmt.Sprintf("179.154.226.%d", acctest.RandIntRange(0, 255)) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, - //CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy, + CheckDestroy: testAccCheckMongoDBAtlasAccessListAPIKeyDestroy, Steps: []resource.TestStep{ { Config: testAccDSMongoDBAtlasAccesslistAPIKeysConfig(orgID, description, ipAddress), diff --git a/mongodbatlas/data_source_mongodbatlas_alert_configuration_test.go b/mongodbatlas/data_source_mongodbatlas_alert_configuration_test.go index 925f47bf26..f1583a7429 100644 --- a/mongodbatlas/data_source_mongodbatlas_alert_configuration_test.go +++ b/mongodbatlas/data_source_mongodbatlas_alert_configuration_test.go @@ -5,6 +5,7 @@ import ( "os" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -13,16 +14,17 @@ func TestAccConfigDSAlertConfiguration_basic(t *testing.T) { var ( alert = &matlas.AlertConfiguration{} dataSourceName = "data.mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccDSMongoDBAtlasAlertConfiguration(projectID), + Config: testAccDSMongoDBAtlasAlertConfiguration(orgID, projectName), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(dataSourceName, alert), resource.TestCheckResourceAttrSet(dataSourceName, "project_id"), @@ -36,16 +38,17 @@ func TestAccConfigDSAlertConfiguration_withThreshold(t *testing.T) { var ( alert = &matlas.AlertConfiguration{} dataSourceName = "data.mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold(projectID, true, 1), + Config: testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold(orgID, projectName, true, 1), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(dataSourceName, alert), resource.TestCheckResourceAttrSet(dataSourceName, "project_id"), @@ -80,10 +83,14 @@ func TestAccConfigDSAlertConfiguration_withPagerDuty(t *testing.T) { }) } -func testAccDSMongoDBAtlasAlertConfiguration(projectID string) string { +func testAccDSMongoDBAtlasAlertConfiguration(orgID, projectName string) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_alert_configuration" "test" { - project_id = "%s" + project_id = mongodbatlas_project.test.id event_type = "OUTSIDE_METRIC_THRESHOLD" enabled = true @@ -114,15 +121,19 @@ func testAccDSMongoDBAtlasAlertConfiguration(projectID string) string { project_id = "${mongodbatlas_alert_configuration.test.project_id}" alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}" } - `, projectID) + `, orgID, projectName) } -func testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold(projectID string, enabled bool, threshold float64) string { +func testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold(orgID, projectName string, enabled bool, threshold float64) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_alert_configuration" "test" { - project_id = "%s" + project_id = mongodbatlas_project.test.id event_type = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT" - enabled = "%t" + enabled = "%[3]t" notification { type_name = "GROUP" @@ -142,7 +153,7 @@ func testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold(projectID string threshold_config { operator = "LESS_THAN" units = "HOURS" - threshold = %f + threshold = %[4]f } } @@ -150,7 +161,7 @@ func testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold(projectID string project_id = "${mongodbatlas_alert_configuration.test.project_id}" alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}" } - `, projectID, enabled, threshold) + `, orgID, projectName, enabled, threshold) } func testAccDSMongoDBAtlasAlertConfigurationConfigWithPagerDuty(projectID, serviceKey string, enabled bool) string { diff --git a/mongodbatlas/data_source_mongodbatlas_alert_configurations_test.go b/mongodbatlas/data_source_mongodbatlas_alert_configurations_test.go index 8cd264a995..a735fab41b 100644 --- a/mongodbatlas/data_source_mongodbatlas_alert_configurations_test.go +++ b/mongodbatlas/data_source_mongodbatlas_alert_configurations_test.go @@ -7,6 +7,7 @@ import ( "strconv" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" matlas "go.mongodb.org/atlas/mongodbatlas" @@ -15,15 +16,16 @@ import ( func TestAccConfigDSAlertConfigurations_basic(t *testing.T) { var ( dataSourceName = "data.mongodbatlas_alert_configurations.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { - Config: testAccDSMongoDBAtlasAlertConfigurations(projectID), + Config: testAccDSMongoDBAtlasAlertConfigurations(orgID, projectName), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationsCount(dataSourceName), resource.TestCheckResourceAttrSet(dataSourceName, "project_id"), @@ -33,16 +35,20 @@ func TestAccConfigDSAlertConfigurations_basic(t *testing.T) { }) } -func testAccDSMongoDBAtlasAlertConfigurations(projectID string) string { +func testAccDSMongoDBAtlasAlertConfigurations(orgID, projectName string) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } data "mongodbatlas_alert_configurations" "test" { - project_id = "%s" + project_id = mongodbatlas_project.test.id list_options { page_num = 0 } } - `, projectID) + `, orgID, projectName) } func testAccCheckMongoDBAtlasAlertConfigurationsCount(resourceName string) resource.TestCheckFunc { diff --git a/mongodbatlas/data_source_mongodbatlas_api_key_test.go b/mongodbatlas/data_source_mongodbatlas_api_key_test.go index dd0e21a275..bab2734d62 100644 --- a/mongodbatlas/data_source_mongodbatlas_api_key_test.go +++ b/mongodbatlas/data_source_mongodbatlas_api_key_test.go @@ -16,10 +16,10 @@ func TestAccConfigDSAPIKey_basic(t *testing.T) { description := fmt.Sprintf("test-acc-api_key-%s", acctest.RandString(5)) roleName := "ORG_MEMBER" - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, - //CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy, + CheckDestroy: testAccCheckMongoDBAtlasAPIKeyDestroy, Steps: []resource.TestStep{ { Config: testAccDSMongoDBAtlasAPIKeyConfig(orgID, description, roleName), diff --git a/mongodbatlas/data_source_mongodbatlas_api_keys_test.go b/mongodbatlas/data_source_mongodbatlas_api_keys_test.go index eb846dbcd0..1a7c00802b 100644 --- a/mongodbatlas/data_source_mongodbatlas_api_keys_test.go +++ b/mongodbatlas/data_source_mongodbatlas_api_keys_test.go @@ -16,10 +16,10 @@ func TestAccConfigDSAPIKeys_basic(t *testing.T) { description := fmt.Sprintf("test-acc-api_key-%s", acctest.RandString(5)) roleName := "ORG_MEMBER" - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, - //CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy, + CheckDestroy: testAccCheckMongoDBAtlasAPIKeyDestroy, Steps: []resource.TestStep{ { Config: testAccDSMongoDBAtlasAPIKeysConfig(orgID, description, roleName), diff --git a/mongodbatlas/data_source_mongodbatlas_cloud_provider_access_setup_test.go b/mongodbatlas/data_source_mongodbatlas_cloud_provider_access_setup_test.go index 2efd374e15..4b5775b072 100644 --- a/mongodbatlas/data_source_mongodbatlas_cloud_provider_access_setup_test.go +++ b/mongodbatlas/data_source_mongodbatlas_cloud_provider_access_setup_test.go @@ -13,14 +13,18 @@ import ( const ( dataSourceCPASProviderConfig = ` + resource "mongodbatlas_project" "test" { + name = %[3]q + org_id = %[2]q + } resource "mongodbatlas_cloud_provider_access_setup" "%[1]s" { - project_id = "%[2]s" - provider_name = "%[3]s" + project_id = mongodbatlas_project.test.id + provider_name = %[4]q } - data "mongodbatlas_cloud_provider_access_setup" "%[4]s" { + data "mongodbatlas_cloud_provider_access_setup" "%[5]s" { project_id = mongodbatlas_cloud_provider_access_setup.%[1]s.project_id - provider_name = "%[3]s" + provider_name = %[4]q role_id = mongodbatlas_cloud_provider_access_setup.%[1]s.role_id } ` @@ -28,20 +32,21 @@ const ( func TestAccConfigDSCloudProviderAccessSetup_aws_basic(t *testing.T) { var ( - suffix = acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) - name = "cpas" + suffix - dataSCName = "ds_cpas" + suffix - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + suffix = acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) + name = "cpas" + suffix + dataSCName = "ds_cpas" + suffix + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") // resources fqdn name resourceName = "mongodbatlas_cloud_provider_access_setup." + name dsName = "data.mongodbatlas_cloud_provider_access_setup." + dataSCName ) - config := fmt.Sprintf(dataSourceCPASProviderConfig, name, projectID, "AWS", dataSCName) + config := fmt.Sprintf(dataSourceCPASProviderConfig, name, orgID, projectName, "AWS", dataSCName) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { @@ -49,7 +54,6 @@ func TestAccConfigDSCloudProviderAccessSetup_aws_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "created_date"), resource.TestCheckResourceAttrSet(resourceName, "role_id"), - resource.TestCheckResourceAttr(dsName, "project_id", projectID), resource.TestCheckResourceAttrSet(dsName, "aws.atlas_assumed_role_external_id"), ), }, diff --git a/mongodbatlas/data_source_mongodbatlas_cloud_provider_access_test.go b/mongodbatlas/data_source_mongodbatlas_cloud_provider_access_test.go index f9fb9e00c8..7aab110eb0 100644 --- a/mongodbatlas/data_source_mongodbatlas_cloud_provider_access_test.go +++ b/mongodbatlas/data_source_mongodbatlas_cloud_provider_access_test.go @@ -11,12 +11,16 @@ import ( const ( dataSourceProviderConfig = ` - resource "mongodbatlas_cloud_provider_access" "%[1]s" { - project_id = "%[2]s" - provider_name = "%[3]s" + resource "mongodbatlas_project" "test" { + name = %[3]q + org_id = %[2]q + } + resource "mongodbatlas_cloud_provider_access" %[1]q { + project_id = mongodbatlas_project.test.id + provider_name = %[4]q } - data "mongodbatlas_cloud_provider_access" "%[4]s" { + data "mongodbatlas_cloud_provider_access" %[5]q { project_id = mongodbatlas_cloud_provider_access.%[1]s.project_id } ` @@ -29,13 +33,14 @@ func TestAccConfigDSCloudProviderAccess_basic(t *testing.T) { dataSCName = "datasource_test_all_roles" + suffix resourceName = "mongodbatlas_cloud_provider_access." + name dsName = "data.mongodbatlas_cloud_provider_access." + dataSCName - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") ) - config := fmt.Sprintf(dataSourceProviderConfig, name, projectID, "AWS", dataSCName) + config := fmt.Sprintf(dataSourceProviderConfig, name, orgID, projectName, "AWS", dataSCName) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { @@ -43,7 +48,6 @@ func TestAccConfigDSCloudProviderAccess_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "atlas_assumed_role_external_id"), resource.TestCheckResourceAttrSet(resourceName, "atlas_aws_account_arn"), - resource.TestCheckResourceAttr(dsName, "project_id", projectID), resource.TestCheckResourceAttrSet(dsName, "aws_iam_roles.0.atlas_assumed_role_external_id"), ), }, diff --git a/mongodbatlas/data_source_mongodbatlas_custom_db_role_test.go b/mongodbatlas/data_source_mongodbatlas_custom_db_role_test.go index e6d0ec39c4..261616f653 100644 --- a/mongodbatlas/data_source_mongodbatlas_custom_db_role_test.go +++ b/mongodbatlas/data_source_mongodbatlas_custom_db_role_test.go @@ -12,24 +12,23 @@ import ( func TestAccConfigDSCustomDBRole_basic(t *testing.T) { resourceName := "mongodbatlas_custom_db_role.test" dataSourceName := "data.mongodbatlas_custom_db_role.test" - projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID := os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName := acctest.RandomWithPrefix("test-acc") roleName := fmt.Sprintf("test-acc-custom_role-%s", acctest.RandString(5)) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy, Steps: []resource.TestStep{ { - Config: testAccDSMongoDBAtlasCustomDBRoleConfig(projectID, roleName, "INSERT", fmt.Sprintf("test-acc-db_name-%s", acctest.RandString(5))), + Config: testAccDSMongoDBAtlasCustomDBRoleConfig(orgID, projectName, roleName, "INSERT", fmt.Sprintf("test-acc-db_name-%s", acctest.RandString(5))), Check: resource.ComposeTestCheckFunc( // Test for Resource testAccCheckMongoDBAtlasCustomDBRolesExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "role_name"), resource.TestCheckResourceAttrSet(resourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(resourceName, "project_id", projectID), resource.TestCheckResourceAttr(resourceName, "role_name", roleName), resource.TestCheckResourceAttr(resourceName, "actions.#", "1"), resource.TestCheckResourceAttr(resourceName, "actions.0.action", "INSERT"), @@ -44,17 +43,21 @@ func TestAccConfigDSCustomDBRole_basic(t *testing.T) { }) } -func testAccDSMongoDBAtlasCustomDBRoleConfig(projectID, roleName, action, databaseName string) string { +func testAccDSMongoDBAtlasCustomDBRoleConfig(orgID, projectName, roleName, action, databaseName string) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_custom_db_role" "test" { - project_id = "%s" - role_name = "%s" + project_id = mongodbatlas_project.test.id + role_name = %[3]q actions { - action = "%s" + action = %[4]q resources { collection_name = "" - database_name = "%s" + database_name = %[5]q } } } @@ -63,5 +66,5 @@ func testAccDSMongoDBAtlasCustomDBRoleConfig(projectID, roleName, action, databa project_id = "${mongodbatlas_custom_db_role.test.project_id}" role_name = "${mongodbatlas_custom_db_role.test.role_name}" } - `, projectID, roleName, action, databaseName) + `, orgID, projectName, roleName, action, databaseName) } diff --git a/mongodbatlas/data_source_mongodbatlas_custom_db_roles_test.go b/mongodbatlas/data_source_mongodbatlas_custom_db_roles_test.go index 5003e0f75a..498d2ad15e 100644 --- a/mongodbatlas/data_source_mongodbatlas_custom_db_roles_test.go +++ b/mongodbatlas/data_source_mongodbatlas_custom_db_roles_test.go @@ -12,29 +12,27 @@ import ( func TestAccConfigDSCustomDBRoles_basic(t *testing.T) { resourceName := "mongodbatlas_custom_db_role.test" dataSourceName := "data.mongodbatlas_custom_db_roles.test" - projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID := os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName := acctest.RandomWithPrefix("test-acc") roleName := fmt.Sprintf("test-acc-custom_role-%s", acctest.RandString(5)) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy, Steps: []resource.TestStep{ { - Config: testAccDSMongoDBAtlasCustomDBRolesConfig(projectID, roleName, "INSERT", fmt.Sprintf("test-acc-db_name-%s", acctest.RandString(5))), + Config: testAccDSMongoDBAtlasCustomDBRolesConfig(orgID, projectName, roleName, "INSERT", fmt.Sprintf("test-acc-db_name-%s", acctest.RandString(5))), Check: resource.ComposeTestCheckFunc( // Test for Resource testAccCheckMongoDBAtlasCustomDBRolesExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "role_name"), resource.TestCheckResourceAttrSet(resourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(resourceName, "project_id", projectID), resource.TestCheckResourceAttr(resourceName, "role_name", roleName), resource.TestCheckResourceAttr(resourceName, "actions.#", "1"), resource.TestCheckResourceAttr(resourceName, "actions.0.action", "INSERT"), resource.TestCheckResourceAttr(resourceName, "actions.0.resources.#", "1"), - // Test for Data source resource.TestCheckResourceAttrSet(dataSourceName, "project_id"), resource.TestCheckResourceAttrSet(dataSourceName, "results.#"), @@ -44,17 +42,21 @@ func TestAccConfigDSCustomDBRoles_basic(t *testing.T) { }) } -func testAccDSMongoDBAtlasCustomDBRolesConfig(projectID, roleName, action, databaseName string) string { +func testAccDSMongoDBAtlasCustomDBRolesConfig(orgID, projectName, roleName, action, databaseName string) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_custom_db_role" "test" { - project_id = "%s" - role_name = "%s" + project_id = mongodbatlas_project.test.id + role_name = %[3]q actions { - action = "%s" + action = %[4]q resources { collection_name = "" - database_name = "%s" + database_name = %[5]q } } } @@ -62,5 +64,5 @@ func testAccDSMongoDBAtlasCustomDBRolesConfig(projectID, roleName, action, datab data "mongodbatlas_custom_db_roles" "test" { project_id = "${mongodbatlas_custom_db_role.test.project_id}" } - `, projectID, roleName, action, databaseName) + `, orgID, projectName, roleName, action, databaseName) } diff --git a/mongodbatlas/data_source_mongodbatlas_custom_dns_configuration_cluster_aws_test.go b/mongodbatlas/data_source_mongodbatlas_custom_dns_configuration_cluster_aws_test.go index 1c704478e8..9d197662a4 100644 --- a/mongodbatlas/data_source_mongodbatlas_custom_dns_configuration_cluster_aws_test.go +++ b/mongodbatlas/data_source_mongodbatlas_custom_dns_configuration_cluster_aws_test.go @@ -5,19 +5,21 @@ import ( "os" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccConfigDSCustomDNSConfigurationAWS_basic(t *testing.T) { resourceName := "data.mongodbatlas_custom_dns_configuration_cluster_aws.test" - projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID := os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName := acctest.RandomWithPrefix("test-acc") resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasCustomDNSConfigurationAWSDataSourceConfig(projectID, true), + Config: testAccMongoDBAtlasCustomDNSConfigurationAWSDataSourceConfig(orgID, projectName, true), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasCustomDNSConfigurationAWSExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -28,15 +30,19 @@ func TestAccConfigDSCustomDNSConfigurationAWS_basic(t *testing.T) { }) } -func testAccMongoDBAtlasCustomDNSConfigurationAWSDataSourceConfig(projectID string, enabled bool) string { +func testAccMongoDBAtlasCustomDNSConfigurationAWSDataSourceConfig(orgID, projectName string, enabled bool) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_custom_dns_configuration_cluster_aws" "test" { - project_id = "%s" - enabled = %t + project_id = mongodbatlas_project.test.id + enabled = %[3]t } data "mongodbatlas_custom_dns_configuration_cluster_aws" "test" { project_id = mongodbatlas_custom_dns_configuration_cluster_aws.test.id } - `, projectID, enabled) + `, orgID, projectName, enabled) } diff --git a/mongodbatlas/data_source_mongodbatlas_database_user_test.go b/mongodbatlas/data_source_mongodbatlas_database_user_test.go index 02fa757d85..3651d20917 100644 --- a/mongodbatlas/data_source_mongodbatlas_database_user_test.go +++ b/mongodbatlas/data_source_mongodbatlas_database_user_test.go @@ -14,16 +14,17 @@ func TestAccConfigDSDatabaseUser_basic(t *testing.T) { var dbUser matlas.DatabaseUser resourceName := "data.mongodbatlas_database_user.test" - projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID := os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName := acctest.RandomWithPrefix("test-acc") roleName := "atlasAdmin" username := fmt.Sprintf("test-acc-%s", acctest.RandString(10)) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasDatabaseUserDataSourceConfig(projectID, roleName, username), + Config: testAccMongoDBAtlasDatabaseUserDataSourceConfig(orgID, projectName, roleName, username), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasDatabaseUserExists(resourceName, &dbUser), testAccCheckMongoDBAtlasDatabaseUserAttributes(&dbUser, username), @@ -40,16 +41,20 @@ func TestAccConfigDSDatabaseUser_basic(t *testing.T) { }) } -func testAccMongoDBAtlasDatabaseUserDataSourceConfig(projectID, roleName, username string) string { +func testAccMongoDBAtlasDatabaseUserDataSourceConfig(orgID, projectName, roleName, username string) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_database_user" "test" { - username = "%[3]s" + username = %[4]q password = "test-acc-password" - project_id = "%[1]s" + project_id = mongodbatlas_project.test.id auth_database_name = "admin" roles { - role_name = "%[2]s" + role_name = %[3]q database_name = "admin" } @@ -68,5 +73,5 @@ func testAccMongoDBAtlasDatabaseUserDataSourceConfig(projectID, roleName, userna project_id = mongodbatlas_database_user.test.project_id auth_database_name = "admin" } - `, projectID, roleName, username) + `, orgID, projectName, roleName, username) } diff --git a/mongodbatlas/data_source_mongodbatlas_database_users_test.go b/mongodbatlas/data_source_mongodbatlas_database_users_test.go index d4964420c9..3c6db3c03c 100644 --- a/mongodbatlas/data_source_mongodbatlas_database_users_test.go +++ b/mongodbatlas/data_source_mongodbatlas_database_users_test.go @@ -11,17 +11,18 @@ import ( func TestAccConfigDSDatabaseUsers_basic(t *testing.T) { resourceName := "data.mongodbatlas_database_users.test" - projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID := os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName := acctest.RandomWithPrefix("test-acc") username := fmt.Sprintf("test-acc-%s", acctest.RandString(10)) roleName := "atlasAdmin" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasDatabaseUsersDataSourceConfig(projectID, roleName, username), + Config: testAccMongoDBAtlasDatabaseUsersDataSourceConfig(orgID, projectName, roleName, username), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("mongodbatlas_database_user.db_user", "id"), resource.TestCheckResourceAttrSet("mongodbatlas_database_user.db_user_1", "id"), @@ -29,9 +30,8 @@ func TestAccConfigDSDatabaseUsers_basic(t *testing.T) { ), }, { - Config: testAccMongoDBAtlasDatabaseUsersDataSourceConfigWithDS(projectID, roleName, username), + Config: testAccMongoDBAtlasDatabaseUsersDataSourceConfigWithDS(orgID, projectName, roleName, username), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "project_id", projectID), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "results.#"), resource.TestCheckResourceAttrSet(resourceName, "results.0.x509_type"), @@ -44,28 +44,32 @@ func TestAccConfigDSDatabaseUsers_basic(t *testing.T) { }) } -func testAccMongoDBAtlasDatabaseUsersDataSourceConfig(projectID, roleName, username string) string { +func testAccMongoDBAtlasDatabaseUsersDataSourceConfig(orgID, projectName, roleName, username string) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_database_user" "db_user" { - username = "%[3]s" + username = %[4]q password = "test-acc-password" - project_id = "%[1]s" + project_id = mongodbatlas_project.test.id auth_database_name = "admin" roles { - role_name = "%[2]s" + role_name = %[3]q database_name = "admin" } } resource "mongodbatlas_database_user" "db_user_1" { - username = "%[3]s-1" + username = "%[4]s-1" password = "test-acc-password-1" - project_id = "%[1]s" + project_id = mongodbatlas_project.test.id auth_database_name = "admin" roles { - role_name = "%[2]s" + role_name = %[3]q database_name = "admin" } @@ -78,15 +82,15 @@ func testAccMongoDBAtlasDatabaseUsersDataSourceConfig(projectID, roleName, usern value = "value 2" } } - `, projectID, roleName, username) + `, orgID, projectName, roleName, username) } -func testAccMongoDBAtlasDatabaseUsersDataSourceConfigWithDS(projectID, roleName, username string) string { +func testAccMongoDBAtlasDatabaseUsersDataSourceConfigWithDS(orgID, projectName, roleName, username string) string { return fmt.Sprintf(` %s data "mongodbatlas_database_users" "test" { - project_id = "%s" + project_id = mongodbatlas_project.test.id } - `, testAccMongoDBAtlasDatabaseUsersDataSourceConfig(projectID, roleName, username), projectID) + `, testAccMongoDBAtlasDatabaseUsersDataSourceConfig(orgID, projectName, roleName, username)) } diff --git a/mongodbatlas/data_source_mongodbatlas_event_trigger_test.go b/mongodbatlas/data_source_mongodbatlas_event_trigger_test.go index 5e9469ba84..4760d6b530 100644 --- a/mongodbatlas/data_source_mongodbatlas_event_trigger_test.go +++ b/mongodbatlas/data_source_mongodbatlas_event_trigger_test.go @@ -13,7 +13,7 @@ import ( ) func TestAccConfigDSEventTrigger_basic(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( resourceName = "mongodbatlas_event_trigger.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") diff --git a/mongodbatlas/data_source_mongodbatlas_event_triggers_test.go b/mongodbatlas/data_source_mongodbatlas_event_triggers_test.go index 524a35ef54..e0e6912915 100644 --- a/mongodbatlas/data_source_mongodbatlas_event_triggers_test.go +++ b/mongodbatlas/data_source_mongodbatlas_event_triggers_test.go @@ -12,7 +12,7 @@ import ( ) func TestAccConfigDSEventTriggers_basic(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( resourceName = "mongodbatlas_event_trigger.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") @@ -38,7 +38,7 @@ func TestAccConfigDSEventTriggers_basic(t *testing.T) { } resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { diff --git a/mongodbatlas/data_source_mongodbatlas_maintenance_window_test.go b/mongodbatlas/data_source_mongodbatlas_maintenance_window_test.go index 59e6557b51..1472146289 100644 --- a/mongodbatlas/data_source_mongodbatlas_maintenance_window_test.go +++ b/mongodbatlas/data_source_mongodbatlas_maintenance_window_test.go @@ -5,6 +5,7 @@ import ( "os" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -12,16 +13,17 @@ import ( func TestAccConfigDSMaintenanceWindow_basic(t *testing.T) { var maintenance matlas.MaintenanceWindow - projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID := os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName := acctest.RandomWithPrefix("test-acc") dayOfWeek := 7 hourOfDay := 3 resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasDataSourceMaintenanceWindowConfig(projectID, dayOfWeek, hourOfDay), + Config: testAccMongoDBAtlasDataSourceMaintenanceWindowConfig(orgID, projectName, dayOfWeek, hourOfDay), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasMaintenanceWindowExists("mongodbatlas_maintenance_window.test", &maintenance), resource.TestCheckResourceAttrSet("data.mongodbatlas_maintenance_window.test", "project_id"), @@ -34,17 +36,21 @@ func TestAccConfigDSMaintenanceWindow_basic(t *testing.T) { }) } -func testAccMongoDBAtlasDataSourceMaintenanceWindowConfig(projectID string, dayOfWeek, hourOfDay int) string { +func testAccMongoDBAtlasDataSourceMaintenanceWindowConfig(orgID, projectName string, dayOfWeek, hourOfDay int) string { return fmt.Sprintf(` - resource "mongodbatlas_maintenance_window" "test" { - project_id = "%s" - day_of_week = %d - hour_of_day = %d + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } + resource "mongodbatlas_maintenance_window" "test" { + project_id = mongodbatlas_project.test.id + day_of_week = %[3]d + hour_of_day = %[4]d auto_defer_once_enabled = true } data "mongodbatlas_maintenance_window" "test" { project_id = "${mongodbatlas_maintenance_window.test.id}" } - `, projectID, dayOfWeek, hourOfDay) + `, orgID, projectName, dayOfWeek, hourOfDay) } diff --git a/mongodbatlas/data_source_mongodbatlas_org_id_test.go b/mongodbatlas/data_source_mongodbatlas_org_id_test.go index 2a556dbb92..def4d0df68 100644 --- a/mongodbatlas/data_source_mongodbatlas_org_id_test.go +++ b/mongodbatlas/data_source_mongodbatlas_org_id_test.go @@ -17,8 +17,8 @@ func TestAccConfigDSOrgID_basic(t *testing.T) { initialRole = []string{"ORG_OWNER"} ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasOrgInvitationDestroy, Steps: []resource.TestStep{ diff --git a/mongodbatlas/data_source_mongodbatlas_org_invitation_test.go b/mongodbatlas/data_source_mongodbatlas_org_invitation_test.go index 175f6d0293..8a58aca0e5 100644 --- a/mongodbatlas/data_source_mongodbatlas_org_invitation_test.go +++ b/mongodbatlas/data_source_mongodbatlas_org_invitation_test.go @@ -18,8 +18,8 @@ func TestAccConfigDSOrgInvitation_basic(t *testing.T) { initialRole = []string{"ORG_OWNER"} ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasOrgInvitationDestroy, Steps: []resource.TestStep{ diff --git a/mongodbatlas/data_source_mongodbatlas_organization_test.go b/mongodbatlas/data_source_mongodbatlas_organization_test.go index 8a416185c6..114ae527ec 100644 --- a/mongodbatlas/data_source_mongodbatlas_organization_test.go +++ b/mongodbatlas/data_source_mongodbatlas_organization_test.go @@ -12,7 +12,7 @@ func TestAccConfigDSOrganization_basic(t *testing.T) { var ( orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") ) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { diff --git a/mongodbatlas/data_source_mongodbatlas_organizations_test.go b/mongodbatlas/data_source_mongodbatlas_organizations_test.go index 79be15f597..33a1c891d6 100644 --- a/mongodbatlas/data_source_mongodbatlas_organizations_test.go +++ b/mongodbatlas/data_source_mongodbatlas_organizations_test.go @@ -11,7 +11,7 @@ func TestAccConfigDSOrganizations_basic(t *testing.T) { var ( datasourceName = "data.mongodbatlas_organizations.test" ) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { @@ -30,7 +30,7 @@ func TestAccConfigDSOrganizations_withPagination(t *testing.T) { var ( datasourceName = "data.mongodbatlas_organizations.test" ) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { diff --git a/mongodbatlas/data_source_mongodbatlas_project_api_key_test.go b/mongodbatlas/data_source_mongodbatlas_project_api_key_test.go index a0eeb83cc5..d2a10d3c42 100644 --- a/mongodbatlas/data_source_mongodbatlas_project_api_key_test.go +++ b/mongodbatlas/data_source_mongodbatlas_project_api_key_test.go @@ -12,22 +12,22 @@ import ( func TestAccConfigDSProjectAPIKey_basic(t *testing.T) { resourceName := "mongodbatlas_project_api_key.test" dataSourceName := "data.mongodbatlas_project_api_key.test" - projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID := os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName := acctest.RandomWithPrefix("test-acc") description := fmt.Sprintf("test-acc-project-api_key-%s", acctest.RandString(5)) roleName := "GROUP_OWNER" - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy, Steps: []resource.TestStep{ { - Config: testAccDSMongoDBAtlasProjectAPIKeyConfig(projectID, description, roleName), + Config: testAccDSMongoDBAtlasProjectAPIKeyConfig(orgID, projectName, description, roleName), Check: resource.ComposeTestCheckFunc( // Test for Resource resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "description"), - resource.TestCheckResourceAttr(resourceName, "project_id", projectID), resource.TestCheckResourceAttr(resourceName, "description", description), // Test for Data source resource.TestCheckResourceAttrSet(dataSourceName, "project_id"), @@ -38,17 +38,21 @@ func TestAccConfigDSProjectAPIKey_basic(t *testing.T) { }) } -func testAccDSMongoDBAtlasProjectAPIKeyConfig(projectID, description, roleNames string) string { +func testAccDSMongoDBAtlasProjectAPIKeyConfig(orgID, projectName, description, roleNames string) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_project_api_key" "test" { - project_id = %[1]q - description = %[2]q - role_names = [%[3]q] + project_id = mongodbatlas_project.test.id + description = %[3]q + role_names = [%[4]q] } data "mongodbatlas_project_api_key" "test" { - project_id = %[1]q + project_id = mongodbatlas_project.test.id api_key_id = "${mongodbatlas_project_api_key.test.api_key_id}" } - `, projectID, description, roleNames) + `, orgID, projectName, description, roleNames) } diff --git a/mongodbatlas/data_source_mongodbatlas_project_api_keys_test.go b/mongodbatlas/data_source_mongodbatlas_project_api_keys_test.go index db276b636e..76ddb30c0b 100644 --- a/mongodbatlas/data_source_mongodbatlas_project_api_keys_test.go +++ b/mongodbatlas/data_source_mongodbatlas_project_api_keys_test.go @@ -12,23 +12,22 @@ import ( func TestAccConfigDSProjectAPIKeys_basic(t *testing.T) { resourceName := "mongodbatlas_project_api_key.test" dataSourceName := "data.mongodbatlas_project_api_keys.test" - orgID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID := os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName := acctest.RandomWithPrefix("test-acc") description := fmt.Sprintf("test-acc-project-api_key-%s", acctest.RandString(5)) roleName := "GROUP_OWNER" - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, - CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy, + CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy, Steps: []resource.TestStep{ { - Config: testAccDSMongoDBAtlasProjectAPIKeysConfig(orgID, description, roleName), + Config: testAccDSMongoDBAtlasProjectAPIKeysConfig(orgID, projectName, description, roleName), Check: resource.ComposeTestCheckFunc( // Test for Resource resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "description"), - - resource.TestCheckResourceAttr(resourceName, "project_id", orgID), resource.TestCheckResourceAttr(resourceName, "description", description), // Test for Data source @@ -40,16 +39,21 @@ func TestAccConfigDSProjectAPIKeys_basic(t *testing.T) { }) } -func testAccDSMongoDBAtlasProjectAPIKeysConfig(projectID, description, roleNames string) string { +func testAccDSMongoDBAtlasProjectAPIKeysConfig(orgID, projectName, description, roleNames string) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } + resource "mongodbatlas_project_api_key" "test" { - project_id = %[1]q - description = %[2]q - role_names = [%[3]q] + project_id = mongodbatlas_project.test.id + description = %[3]q + role_names = [%[4]q] } data "mongodbatlas_project_api_keys" "test" { - project_id = %[1]q + project_id = mongodbatlas_project.test.id } - `, projectID, description, roleNames) + `, orgID, projectName, description, roleNames) } diff --git a/mongodbatlas/data_source_mongodbatlas_search_index_test.go b/mongodbatlas/data_source_mongodbatlas_search_index_test.go deleted file mode 100644 index e09ba56ebc..0000000000 --- a/mongodbatlas/data_source_mongodbatlas_search_index_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package mongodbatlas - -import ( - "fmt" - "os" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestAccConfigDSSearchIndex_byID(t *testing.T) { - var ( - clusterName = acctest.RandomWithPrefix("test-acc-global") - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - datasourceName = "data.mongodbatlas_search_index.test_two" - ) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ProviderFactories: testAccProviderFactories, - CheckDestroy: testAccCheckMongoDBAtlasSearchIndexDestroy, - Steps: []resource.TestStep{ - { - Config: testAccMongoDBAtlasSearchIndexDSConfig(projectID, clusterName), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(datasourceName, "name"), - resource.TestCheckResourceAttrSet(datasourceName, "project_id"), - resource.TestCheckResourceAttrSet(datasourceName, "name"), - resource.TestCheckResourceAttrSet(datasourceName, "collection_name"), - resource.TestCheckResourceAttrSet(datasourceName, "database"), - resource.TestCheckResourceAttrSet(datasourceName, "search_analyzer"), - resource.TestCheckResourceAttrSet(datasourceName, "synonyms.#"), - resource.TestCheckResourceAttr(datasourceName, "synonyms.#", "1"), - resource.TestCheckResourceAttr(datasourceName, "synonyms.0.analyzer", "lucene.simple"), - resource.TestCheckResourceAttr(datasourceName, "synonyms.0.name", "synonym_test"), - resource.TestCheckResourceAttr(datasourceName, "synonyms.0.source_collection", "collection_test"), - ), - }, - }, - }) -} - -func testAccMongoDBAtlasSearchIndexDSConfig(projectID, clusterName string) string { - return fmt.Sprintf(` - %s - - data "mongodbatlas_search_index" "test_two" { - cluster_name = mongodbatlas_search_index.test.cluster_name - project_id = mongodbatlas_search_index.test.project_id - index_id = mongodbatlas_search_index.test.index_id - } - `, testAccMongoDBAtlasSearchIndexConfigSynonyms(projectID, clusterName)) -} diff --git a/mongodbatlas/data_source_mongodbatlas_search_indexes_test.go b/mongodbatlas/data_source_mongodbatlas_search_indexes_test.go deleted file mode 100644 index 85b098d4ac..0000000000 --- a/mongodbatlas/data_source_mongodbatlas_search_indexes_test.go +++ /dev/null @@ -1,104 +0,0 @@ -package mongodbatlas - -import ( - "fmt" - "os" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestAccConfigDSSearchIndexes_basic(t *testing.T) { - var ( - clusterName = acctest.RandomWithPrefix("test-acc-global") - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - collectionName = "collection_test" - databaseName = "database_test" - datasourceName = "data.mongodbatlas_search_indexes.data_index" - ) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckMongoDBAtlasSearchIndexDestroy, - Steps: []resource.TestStep{ - { - Config: testAccMongoDBAtlasSearchIndexesDSConfig(projectID, clusterName, databaseName, collectionName), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(datasourceName, "cluster_name"), - resource.TestCheckResourceAttrSet(datasourceName, "database"), - resource.TestCheckResourceAttrSet(datasourceName, "project_id"), - resource.TestCheckResourceAttrSet(datasourceName, "results.#"), - resource.TestCheckResourceAttrSet(datasourceName, "results.0.index_id"), - resource.TestCheckResourceAttrSet(datasourceName, "results.0.name"), - ), - }, - }, - }) -} - -func TestAccConfigDSSearchIndexes_WithSynonyms(t *testing.T) { - var ( - clusterName = acctest.RandomWithPrefix("test-acc-global") - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - collectionName = "collection_test" - databaseName = "database_test" - datasourceName = "data.mongodbatlas_search_indexes.data_index" - ) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckMongoDBAtlasSearchIndexDestroy, - Steps: []resource.TestStep{ - { - Config: testAccMongoDBAtlasSearchIndexesDSConfigSynonyms(projectID, clusterName, databaseName, collectionName), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(datasourceName, "cluster_name"), - resource.TestCheckResourceAttrSet(datasourceName, "database"), - resource.TestCheckResourceAttrSet(datasourceName, "project_id"), - resource.TestCheckResourceAttrSet(datasourceName, "results.#"), - resource.TestCheckResourceAttrSet(datasourceName, "results.0.index_id"), - resource.TestCheckResourceAttrSet(datasourceName, "results.0.name"), - resource.TestCheckResourceAttrSet(datasourceName, "results.0.analyzer"), - resource.TestCheckResourceAttr(datasourceName, "results.0.synonyms.#", "1"), - resource.TestCheckResourceAttr(datasourceName, "results.0.synonyms.0.analyzer", "lucene.simple"), - resource.TestCheckResourceAttr(datasourceName, "results.0.synonyms.0.name", "synonym_test"), - resource.TestCheckResourceAttr(datasourceName, "results.0.synonyms.0.source_collection", "collection_test"), - ), - }, - }, - }) -} - -func testAccMongoDBAtlasSearchIndexesDSConfig(projectID, clusterName, databaseName, collectionName string) string { - return fmt.Sprintf(` - %s - - data "mongodbatlas_search_indexes" "data_index" { - cluster_name = mongodbatlas_search_index.test.cluster_name - project_id = mongodbatlas_search_index.test.project_id - database = "%s" - collection_name = "%s" - page_num = 1 - items_per_page = 100 - - } - `, testAccMongoDBAtlasSearchIndexConfig(projectID, clusterName), databaseName, collectionName) -} - -func testAccMongoDBAtlasSearchIndexesDSConfigSynonyms(projectID, clusterName, databaseName, collectionName string) string { - return fmt.Sprintf(` - %s - - data "mongodbatlas_search_indexes" "data_index" { - cluster_name = mongodbatlas_search_index.test.cluster_name - project_id = mongodbatlas_search_index.test.project_id - database = "%s" - collection_name = "%s" - page_num = 1 - items_per_page = 100 - } - `, testAccMongoDBAtlasSearchIndexConfigSynonyms(projectID, clusterName), databaseName, collectionName) -} diff --git a/mongodbatlas/data_source_mongodbatlas_team_test.go b/mongodbatlas/data_source_mongodbatlas_team_test.go index 4dbae41f8c..58c8b52932 100644 --- a/mongodbatlas/data_source_mongodbatlas_team_test.go +++ b/mongodbatlas/data_source_mongodbatlas_team_test.go @@ -14,11 +14,11 @@ func TestAccConfigDSTeam_basic(t *testing.T) { dataSourceName = "data.mongodbatlas_teams.test" orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") name = fmt.Sprintf("test-acc-%s", acctest.RandString(10)) - username = "mongodbatlas.testing@gmail.com" + username = os.Getenv("MONGODB_ATLAS_USERNAME_CLOUD_DEV") ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasTeamDestroy, Steps: []resource.TestStep{ @@ -40,11 +40,11 @@ func TestAccConfigDSTeamByName_basic(t *testing.T) { dataSourceName = "data.mongodbatlas_teams.test2" orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") name = fmt.Sprintf("test-acc-%s", acctest.RandString(10)) - username = "mongodbatlas.testing@gmail.com" + username = os.Getenv("MONGODB_ATLAS_USERNAME_CLOUD_DEV") ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasTeamDestroy, Steps: []resource.TestStep{ diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integration_test.go b/mongodbatlas/data_source_mongodbatlas_third_party_integration_test.go index f3c810ed5c..fdb1de2ef1 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integration_test.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integration_test.go @@ -116,7 +116,7 @@ type thirdPartyConfig struct { } func TestAccConfigDSThirdPartyIntegration_basic(t *testing.T) { - SkipTest(t) // TODO: Address failures in v1.4.6 + SkipTestForCI(t) // TODO: Address failures in v1.4.6 var ( targetIntegration = matlas.ThirdPartyIntegration{} diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integrations_test.go b/mongodbatlas/data_source_mongodbatlas_third_party_integrations_test.go index f17279c31f..4d3c880f64 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integrations_test.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integrations_test.go @@ -11,7 +11,7 @@ import ( ) func TestAccConfigDSThirdPartyIntegrations_basic(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") intgTypes = []string{"NEW_RELIC", "OPS_GENIE", "DATADOG", "VICTOR_OPS", "WEBHOOK", "PROMETHEUS"} diff --git a/mongodbatlas/resource_mongodbatlas_alert_configuration_test.go b/mongodbatlas/resource_mongodbatlas_alert_configuration_test.go index 02b8525984..0431d383ed 100644 --- a/mongodbatlas/resource_mongodbatlas_alert_configuration_test.go +++ b/mongodbatlas/resource_mongodbatlas_alert_configuration_test.go @@ -6,6 +6,7 @@ import ( "os" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" matlas "go.mongodb.org/atlas/mongodbatlas" @@ -14,17 +15,18 @@ import ( func TestAccConfigRSAlertConfiguration_basic(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") alert = &matlas.AlertConfiguration{} ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationConfig(projectID, true), + Config: testAccMongoDBAtlasAlertConfigurationConfig(orgID, projectName, true), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -32,7 +34,7 @@ func TestAccConfigRSAlertConfiguration_basic(t *testing.T) { ), }, { - Config: testAccMongoDBAtlasAlertConfigurationConfig(projectID, false), + Config: testAccMongoDBAtlasAlertConfigurationConfig(orgID, projectName, false), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -46,24 +48,25 @@ func TestAccConfigRSAlertConfiguration_basic(t *testing.T) { func TestAccConfigRSAlertConfiguration_Notifications(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") alert = &matlas.AlertConfiguration{} ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationConfigNotifications(projectID, true, true, false), + Config: testAccMongoDBAtlasAlertConfigurationConfigNotifications(orgID, projectName, true, true, false), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), ), }, { - Config: testAccMongoDBAtlasAlertConfigurationConfigNotifications(projectID, false, false, true), + Config: testAccMongoDBAtlasAlertConfigurationConfigNotifications(orgID, projectName, false, false, true), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -76,17 +79,18 @@ func TestAccConfigRSAlertConfiguration_Notifications(t *testing.T) { func TestAccConfigRSAlertConfiguration_WithMatchers(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") alert = &matlas.AlertConfiguration{} ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationConfigWithMatchers(projectID, true, false, true, + Config: testAccMongoDBAtlasAlertConfigurationConfigWithMatchers(orgID, projectName, true, false, true, matlas.Matcher{ FieldName: "TYPE_NAME", Operator: "EQUALS", @@ -103,7 +107,7 @@ func TestAccConfigRSAlertConfiguration_WithMatchers(t *testing.T) { ), }, { - Config: testAccMongoDBAtlasAlertConfigurationConfigWithMatchers(projectID, false, true, false, + Config: testAccMongoDBAtlasAlertConfigurationConfigWithMatchers(orgID, projectName, false, true, false, matlas.Matcher{ FieldName: "TYPE_NAME", Operator: "NOT_EQUALS", @@ -126,24 +130,25 @@ func TestAccConfigRSAlertConfiguration_WithMatchers(t *testing.T) { func TestAccConfigRSAlertConfiguration_whitMetricUpdated(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") alert = &matlas.AlertConfiguration{} ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationConfigWithMetrictUpdated(projectID, true, 99.0), + Config: testAccMongoDBAtlasAlertConfigurationConfigWithMetrictUpdated(orgID, projectName, true, 99.0), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), ), }, { - Config: testAccMongoDBAtlasAlertConfigurationConfigWithMetrictUpdated(projectID, false, 89.7), + Config: testAccMongoDBAtlasAlertConfigurationConfigWithMetrictUpdated(orgID, projectName, false, 89.7), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -156,24 +161,25 @@ func TestAccConfigRSAlertConfiguration_whitMetricUpdated(t *testing.T) { func TestAccConfigRSAlertConfiguration_whitThresholdUpdated(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") alert = &matlas.AlertConfiguration{} ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationConfigWithThresholdUpdated(projectID, true, 1), + Config: testAccMongoDBAtlasAlertConfigurationConfigWithThresholdUpdated(orgID, projectName, true, 1), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), ), }, { - Config: testAccMongoDBAtlasAlertConfigurationConfigWithThresholdUpdated(projectID, false, 3), + Config: testAccMongoDBAtlasAlertConfigurationConfigWithThresholdUpdated(orgID, projectName, false, 3), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -194,16 +200,17 @@ func TestAccConfigRSAlertConfiguration_whitoutRoles(t *testing.T) { var ( alert = &matlas.AlertConfiguration{} resourceName = "mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationConfigWithoutRoles(projectID, true, 99.0), + Config: testAccMongoDBAtlasAlertConfigurationConfigWithoutRoles(orgID, projectName, true, 99.0), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -215,17 +222,18 @@ func TestAccConfigRSAlertConfiguration_whitoutRoles(t *testing.T) { func TestAccConfigRSAlertConfiguration_importBasic(t *testing.T) { var ( - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") resourceName = "mongodbatlas_alert_configuration.test" ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationConfig(projectID, true), + Config: testAccMongoDBAtlasAlertConfigurationConfig(orgID, projectName, true), }, { ResourceName: resourceName, @@ -240,17 +248,18 @@ func TestAccConfigRSAlertConfiguration_importBasic(t *testing.T) { func TestAccConfigRSAlertConfiguration_importConfigNotifications(t *testing.T) { var ( - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") resourceName = "mongodbatlas_alert_configuration.test" ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationConfigNotifications(projectID, true, true, false), + Config: testAccMongoDBAtlasAlertConfigurationConfigNotifications(orgID, projectName, true, true, false), }, { ResourceName: resourceName, @@ -421,12 +430,17 @@ func testAccCheckMongoDBAtlasAlertConfigurationImportStateIDFunc(resourceName st } } -func testAccMongoDBAtlasAlertConfigurationConfig(projectID string, enabled bool) string { +func testAccMongoDBAtlasAlertConfigurationConfig(orgID, projectName string, enabled bool) string { return fmt.Sprintf(` +resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q +} + resource "mongodbatlas_alert_configuration" "test" { - project_id = %[1]q + project_id = mongodbatlas_project.test.id event_type = "OUTSIDE_METRIC_THRESHOLD" - enabled = %t + enabled = "%[3]t" notification { type_name = "GROUP" @@ -459,22 +473,26 @@ resource "mongodbatlas_alert_configuration" "test" { mode = "AVERAGE" } } - `, projectID, enabled) + `, orgID, projectName, enabled) } -func testAccMongoDBAtlasAlertConfigurationConfigNotifications(projectID string, enabled, smsEnabled, emailEnabled bool) string { +func testAccMongoDBAtlasAlertConfigurationConfigNotifications(orgID, projectName string, enabled, smsEnabled, emailEnabled bool) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_alert_configuration" "test" { - project_id = "%[1]s" + project_id = mongodbatlas_project.test.id event_type = "NO_PRIMARY" - enabled = "%[2]t" + enabled = "%[3]t" notification { type_name = "GROUP" interval_min = 5 delay_min = 0 - sms_enabled = %[3]t - email_enabled = %[4]t + sms_enabled = %[4]t + email_enabled = %[5]t roles = ["GROUP_DATA_ACCESS_READ_ONLY"] } @@ -482,51 +500,59 @@ func testAccMongoDBAtlasAlertConfigurationConfigNotifications(projectID string, type_name = "ORG" interval_min = 5 delay_min = 1 - sms_enabled = %[3]t - email_enabled = %[4]t + sms_enabled = %[4]t + email_enabled = %[5]t } } - `, projectID, enabled, smsEnabled, emailEnabled) + `, orgID, projectName, enabled, smsEnabled, emailEnabled) } -func testAccMongoDBAtlasAlertConfigurationConfigWithMatchers(projectID string, enabled, smsEnabled, emailEnabled bool, m1, m2 matlas.Matcher) string { +func testAccMongoDBAtlasAlertConfigurationConfigWithMatchers(orgID, projectName string, enabled, smsEnabled, emailEnabled bool, m1, m2 matlas.Matcher) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_alert_configuration" "test" { - project_id = "%s" + project_id = mongodbatlas_project.test.id event_type = "HOST_DOWN" - enabled = "%t" + enabled = "%[3]t" notification { type_name = "GROUP" interval_min = 5 delay_min = 0 - sms_enabled = %t - email_enabled = %t + sms_enabled = %[4]t + email_enabled = %[5]t roles = ["GROUP_DATA_ACCESS_READ_ONLY", "GROUP_CLUSTER_MANAGER"] } matcher { - field_name = "%s" - operator = "%s" - value = "%s" + field_name = %[6]q + operator = %[7]q + value = %[8]q } matcher { - field_name = "%s" - operator = "%s" - value = "%s" + field_name = %[9]q + operator = %[10]q + value = %[11]q } } - `, projectID, enabled, smsEnabled, emailEnabled, + `, orgID, projectName, enabled, smsEnabled, emailEnabled, m1.FieldName, m1.Operator, m1.Value, m2.FieldName, m2.Operator, m2.Value) } -func testAccMongoDBAtlasAlertConfigurationConfigWithMetrictUpdated(projectID string, enabled bool, threshold float64) string { +func testAccMongoDBAtlasAlertConfigurationConfigWithMetrictUpdated(orgID, projectName string, enabled bool, threshold float64) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_alert_configuration" "test" { - project_id = "%s" + project_id = mongodbatlas_project.test.id event_type = "OUTSIDE_METRIC_THRESHOLD" - enabled = "%t" + enabled = "%[3]t" notification { type_name = "GROUP" @@ -546,20 +572,24 @@ func testAccMongoDBAtlasAlertConfigurationConfigWithMetrictUpdated(projectID str metric_threshold_config { metric_name = "ASSERT_REGULAR" operator = "LESS_THAN" - threshold = %f + threshold = %[4]f units = "RAW" mode = "AVERAGE" } } - `, projectID, enabled, threshold) + `, orgID, projectName, enabled, threshold) } -func testAccMongoDBAtlasAlertConfigurationConfigWithoutRoles(projectID string, enabled bool, threshold float64) string { +func testAccMongoDBAtlasAlertConfigurationConfigWithoutRoles(orgID, projectName string, enabled bool, threshold float64) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_alert_configuration" "test" { - project_id = "%s" + project_id = mongodbatlas_project.test.id event_type = "OUTSIDE_METRIC_THRESHOLD" - enabled = "%t" + enabled = "%[3]t" notification { type_name = "EMAIL" @@ -579,20 +609,24 @@ func testAccMongoDBAtlasAlertConfigurationConfigWithoutRoles(projectID string, e metric_threshold_config { metric_name = "ASSERT_REGULAR" operator = "LESS_THAN" - threshold = %f + threshold = %[4]f units = "RAW" mode = "AVERAGE" } } - `, projectID, enabled, threshold) + `, orgID, projectName, enabled, threshold) } -func testAccMongoDBAtlasAlertConfigurationConfigWithThresholdUpdated(projectID string, enabled bool, threshold float64) string { +func testAccMongoDBAtlasAlertConfigurationConfigWithThresholdUpdated(orgID, projectName string, enabled bool, threshold float64) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_alert_configuration" "test" { - project_id = "%s" + project_id = mongodbatlas_project.test.id event_type = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT" - enabled = "%t" + enabled = "%[3]t" notification { type_name = "GROUP" @@ -612,10 +646,10 @@ func testAccMongoDBAtlasAlertConfigurationConfigWithThresholdUpdated(projectID s threshold_config { operator = "LESS_THAN" units = "HOURS" - threshold = %f + threshold = %[4]f } } - `, projectID, enabled, threshold) + `, orgID, projectName, enabled, threshold) } func testAccMongoDBAtlasAlertConfigurationConfigWithDataDog(projectID, dataDogAPIKey, dataDogRegion string, enabled bool) string { diff --git a/mongodbatlas/resource_mongodbatlas_api_key_test.go b/mongodbatlas/resource_mongodbatlas_api_key_test.go index 99de741d1c..f477a05ee1 100644 --- a/mongodbatlas/resource_mongodbatlas_api_key_test.go +++ b/mongodbatlas/resource_mongodbatlas_api_key_test.go @@ -21,8 +21,8 @@ func TestAccConfigRSAPIKey_Basic(t *testing.T) { roleNameUpdated = "ORG_BILLING_ADMIN" ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasAPIKeyDestroy, Steps: []resource.TestStep{ @@ -32,7 +32,6 @@ func TestAccConfigRSAPIKey_Basic(t *testing.T) { testAccCheckMongoDBAtlasAPIKeyExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "org_id"), resource.TestCheckResourceAttrSet(resourceName, "description"), - resource.TestCheckResourceAttr(resourceName, "org_id", orgID), resource.TestCheckResourceAttr(resourceName, "description", description), ), @@ -43,7 +42,6 @@ func TestAccConfigRSAPIKey_Basic(t *testing.T) { testAccCheckMongoDBAtlasAPIKeyExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "org_id"), resource.TestCheckResourceAttrSet(resourceName, "description"), - resource.TestCheckResourceAttr(resourceName, "org_id", orgID), resource.TestCheckResourceAttr(resourceName, "description", descriptionUpdate), ), @@ -60,8 +58,8 @@ func TestAccConfigRSAPIKey_importBasic(t *testing.T) { roleName = "ORG_MEMBER" ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasAPIKeyDestroy, Steps: []resource.TestStep{ diff --git a/mongodbatlas/resource_mongodbatlas_cloud_provider_access_setup_test.go b/mongodbatlas/resource_mongodbatlas_cloud_provider_access_setup_test.go index fa09cb24e4..197980d321 100644 --- a/mongodbatlas/resource_mongodbatlas_cloud_provider_access_setup_test.go +++ b/mongodbatlas/resource_mongodbatlas_cloud_provider_access_setup_test.go @@ -12,9 +12,13 @@ import ( const ( createProviderAccessSetupRole = ` + resource "mongodbatlas_project" "test" { + name = %[3]q + org_id = %[2]q + } resource "mongodbatlas_cloud_provider_access_setup" "%[1]s" { - project_id = "%[2]s" - provider_name = "%[3]s" + project_id = mongodbatlas_project.test.id + provider_name = %[4]q } ` @@ -24,18 +28,19 @@ func TestAccConfigRSCloudProviderAccessSetup_basic(t *testing.T) { var ( name = "test_basic" + acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) resourceName = "mongodbatlas_cloud_provider_access_setup." + name - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") targetRole = matlas.AWSIAMRole{} ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, // same as regular cloud provider access resource CheckDestroy: testAccCheckMongoDBAtlasProviderAccessDestroy, Steps: []resource.TestStep{ { - Config: fmt.Sprintf(createProviderAccessSetupRole, name, projectID, "AWS"), + Config: fmt.Sprintf(createProviderAccessSetupRole, name, orgID, projectName, "AWS"), Check: resource.ComposeTestCheckFunc( // same as regular cloud resource testAccCheckMongoDBAtlasProviderAccessExists(resourceName, &targetRole), @@ -52,17 +57,18 @@ func TestAccConfigRSCloudProviderAccessSetup_importBasic(t *testing.T) { var ( name = "test_basic" + acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) resourceName = "mongodbatlas_cloud_provider_access_setup." + name - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") targetRole = matlas.AWSIAMRole{} ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasProviderAccessDestroy, Steps: []resource.TestStep{ { - Config: fmt.Sprintf(createProviderAccessSetupRole, name, projectID, "AWS"), + Config: fmt.Sprintf(createProviderAccessSetupRole, name, orgID, projectName, "AWS"), Check: resource.ComposeTestCheckFunc( // same as regular cloud provider because we are just checking in the api testAccCheckMongoDBAtlasProviderAccessExists(resourceName, &targetRole), diff --git a/mongodbatlas/resource_mongodbatlas_cloud_provider_access_test.go b/mongodbatlas/resource_mongodbatlas_cloud_provider_access_test.go index 0b39e12e1f..cf6c29a973 100644 --- a/mongodbatlas/resource_mongodbatlas_cloud_provider_access_test.go +++ b/mongodbatlas/resource_mongodbatlas_cloud_provider_access_test.go @@ -14,9 +14,13 @@ import ( const ( createProviderAccessRole = ` - resource "mongodbatlas_cloud_provider_access" "%[1]s" { - project_id = "%[2]s" - provider_name = "%[3]s" + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } + resource "mongodbatlas_cloud_provider_access" "test" { + project_id = mongodbatlas_project.test.id + provider_name = %[3]q } ` @@ -24,19 +28,18 @@ const ( func TestAccConfigRSCloudProviderAccess_basic(t *testing.T) { var ( - name = "test_basic" + acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) - resourceName = "mongodbatlas_cloud_provider_access." + name - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + resourceName = "mongodbatlas_cloud_provider_access.test" + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") targetRole = matlas.AWSIAMRole{} ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, - CheckDestroy: testAccCheckMongoDBAtlasProviderAccessDestroy, Steps: []resource.TestStep{ { - Config: fmt.Sprintf(createProviderAccessRole, name, projectID, "AWS"), + Config: fmt.Sprintf(createProviderAccessRole, orgID, projectName, "AWS"), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasProviderAccessExists(resourceName, &targetRole), resource.TestCheckResourceAttrSet(resourceName, "atlas_assumed_role_external_id"), @@ -50,19 +53,18 @@ func TestAccConfigRSCloudProviderAccess_basic(t *testing.T) { func TestAccConfigRSCloudProviderAccess_importBasic(t *testing.T) { var ( - name = "test_basic" + acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) - resourceName = "mongodbatlas_cloud_provider_access." + name - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + resourceName = "mongodbatlas_cloud_provider_access.test" + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") targetRole = matlas.AWSIAMRole{} ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, - CheckDestroy: testAccCheckMongoDBAtlasProviderAccessDestroy, Steps: []resource.TestStep{ { - Config: fmt.Sprintf(createProviderAccessRole, name, projectID, "AWS"), + Config: fmt.Sprintf(createProviderAccessRole, orgID, projectName, "AWS"), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasProviderAccessExists(resourceName, &targetRole), resource.TestCheckResourceAttrSet(resourceName, "atlas_assumed_role_external_id"), diff --git a/mongodbatlas/resource_mongodbatlas_custom_db_role_test.go b/mongodbatlas/resource_mongodbatlas_custom_db_role_test.go index 5559ad5e7a..b9187e5a5b 100644 --- a/mongodbatlas/resource_mongodbatlas_custom_db_role_test.go +++ b/mongodbatlas/resource_mongodbatlas_custom_db_role_test.go @@ -17,24 +17,23 @@ import ( func TestAccConfigRSCustomDBRoles_Basic(t *testing.T) { var ( resourceName = "mongodbatlas_custom_db_role.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") roleName = fmt.Sprintf("test-acc-custom_role-%s", acctest.RandString(5)) ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasCustomDBRolesDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasCustomDBRolesConfigBasic(projectID, roleName, "INSERT", fmt.Sprintf("test-acc-db_name-%s", acctest.RandString(5))), + Config: testAccMongoDBAtlasCustomDBRolesConfigBasic(orgID, projectName, roleName, "INSERT", fmt.Sprintf("test-acc-db_name-%s", acctest.RandString(5))), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasCustomDBRolesExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "role_name"), resource.TestCheckResourceAttrSet(resourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(resourceName, "project_id", projectID), resource.TestCheckResourceAttr(resourceName, "role_name", roleName), resource.TestCheckResourceAttr(resourceName, "actions.#", "1"), resource.TestCheckResourceAttr(resourceName, "actions.0.action", "INSERT"), @@ -42,14 +41,12 @@ func TestAccConfigRSCustomDBRoles_Basic(t *testing.T) { ), }, { - Config: testAccMongoDBAtlasCustomDBRolesConfigBasic(projectID, roleName, "UPDATE", fmt.Sprintf("test-acc-db_name-%s", acctest.RandString(5))), + Config: testAccMongoDBAtlasCustomDBRolesConfigBasic(orgID, projectName, roleName, "UPDATE", fmt.Sprintf("test-acc-db_name-%s", acctest.RandString(5))), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasCustomDBRolesExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "role_name"), resource.TestCheckResourceAttrSet(resourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(resourceName, "project_id", projectID), resource.TestCheckResourceAttr(resourceName, "role_name", roleName), resource.TestCheckResourceAttr(resourceName, "actions.#", "1"), resource.TestCheckResourceAttr(resourceName, "actions.0.action", "UPDATE"), @@ -64,8 +61,8 @@ func TestAccConfigRSCustomDBRoles_WithInheritedRoles(t *testing.T) { testRoleResourceName := "mongodbatlas_custom_db_role.test_role" InheritedRoleResourceNameOne := "mongodbatlas_custom_db_role.inherited_role_one" InheritedRoleResourceNameTwo := "mongodbatlas_custom_db_role.inherited_role_two" - - projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID := os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName := acctest.RandomWithPrefix("test-acc") inheritRole := []matlas.CustomDBRole{ { @@ -129,13 +126,13 @@ func TestAccConfigRSCustomDBRoles_WithInheritedRoles(t *testing.T) { }}, } - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasCustomDBRolesDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasCustomDBRolesConfigWithInheritedRoles(projectID, inheritRole, testRole), + Config: testAccMongoDBAtlasCustomDBRolesConfigWithInheritedRoles(orgID, projectName, inheritRole, testRole), Check: resource.ComposeTestCheckFunc( // For Inherited Roles @@ -144,8 +141,6 @@ func TestAccConfigRSCustomDBRoles_WithInheritedRoles(t *testing.T) { resource.TestCheckResourceAttrSet(InheritedRoleResourceNameOne, "project_id"), resource.TestCheckResourceAttrSet(InheritedRoleResourceNameOne, "role_name"), resource.TestCheckResourceAttrSet(InheritedRoleResourceNameOne, "actions.0.action"), - - resource.TestCheckResourceAttr(InheritedRoleResourceNameOne, "project_id", projectID), resource.TestCheckResourceAttr(InheritedRoleResourceNameOne, "role_name", inheritRole[0].RoleName), resource.TestCheckResourceAttr(InheritedRoleResourceNameOne, "actions.#", cast.ToString(len(inheritRole[0].Actions))), resource.TestCheckResourceAttr(InheritedRoleResourceNameOne, "actions.0.action", inheritRole[0].Actions[0].Action), @@ -156,8 +151,6 @@ func TestAccConfigRSCustomDBRoles_WithInheritedRoles(t *testing.T) { resource.TestCheckResourceAttrSet(InheritedRoleResourceNameTwo, "project_id"), resource.TestCheckResourceAttrSet(InheritedRoleResourceNameTwo, "role_name"), resource.TestCheckResourceAttrSet(InheritedRoleResourceNameTwo, "actions.0.action"), - - resource.TestCheckResourceAttr(InheritedRoleResourceNameTwo, "project_id", projectID), resource.TestCheckResourceAttr(InheritedRoleResourceNameTwo, "role_name", inheritRole[1].RoleName), resource.TestCheckResourceAttr(InheritedRoleResourceNameTwo, "actions.#", cast.ToString(len(inheritRole[1].Actions))), resource.TestCheckResourceAttr(InheritedRoleResourceNameTwo, "actions.0.action", inheritRole[1].Actions[0].Action), @@ -168,8 +161,6 @@ func TestAccConfigRSCustomDBRoles_WithInheritedRoles(t *testing.T) { resource.TestCheckResourceAttrSet(testRoleResourceName, "project_id"), resource.TestCheckResourceAttrSet(testRoleResourceName, "role_name"), resource.TestCheckResourceAttrSet(testRoleResourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(testRoleResourceName, "project_id", projectID), resource.TestCheckResourceAttr(testRoleResourceName, "role_name", testRole.RoleName), resource.TestCheckResourceAttr(testRoleResourceName, "actions.#", cast.ToString(len(testRole.Actions))), resource.TestCheckResourceAttr(testRoleResourceName, "actions.0.action", testRole.Actions[0].Action), @@ -178,7 +169,7 @@ func TestAccConfigRSCustomDBRoles_WithInheritedRoles(t *testing.T) { ), }, { - Config: testAccMongoDBAtlasCustomDBRolesConfigWithInheritedRoles(projectID, inheritRoleUpdated, testRoleUpdated), + Config: testAccMongoDBAtlasCustomDBRolesConfigWithInheritedRoles(orgID, projectName, inheritRoleUpdated, testRoleUpdated), Check: resource.ComposeTestCheckFunc( // For Inherited Role @@ -187,8 +178,6 @@ func TestAccConfigRSCustomDBRoles_WithInheritedRoles(t *testing.T) { resource.TestCheckResourceAttrSet(InheritedRoleResourceNameOne, "project_id"), resource.TestCheckResourceAttrSet(InheritedRoleResourceNameOne, "role_name"), resource.TestCheckResourceAttrSet(InheritedRoleResourceNameOne, "actions.0.action"), - - resource.TestCheckResourceAttr(InheritedRoleResourceNameOne, "project_id", projectID), resource.TestCheckResourceAttr(InheritedRoleResourceNameOne, "role_name", inheritRoleUpdated[0].RoleName), resource.TestCheckResourceAttr(InheritedRoleResourceNameOne, "actions.#", cast.ToString(len(inheritRoleUpdated[0].Actions))), resource.TestCheckResourceAttr(InheritedRoleResourceNameOne, "actions.0.action", inheritRoleUpdated[0].Actions[0].Action), @@ -199,8 +188,6 @@ func TestAccConfigRSCustomDBRoles_WithInheritedRoles(t *testing.T) { resource.TestCheckResourceAttrSet(InheritedRoleResourceNameTwo, "project_id"), resource.TestCheckResourceAttrSet(InheritedRoleResourceNameTwo, "role_name"), resource.TestCheckResourceAttrSet(InheritedRoleResourceNameTwo, "actions.0.action"), - - resource.TestCheckResourceAttr(InheritedRoleResourceNameTwo, "project_id", projectID), resource.TestCheckResourceAttr(InheritedRoleResourceNameTwo, "role_name", inheritRoleUpdated[1].RoleName), resource.TestCheckResourceAttr(InheritedRoleResourceNameTwo, "actions.#", cast.ToString(len(inheritRoleUpdated[1].Actions))), resource.TestCheckResourceAttr(InheritedRoleResourceNameTwo, "actions.0.action", inheritRoleUpdated[1].Actions[0].Action), @@ -211,8 +198,6 @@ func TestAccConfigRSCustomDBRoles_WithInheritedRoles(t *testing.T) { resource.TestCheckResourceAttrSet(testRoleResourceName, "project_id"), resource.TestCheckResourceAttrSet(testRoleResourceName, "role_name"), resource.TestCheckResourceAttrSet(testRoleResourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(testRoleResourceName, "project_id", projectID), resource.TestCheckResourceAttr(testRoleResourceName, "role_name", testRoleUpdated.RoleName), resource.TestCheckResourceAttr(testRoleResourceName, "actions.#", cast.ToString(len(testRoleUpdated.Actions))), resource.TestCheckResourceAttr(testRoleResourceName, "actions.0.action", testRoleUpdated.Actions[0].Action), @@ -228,7 +213,8 @@ func TestAccConfigRSCustomDBRoles_MultipleCustomRoles(t *testing.T) { var ( testRoleResourceName = "mongodbatlas_custom_db_role.test_role" InheritedRoleResourceName = "mongodbatlas_custom_db_role.inherited_role" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") ) inheritRole := &matlas.CustomDBRole{ @@ -343,13 +329,13 @@ func TestAccConfigRSCustomDBRoles_MultipleCustomRoles(t *testing.T) { }, } - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasCustomDBRolesDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasCustomDBRolesConfigMultiple(projectID, inheritRole, testRole), + Config: testAccMongoDBAtlasCustomDBRolesConfigMultiple(orgID, projectName, inheritRole, testRole), Check: resource.ComposeTestCheckFunc( // For Inherited Role @@ -357,8 +343,6 @@ func TestAccConfigRSCustomDBRoles_MultipleCustomRoles(t *testing.T) { resource.TestCheckResourceAttrSet(InheritedRoleResourceName, "project_id"), resource.TestCheckResourceAttrSet(InheritedRoleResourceName, "role_name"), resource.TestCheckResourceAttrSet(InheritedRoleResourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(InheritedRoleResourceName, "project_id", projectID), resource.TestCheckResourceAttr(InheritedRoleResourceName, "role_name", inheritRole.RoleName), resource.TestCheckResourceAttr(InheritedRoleResourceName, "actions.#", cast.ToString(len(inheritRole.Actions))), resource.TestCheckResourceAttr(InheritedRoleResourceName, "actions.0.action", inheritRole.Actions[0].Action), @@ -369,8 +353,6 @@ func TestAccConfigRSCustomDBRoles_MultipleCustomRoles(t *testing.T) { resource.TestCheckResourceAttrSet(testRoleResourceName, "project_id"), resource.TestCheckResourceAttrSet(testRoleResourceName, "role_name"), resource.TestCheckResourceAttrSet(testRoleResourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(testRoleResourceName, "project_id", projectID), resource.TestCheckResourceAttr(testRoleResourceName, "role_name", testRole.RoleName), resource.TestCheckResourceAttr(testRoleResourceName, "actions.#", cast.ToString(len(testRole.Actions))), resource.TestCheckResourceAttr(testRoleResourceName, "actions.0.action", testRole.Actions[0].Action), @@ -378,7 +360,7 @@ func TestAccConfigRSCustomDBRoles_MultipleCustomRoles(t *testing.T) { ), }, { - Config: testAccMongoDBAtlasCustomDBRolesConfigMultiple(projectID, inheritRoleUpdated, testRoleUpdated), + Config: testAccMongoDBAtlasCustomDBRolesConfigMultiple(orgID, projectName, inheritRoleUpdated, testRoleUpdated), Check: resource.ComposeTestCheckFunc( // For Inherited Role @@ -386,8 +368,6 @@ func TestAccConfigRSCustomDBRoles_MultipleCustomRoles(t *testing.T) { resource.TestCheckResourceAttrSet(InheritedRoleResourceName, "project_id"), resource.TestCheckResourceAttrSet(InheritedRoleResourceName, "role_name"), resource.TestCheckResourceAttrSet(InheritedRoleResourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(InheritedRoleResourceName, "project_id", projectID), resource.TestCheckResourceAttr(InheritedRoleResourceName, "role_name", inheritRoleUpdated.RoleName), resource.TestCheckResourceAttr(InheritedRoleResourceName, "actions.#", cast.ToString(len(inheritRoleUpdated.Actions))), resource.TestCheckResourceAttr(InheritedRoleResourceName, "actions.0.action", inheritRoleUpdated.Actions[0].Action), @@ -398,8 +378,6 @@ func TestAccConfigRSCustomDBRoles_MultipleCustomRoles(t *testing.T) { resource.TestCheckResourceAttrSet(testRoleResourceName, "project_id"), resource.TestCheckResourceAttrSet(testRoleResourceName, "role_name"), resource.TestCheckResourceAttrSet(testRoleResourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(testRoleResourceName, "project_id", projectID), resource.TestCheckResourceAttr(testRoleResourceName, "role_name", testRoleUpdated.RoleName), resource.TestCheckResourceAttr(testRoleResourceName, "actions.#", cast.ToString(len(testRoleUpdated.Actions))), resource.TestCheckResourceAttr(testRoleResourceName, "actions.0.action", testRoleUpdated.Actions[0].Action), @@ -415,7 +393,8 @@ func TestAccConfigRSCustomDBRoles_MultipleResources(t *testing.T) { t.Skip() var ( resourceName = "mongodbatlas_custom_db_role.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") roleName string ) @@ -424,19 +403,17 @@ func TestAccConfigRSCustomDBRoles_MultipleResources(t *testing.T) { t.Run(roleName, func(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasCustomDBRolesDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasCustomDBRolesConfigBasic(projectID, roleName, "INSERT", fmt.Sprintf("test-acc-db_name-%s", acctest.RandString(5))), + Config: testAccMongoDBAtlasCustomDBRolesConfigBasic(orgID, projectName, roleName, "INSERT", fmt.Sprintf("test-acc-db_name-%s", acctest.RandString(5))), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasCustomDBRolesExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "role_name"), resource.TestCheckResourceAttrSet(resourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(resourceName, "project_id", projectID), resource.TestCheckResourceAttr(resourceName, "role_name", roleName), resource.TestCheckResourceAttr(resourceName, "actions.#", "1"), resource.TestCheckResourceAttr(resourceName, "actions.0.action", "INSERT"), @@ -452,18 +429,19 @@ func TestAccConfigRSCustomDBRoles_MultipleResources(t *testing.T) { func TestAccConfigRSCustomDBRoles_importBasic(t *testing.T) { var ( resourceName = "mongodbatlas_custom_db_role.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") roleName = fmt.Sprintf("test-acc-custom_role-%s", acctest.RandString(5)) databaseName = fmt.Sprintf("test-acc-db_name-%s", acctest.RandString(5)) ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasCustomDBRolesDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasCustomDBRolesConfigBasic(projectID, roleName, "INSERT", databaseName), + Config: testAccMongoDBAtlasCustomDBRolesConfigBasic(orgID, projectName, roleName, "INSERT", databaseName), }, { ResourceName: resourceName, @@ -479,7 +457,8 @@ func TestAccConfigRSCustomDBRoles_UpdatedInheritRoles(t *testing.T) { var ( testRoleResourceName = "mongodbatlas_custom_db_role.test_role" InheritedRoleResourceName = "mongodbatlas_custom_db_role.inherited_role" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") ) inheritRole := &matlas.CustomDBRole{ @@ -553,13 +532,13 @@ func TestAccConfigRSCustomDBRoles_UpdatedInheritRoles(t *testing.T) { }, } - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasCustomDBRolesDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasCustomDBRolesConfigMultiple(projectID, inheritRole, testRole), + Config: testAccMongoDBAtlasCustomDBRolesConfigMultiple(orgID, projectName, inheritRole, testRole), Check: resource.ComposeTestCheckFunc( // For Inherited Role @@ -567,8 +546,6 @@ func TestAccConfigRSCustomDBRoles_UpdatedInheritRoles(t *testing.T) { resource.TestCheckResourceAttrSet(InheritedRoleResourceName, "project_id"), resource.TestCheckResourceAttrSet(InheritedRoleResourceName, "role_name"), resource.TestCheckResourceAttrSet(InheritedRoleResourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(InheritedRoleResourceName, "project_id", projectID), resource.TestCheckResourceAttr(InheritedRoleResourceName, "role_name", inheritRole.RoleName), resource.TestCheckResourceAttr(InheritedRoleResourceName, "actions.#", cast.ToString(len(inheritRole.Actions))), resource.TestCheckResourceAttr(InheritedRoleResourceName, "actions.0.action", inheritRole.Actions[0].Action), @@ -578,14 +555,12 @@ func TestAccConfigRSCustomDBRoles_UpdatedInheritRoles(t *testing.T) { testAccCheckMongoDBAtlasCustomDBRolesExists(testRoleResourceName), resource.TestCheckResourceAttrSet(testRoleResourceName, "project_id"), resource.TestCheckResourceAttrSet(testRoleResourceName, "role_name"), - - resource.TestCheckResourceAttr(testRoleResourceName, "project_id", projectID), resource.TestCheckResourceAttr(testRoleResourceName, "role_name", testRole.RoleName), resource.TestCheckResourceAttr(testRoleResourceName, "inherited_roles.#", "1"), ), }, { - Config: testAccMongoDBAtlasCustomDBRolesConfigMultiple(projectID, inheritRoleUpdated, testRole), + Config: testAccMongoDBAtlasCustomDBRolesConfigMultiple(orgID, projectName, inheritRoleUpdated, testRole), Check: resource.ComposeTestCheckFunc( // For Inherited Role @@ -593,8 +568,6 @@ func TestAccConfigRSCustomDBRoles_UpdatedInheritRoles(t *testing.T) { resource.TestCheckResourceAttrSet(InheritedRoleResourceName, "project_id"), resource.TestCheckResourceAttrSet(InheritedRoleResourceName, "role_name"), resource.TestCheckResourceAttrSet(InheritedRoleResourceName, "actions.0.action"), - - resource.TestCheckResourceAttr(InheritedRoleResourceName, "project_id", projectID), resource.TestCheckResourceAttr(InheritedRoleResourceName, "role_name", inheritRoleUpdated.RoleName), resource.TestCheckResourceAttr(InheritedRoleResourceName, "actions.#", cast.ToString(len(inheritRoleUpdated.Actions))), resource.TestCheckResourceAttr(InheritedRoleResourceName, "actions.0.action", inheritRoleUpdated.Actions[0].Action), @@ -604,8 +577,6 @@ func TestAccConfigRSCustomDBRoles_UpdatedInheritRoles(t *testing.T) { testAccCheckMongoDBAtlasCustomDBRolesExists(testRoleResourceName), resource.TestCheckResourceAttrSet(testRoleResourceName, "project_id"), resource.TestCheckResourceAttrSet(testRoleResourceName, "role_name"), - - resource.TestCheckResourceAttr(testRoleResourceName, "project_id", projectID), resource.TestCheckResourceAttr(testRoleResourceName, "role_name", testRole.RoleName), resource.TestCheckResourceAttr(testRoleResourceName, "inherited_roles.#", "1"), ), @@ -668,59 +639,68 @@ func testAccCheckMongoDBAtlasCustomDBRolesImportStateIDFunc(resourceName string) } } -func testAccMongoDBAtlasCustomDBRolesConfigBasic(projectID, roleName, action, databaseName string) string { +func testAccMongoDBAtlasCustomDBRolesConfigBasic(orgID, projectName, roleName, action, databaseName string) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_custom_db_role" "test" { - project_id = "%s" - role_name = "%s" + project_id = mongodbatlas_project.test.id + role_name = %[3]q actions { - action = "%s" + action = %[4]q resources { collection_name = "" - database_name = "%s" + database_name = %[5]q } } } - `, projectID, roleName, action, databaseName) + `, orgID, projectName, roleName, action, databaseName) } -func testAccMongoDBAtlasCustomDBRolesConfigWithInheritedRoles(projectID string, inheritedRole []matlas.CustomDBRole, testRole *matlas.CustomDBRole) string { +func testAccMongoDBAtlasCustomDBRolesConfigWithInheritedRoles(orgID, projectName string, inheritedRole []matlas.CustomDBRole, testRole *matlas.CustomDBRole) string { return fmt.Sprintf(` + + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_custom_db_role" "inherited_role_one" { - project_id = "%s" - role_name = "%s" + project_id = mongodbatlas_project.test.id + role_name = %[3]q actions { - action = "%s" + action = %[4]q resources { collection_name = "" - database_name = "%s" + database_name = %[5]q } } } resource "mongodbatlas_custom_db_role" "inherited_role_two" { project_id = "${mongodbatlas_custom_db_role.inherited_role_one.project_id}" - role_name = "%s" + role_name = %[6]q actions { - action = "%s" + action = %[7]q resources { - cluster = %t + cluster = %[8]t } } } resource "mongodbatlas_custom_db_role" "test_role" { project_id = "${mongodbatlas_custom_db_role.inherited_role_one.project_id}" - role_name = "%s" + role_name = %[9]q actions { - action = "%s" + action = %[10]q resources { collection_name = "" - database_name = "%s" + database_name = %[11]q } } @@ -734,14 +714,14 @@ func testAccMongoDBAtlasCustomDBRolesConfigWithInheritedRoles(projectID string, database_name = "admin" } } - `, projectID, + `, orgID, projectName, inheritedRole[0].RoleName, inheritedRole[0].Actions[0].Action, *inheritedRole[0].Actions[0].Resources[0].DB, inheritedRole[1].RoleName, inheritedRole[1].Actions[0].Action, *inheritedRole[1].Actions[0].Resources[0].Cluster, testRole.RoleName, testRole.Actions[0].Action, *testRole.Actions[0].Resources[0].DB, ) } -func testAccMongoDBAtlasCustomDBRolesConfigMultiple(projectID string, inheritedRole, testRole *matlas.CustomDBRole) string { +func testAccMongoDBAtlasCustomDBRolesConfigMultiple(orgID, projectName string, inheritedRole, testRole *matlas.CustomDBRole) string { getCustomRoleFields := func(customRole *matlas.CustomDBRole) map[string]string { var ( actions string @@ -786,22 +766,26 @@ func testAccMongoDBAtlasCustomDBRolesConfigMultiple(projectID string, inheritedR } return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_custom_db_role" "inherited_role" { - project_id = "%s" - role_name = "%s" + project_id = mongodbatlas_project.test.id + role_name = %[3]q - %s + %[4]s } resource "mongodbatlas_custom_db_role" "test_role" { project_id = "${mongodbatlas_custom_db_role.inherited_role.project_id}" - role_name = "%s" + role_name = %[5]q - %s + %[6]s - %s + %[7]s } - `, projectID, + `, orgID, projectName, inheritedRole.RoleName, getCustomRoleFields(inheritedRole)["actions"], testRole.RoleName, getCustomRoleFields(testRole)["actions"], getCustomRoleFields(testRole)["inherited_roles"], ) diff --git a/mongodbatlas/resource_mongodbatlas_custom_dns_configuration_cluster_aws_test.go b/mongodbatlas/resource_mongodbatlas_custom_dns_configuration_cluster_aws_test.go index 5390b63947..0c5ef2f4f3 100644 --- a/mongodbatlas/resource_mongodbatlas_custom_dns_configuration_cluster_aws_test.go +++ b/mongodbatlas/resource_mongodbatlas_custom_dns_configuration_cluster_aws_test.go @@ -6,6 +6,7 @@ import ( "os" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) @@ -13,16 +14,17 @@ import ( func TestAccConfigRSCustomDNSConfigurationAWS_basic(t *testing.T) { var ( resourceName = "mongodbatlas_custom_dns_configuration_cluster_aws.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasCustomDNSConfigurationAWSDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasCustomDNSConfigurationAWSConfig(projectID, true), + Config: testAccMongoDBAtlasCustomDNSConfigurationAWSConfig(orgID, projectName, true), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasCustomDNSConfigurationAWSExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -30,7 +32,7 @@ func TestAccConfigRSCustomDNSConfigurationAWS_basic(t *testing.T) { ), }, { - Config: testAccMongoDBAtlasCustomDNSConfigurationAWSConfig(projectID, false), + Config: testAccMongoDBAtlasCustomDNSConfigurationAWSConfig(orgID, projectName, false), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasCustomDNSConfigurationAWSExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -38,7 +40,7 @@ func TestAccConfigRSCustomDNSConfigurationAWS_basic(t *testing.T) { ), }, { - Config: testAccMongoDBAtlasCustomDNSConfigurationAWSConfig(projectID, true), + Config: testAccMongoDBAtlasCustomDNSConfigurationAWSConfig(orgID, projectName, true), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasCustomDNSConfigurationAWSExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -52,16 +54,17 @@ func TestAccConfigRSCustomDNSConfigurationAWS_basic(t *testing.T) { func TestAccConfigRSCustomDNSConfigurationAWS_importBasic(t *testing.T) { var ( resourceName = "mongodbatlas_custom_dns_configuration_cluster_aws.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasCustomDNSConfigurationAWSDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasCustomDNSConfigurationAWSConfig(projectID, true), + Config: testAccMongoDBAtlasCustomDNSConfigurationAWSConfig(orgID, projectName, true), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "enabled"), @@ -127,10 +130,14 @@ func testAccCheckMongoDBAtlasCustomDNSConfigurationAWSStateIDFunc(resourceName s } } -func testAccMongoDBAtlasCustomDNSConfigurationAWSConfig(projectID string, enabled bool) string { +func testAccMongoDBAtlasCustomDNSConfigurationAWSConfig(orgID, projectName string, enabled bool) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_custom_dns_configuration_cluster_aws" "test" { - project_id = "%s" - enabled = %t - }`, projectID, enabled) + project_id = mongodbatlas_project.test.id + enabled = %[3]t + }`, orgID, projectName, enabled) } diff --git a/mongodbatlas/resource_mongodbatlas_database_user_test.go b/mongodbatlas/resource_mongodbatlas_database_user_test.go index 3d2e446305..69f452d7d6 100644 --- a/mongodbatlas/resource_mongodbatlas_database_user_test.go +++ b/mongodbatlas/resource_mongodbatlas_database_user_test.go @@ -23,7 +23,7 @@ func TestAccConfigRSDatabaseUser_basic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ @@ -66,7 +66,7 @@ func TestAccConfigRSDatabaseUser_withX509TypeCustomer(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ @@ -97,7 +97,7 @@ func TestAccConfigRSDatabaseUser_withX509TypeManaged(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ @@ -127,7 +127,7 @@ func TestAccConfigRSDatabaseUser_withAWSIAMType(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ @@ -161,7 +161,7 @@ func TestAccConfigRSDatabaseUser_withAWSIAMType_import(t *testing.T) { } resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ @@ -198,7 +198,7 @@ func TestAccConfigRSDatabaseUser_WithLabels(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ @@ -279,7 +279,7 @@ func TestAccConfigRSDatabaseUser_withRoles(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ @@ -343,7 +343,7 @@ func TestAccConfigRSDatabaseUser_withScopes(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ @@ -405,7 +405,7 @@ func TestAccConfigRSDatabaseUser_withScopesAndEmpty(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ @@ -460,7 +460,7 @@ func TestAccConfigRSDatabaseUser_withLDAPAuthType(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ @@ -489,7 +489,7 @@ func TestAccConfigRSDatabaseUser_importBasic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ @@ -525,7 +525,7 @@ func TestAccConfigRSDatabaseUser_importX509TypeCustomer(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ @@ -562,7 +562,7 @@ func TestAccConfigRSDatabaseUser_importLDAPAuthType(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy, Steps: []resource.TestStep{ diff --git a/mongodbatlas/resource_mongodbatlas_event_trigger_test.go b/mongodbatlas/resource_mongodbatlas_event_trigger_test.go index 10d0eecce3..94350c415d 100644 --- a/mongodbatlas/resource_mongodbatlas_event_trigger_test.go +++ b/mongodbatlas/resource_mongodbatlas_event_trigger_test.go @@ -15,7 +15,7 @@ import ( ) func TestAccConfigRSEventTriggerDatabase_basic(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( resourceName = "mongodbatlas_event_trigger.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") @@ -49,7 +49,7 @@ func TestAccConfigRSEventTriggerDatabase_basic(t *testing.T) { } resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasEventTriggerDestroy, Steps: []resource.TestStep{ @@ -78,7 +78,7 @@ func TestAccConfigRSEventTriggerDatabase_basic(t *testing.T) { } func TestAccConfigRSEventTriggerDatabase_eventProccesor(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( resourceName = "mongodbatlas_event_trigger.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") @@ -144,7 +144,7 @@ func TestAccConfigRSEventTriggerDatabase_eventProccesor(t *testing.T) { } func TestAccConfigRSEventTriggerAuth_basic(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( resourceName = "mongodbatlas_event_trigger.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") @@ -203,7 +203,7 @@ func TestAccConfigRSEventTriggerAuth_basic(t *testing.T) { } func TestAccConfigRSEventTriggerAuth_eventProcessor(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( resourceName = "mongodbatlas_event_trigger.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") @@ -264,7 +264,7 @@ func TestAccConfigRSEventTriggerAuth_eventProcessor(t *testing.T) { } func TestAccConfigRSEventTriggerSchedule_basic(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( resourceName = "mongodbatlas_event_trigger.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") @@ -320,7 +320,7 @@ func TestAccConfigRSEventTriggerSchedule_basic(t *testing.T) { } func TestAccConfigRSEventTriggerSchedule_eventProcessor(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( resourceName = "mongodbatlas_event_trigger.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") @@ -378,7 +378,7 @@ func TestAccConfigRSEventTriggerSchedule_eventProcessor(t *testing.T) { } func TestAccConfigRSEventTriggerFunction_basic(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( resourceName = "mongodbatlas_event_trigger.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") diff --git a/mongodbatlas/resource_mongodbatlas_maintenance_window_test.go b/mongodbatlas/resource_mongodbatlas_maintenance_window_test.go index 56de99225d..c5512cd20c 100644 --- a/mongodbatlas/resource_mongodbatlas_maintenance_window_test.go +++ b/mongodbatlas/resource_mongodbatlas_maintenance_window_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/go-test/deep" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/spf13/cast" @@ -18,45 +19,41 @@ func TestAccConfigRSMaintenanceWindow_basic(t *testing.T) { var ( maintenance matlas.MaintenanceWindow resourceName = "mongodbatlas_maintenance_window.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") dayOfWeek = 7 hourOfDay = 3 dayOfWeekUpdated = 4 hourOfDayUpdated = 5 ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, - CheckDestroy: testAccCheckMongoDBAtlasMaintenanceWindowDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasMaintenanceWindowConfig(projectID, dayOfWeek, hourOfDay), + Config: testAccMongoDBAtlasMaintenanceWindowConfig(orgID, projectName, dayOfWeek, hourOfDay), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasMaintenanceWindowExists(resourceName, &maintenance), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "day_of_week"), resource.TestCheckResourceAttrSet(resourceName, "hour_of_day"), - resource.TestCheckResourceAttr(resourceName, "day_of_week", cast.ToString(dayOfWeek)), resource.TestCheckResourceAttr(resourceName, "hour_of_day", cast.ToString(hourOfDay)), resource.TestCheckResourceAttr(resourceName, "number_of_deferrals", "0"), - testAccCheckMongoDBAtlasMaintenanceWindowAttributes("day_of_week", dayOfWeek, &maintenance.DayOfWeek), ), }, { - Config: testAccMongoDBAtlasMaintenanceWindowConfig(projectID, dayOfWeekUpdated, hourOfDayUpdated), + Config: testAccMongoDBAtlasMaintenanceWindowConfig(orgID, projectName, dayOfWeekUpdated, hourOfDayUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasMaintenanceWindowExists(resourceName, &maintenance), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "day_of_week"), resource.TestCheckResourceAttrSet(resourceName, "hour_of_day"), - resource.TestCheckResourceAttr(resourceName, "day_of_week", cast.ToString(dayOfWeekUpdated)), resource.TestCheckResourceAttr(resourceName, "hour_of_day", cast.ToString(hourOfDayUpdated)), resource.TestCheckResourceAttr(resourceName, "number_of_deferrals", "0"), - testAccCheckMongoDBAtlasMaintenanceWindowAttributes("day_of_week", dayOfWeekUpdated, &maintenance.DayOfWeek), ), }, @@ -68,29 +65,27 @@ func TestAccConfigRSMaintenanceWindow_importBasic(t *testing.T) { var ( maintenance matlas.MaintenanceWindow resourceName = "mongodbatlas_maintenance_window.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") dayOfWeek = 1 hourOfDay = 3 ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, - CheckDestroy: testAccCheckMongoDBAtlasMaintenanceWindowDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasMaintenanceWindowConfig(projectID, dayOfWeek, hourOfDay), + Config: testAccMongoDBAtlasMaintenanceWindowConfig(orgID, projectName, dayOfWeek, hourOfDay), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasMaintenanceWindowExists(resourceName, &maintenance), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "day_of_week"), resource.TestCheckResourceAttrSet(resourceName, "hour_of_day"), - resource.TestCheckResourceAttr(resourceName, "day_of_week", cast.ToString(dayOfWeek)), resource.TestCheckResourceAttr(resourceName, "hour_of_day", cast.ToString(hourOfDay)), resource.TestCheckResourceAttr(resourceName, "number_of_deferrals", "0"), resource.TestCheckResourceAttr(resourceName, "start_asap", "false"), - testAccCheckMongoDBAtlasMaintenanceWindowAttributes("day_of_week", dayOfWeek, &maintenance.DayOfWeek), ), }, @@ -108,29 +103,27 @@ func TestAccConfigRSMaintenanceWindow_autoDeferActivated(t *testing.T) { var ( maintenance matlas.MaintenanceWindow resourceName = "mongodbatlas_maintenance_window.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") dayOfWeek = 7 hourOfDay = 3 ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, - CheckDestroy: testAccCheckMongoDBAtlasMaintenanceWindowDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasMaintenanceWindowConfigAutoDeferEnabled(projectID, dayOfWeek, hourOfDay), + Config: testAccMongoDBAtlasMaintenanceWindowConfigAutoDeferEnabled(orgID, projectName, dayOfWeek, hourOfDay), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasMaintenanceWindowExists(resourceName, &maintenance), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "day_of_week"), resource.TestCheckResourceAttrSet(resourceName, "hour_of_day"), - resource.TestCheckResourceAttr(resourceName, "day_of_week", cast.ToString(dayOfWeek)), resource.TestCheckResourceAttr(resourceName, "hour_of_day", cast.ToString(hourOfDay)), resource.TestCheckResourceAttr(resourceName, "number_of_deferrals", "0"), resource.TestCheckResourceAttr(resourceName, "auto_defer_once_enabled", "true"), - testAccCheckMongoDBAtlasMaintenanceWindowAttributes("day_of_week", dayOfWeek, &maintenance.DayOfWeek), ), }, @@ -138,14 +131,18 @@ func TestAccConfigRSMaintenanceWindow_autoDeferActivated(t *testing.T) { }) } -func testAccMongoDBAtlasMaintenanceWindowConfigAutoDeferEnabled(projectID string, dayOfWeek, hourOfDay int) string { +func testAccMongoDBAtlasMaintenanceWindowConfigAutoDeferEnabled(orgID, projectName string, dayOfWeek, hourOfDay int) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_maintenance_window" "test" { - project_id = "%s" - day_of_week = %d - hour_of_day = %d + project_id = mongodbatlas_project.test.id + day_of_week = %[3]d + hour_of_day = %[4]d auto_defer_once_enabled = true - }`, projectID, dayOfWeek, hourOfDay) + }`, orgID, projectName, dayOfWeek, hourOfDay) } func testAccCheckMongoDBAtlasMaintenanceWindowExists(resourceName string, maintenance *matlas.MaintenanceWindow) resource.TestCheckFunc { @@ -184,23 +181,6 @@ func testAccCheckMongoDBAtlasMaintenanceWindowAttributes(attr string, expected i } } -func testAccCheckMongoDBAtlasMaintenanceWindowDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*MongoDBClient).Atlas - - for _, rs := range s.RootModule().Resources { - if rs.Type != "mongodbatlas_maintenance_window" { - continue - } - - _, _, err := conn.MaintenanceWindows.Get(context.Background(), rs.Primary.ID) - if err != nil { - return fmt.Errorf("maintenance Window (%s) does not exist", rs.Primary.ID) - } - } - - return nil -} - func testAccCheckMongoDBAtlasMaintenanceWindowImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] @@ -212,11 +192,15 @@ func testAccCheckMongoDBAtlasMaintenanceWindowImportStateIDFunc(resourceName str } } -func testAccMongoDBAtlasMaintenanceWindowConfig(projectID string, dayOfWeek, hourOfDay int) string { +func testAccMongoDBAtlasMaintenanceWindowConfig(orgID, projectName string, dayOfWeek, hourOfDay int) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_maintenance_window" "test" { - project_id = "%s" - day_of_week = %d - hour_of_day = %d - }`, projectID, dayOfWeek, hourOfDay) + project_id = mongodbatlas_project.test.id + day_of_week = %[3]d + hour_of_day = %[4]d + }`, orgID, projectName, dayOfWeek, hourOfDay) } diff --git a/mongodbatlas/resource_mongodbatlas_org_invitation_test.go b/mongodbatlas/resource_mongodbatlas_org_invitation_test.go index 00edd7fabb..3d9c041067 100644 --- a/mongodbatlas/resource_mongodbatlas_org_invitation_test.go +++ b/mongodbatlas/resource_mongodbatlas_org_invitation_test.go @@ -23,8 +23,8 @@ func TestAccConfigRSOrgInvitation_basic(t *testing.T) { updateRoles = []string{"ORG_GROUP_CREATOR", "ORG_BILLING_ADMIN"} ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasOrgInvitationDestroy, Steps: []resource.TestStep{ @@ -64,7 +64,7 @@ func TestAccConfigRSOrgInvitation_importBasic(t *testing.T) { ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasOrgInvitationDestroy, Steps: []resource.TestStep{ @@ -75,7 +75,6 @@ func TestAccConfigRSOrgInvitation_importBasic(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "username"), resource.TestCheckResourceAttrSet(resourceName, "roles.#"), resource.TestCheckResourceAttrSet(resourceName, "invitation_id"), - resource.TestCheckResourceAttr(resourceName, "org_id", orgID), resource.TestCheckResourceAttr(resourceName, "username", name), resource.TestCheckResourceAttr(resourceName, "roles.#", "1"), diff --git a/mongodbatlas/resource_mongodbatlas_organization_test.go b/mongodbatlas/resource_mongodbatlas_organization_test.go index d8b5daa5b0..4daf0ce8f4 100644 --- a/mongodbatlas/resource_mongodbatlas_organization_test.go +++ b/mongodbatlas/resource_mongodbatlas_organization_test.go @@ -13,7 +13,7 @@ import ( ) func TestAccConfigRSOrganization_Basic(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( resourceName = "mongodbatlas_organization.test" orgOwnerID = os.Getenv("MONGODB_ATLAS_ORG_OWNER_ID") @@ -41,7 +41,7 @@ func TestAccConfigRSOrganization_Basic(t *testing.T) { } func TestAccConfigRSOrganization_importBasic(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( resourceName = "mongodbatlas_organization.test" orgOwnerID = os.Getenv("MONGODB_ATLAS_ORG_OWNER_ID") diff --git a/mongodbatlas/resource_mongodbatlas_project_api_key_test.go b/mongodbatlas/resource_mongodbatlas_project_api_key_test.go index 8132de4e1d..167462a165 100644 --- a/mongodbatlas/resource_mongodbatlas_project_api_key_test.go +++ b/mongodbatlas/resource_mongodbatlas_project_api_key_test.go @@ -14,23 +14,22 @@ import ( func TestAccConfigRSProjectAPIKey_Basic(t *testing.T) { var ( resourceName = "mongodbatlas_project_api_key.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") description = fmt.Sprintf("test-acc-project-api_key-%s", acctest.RandString(5)) roleName = "GROUP_OWNER" ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(projectID, description, roleName), + Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "description"), - - resource.TestCheckResourceAttr(resourceName, "project_id", projectID), resource.TestCheckResourceAttr(resourceName, "description", description), ), }, @@ -41,23 +40,22 @@ func TestAccConfigRSProjectAPIKey_Basic(t *testing.T) { func TestAccConfigRSProjectAPIKey_Multiple(t *testing.T) { var ( resourceName = "mongodbatlas_project_api_key.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") description = fmt.Sprintf("test-acc-project-api_key-%s", acctest.RandString(5)) roleName = "GROUP_OWNER" ) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasProjectAPIKeyConfigMultiple(projectID, description, roleName), + Config: testAccMongoDBAtlasProjectAPIKeyConfigMultiple(orgID, projectName, description, roleName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "description"), - - resource.TestCheckResourceAttr(resourceName, "project_id", projectID), resource.TestCheckResourceAttr(resourceName, "description", description), ), }, @@ -68,18 +66,19 @@ func TestAccConfigRSProjectAPIKey_Multiple(t *testing.T) { func TestAccConfigRSProjectAPIKey_importBasic(t *testing.T) { var ( resourceName = "mongodbatlas_project_api_key.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") description = fmt.Sprintf("test-acc-import-project-api_key-%s", acctest.RandString(5)) roleName = "GROUP_OWNER" ) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(projectID, description, roleName), + Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName), }, { ResourceName: resourceName, @@ -127,26 +126,34 @@ func testAccCheckMongoDBAtlasProjectAPIKeyImportStateIDFunc(resourceName string) } } -func testAccMongoDBAtlasProjectAPIKeyConfigBasic(projectID, description, roleNames string) string { +func testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleNames string) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_project_api_key" "test" { - project_id = %[1]q - description = %[2]q - role_names = [%[3]q] + project_id = mongodbatlas_project.test.id + description = %[3]q + role_names = [%[4]q] } - `, projectID, description, roleNames) + `, orgID, projectName, description, roleNames) } -func testAccMongoDBAtlasProjectAPIKeyConfigMultiple(projectID, description, roleNames string) string { +func testAccMongoDBAtlasProjectAPIKeyConfigMultiple(orgID, projectName, description, roleNames string) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_project_api_key" "test" { - project_id = %[1]q - description = %[2]q + project_id = mongodbatlas_project.test.id + description = %[3]q project_assignment { - project_id = %[1]q - role_names = [%[3]q] + project_id = mongodbatlas_project.test.id + role_names = [%[4]q] } } - `, projectID, description, roleNames) + `, orgID, projectName, description, roleNames) } diff --git a/mongodbatlas/resource_mongodbatlas_search_index_test.go b/mongodbatlas/resource_mongodbatlas_search_index_test.go index 0020253dc3..2bb2f268dc 100644 --- a/mongodbatlas/resource_mongodbatlas_search_index_test.go +++ b/mongodbatlas/resource_mongodbatlas_search_index_test.go @@ -14,14 +14,16 @@ import ( func TestAccClusterRSSearchIndex_basic(t *testing.T) { var ( - index matlas.SearchIndex - resourceName = "mongodbatlas_search_index.test" - clusterName = acctest.RandomWithPrefix("test-acc-index") - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - name = "name_test" + index matlas.SearchIndex + resourceName = "mongodbatlas_search_index.test" + clusterName = acctest.RandomWithPrefix("test-acc-index") + projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + name = "name_test" + datasourceIndexesName = "data.mongodbatlas_search_indexes.data_index" + datasourceName = "data.mongodbatlas_search_indexes.data_index" ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasSearchIndexDestroy, Steps: []resource.TestStep{ @@ -32,6 +34,23 @@ func TestAccClusterRSSearchIndex_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "name", name), resource.TestCheckResourceAttr(resourceName, "project_id", projectID), resource.TestCheckResourceAttr(resourceName, "cluster_name", clusterName), + resource.TestCheckResourceAttrSet(datasourceName, "name"), + resource.TestCheckResourceAttrSet(datasourceName, "project_id"), + resource.TestCheckResourceAttrSet(datasourceName, "name"), + resource.TestCheckResourceAttrSet(datasourceName, "collection_name"), + resource.TestCheckResourceAttrSet(datasourceName, "database"), + resource.TestCheckResourceAttrSet(datasourceName, "search_analyzer"), + resource.TestCheckResourceAttrSet(datasourceName, "synonyms.#"), + resource.TestCheckResourceAttr(datasourceName, "synonyms.#", "1"), + resource.TestCheckResourceAttr(datasourceName, "synonyms.0.analyzer", "lucene.simple"), + resource.TestCheckResourceAttr(datasourceName, "synonyms.0.name", "synonym_test"), + resource.TestCheckResourceAttr(datasourceName, "synonyms.0.source_collection", "collection_test"), + resource.TestCheckResourceAttrSet(datasourceIndexesName, "cluster_name"), + resource.TestCheckResourceAttrSet(datasourceIndexesName, "database"), + resource.TestCheckResourceAttrSet(datasourceIndexesName, "project_id"), + resource.TestCheckResourceAttrSet(datasourceIndexesName, "results.#"), + resource.TestCheckResourceAttrSet(datasourceIndexesName, "results.0.index_id"), + resource.TestCheckResourceAttrSet(datasourceIndexesName, "results.0.name"), ), }, }, @@ -48,7 +67,7 @@ func TestAccClusterRSSearchIndex_withMapping(t *testing.T) { updatedAnalyzer = "lucene.simple" ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasSearchIndexDestroy, Steps: []resource.TestStep{ @@ -70,28 +89,40 @@ func TestAccClusterRSSearchIndex_withSynonyms(t *testing.T) { var ( index matlas.SearchIndex resourceName = "mongodbatlas_search_index.test" + datasourceName = "data.mongodbatlas_search_indexes.data_index" clusterName = acctest.RandomWithPrefix("test-acc-index") - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") name = "name_test" updatedAnalyzer = "lucene.standard" ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasSearchIndexDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasSearchIndexConfigSynonyms(projectID, clusterName), + Config: testAccMongoDBAtlasSearchIndexConfigSynonyms(orgID, projectName, clusterName), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasSearchIndexExists(resourceName, &index), resource.TestCheckResourceAttr(resourceName, "name", name), - resource.TestCheckResourceAttr(resourceName, "project_id", projectID), resource.TestCheckResourceAttr(resourceName, "cluster_name", clusterName), resource.TestCheckResourceAttr(resourceName, "analyzer", updatedAnalyzer), resource.TestCheckResourceAttr(resourceName, "synonyms.#", "1"), resource.TestCheckResourceAttr(resourceName, "synonyms.0.analyzer", "lucene.simple"), resource.TestCheckResourceAttr(resourceName, "synonyms.0.name", "synonym_test"), resource.TestCheckResourceAttr(resourceName, "synonyms.0.source_collection", "collection_test"), + resource.TestCheckResourceAttrSet(datasourceName, "cluster_name"), + resource.TestCheckResourceAttrSet(datasourceName, "database"), + resource.TestCheckResourceAttrSet(datasourceName, "project_id"), + resource.TestCheckResourceAttrSet(datasourceName, "results.#"), + resource.TestCheckResourceAttrSet(datasourceName, "results.0.index_id"), + resource.TestCheckResourceAttrSet(datasourceName, "results.0.name"), + resource.TestCheckResourceAttrSet(datasourceName, "results.0.analyzer"), + resource.TestCheckResourceAttr(datasourceName, "results.0.synonyms.#", "1"), + resource.TestCheckResourceAttr(datasourceName, "results.0.synonyms.0.analyzer", "lucene.simple"), + resource.TestCheckResourceAttr(datasourceName, "results.0.synonyms.0.name", "synonym_test"), + resource.TestCheckResourceAttr(datasourceName, "results.0.synonyms.0.source_collection", "collection_test"), ), }, }, @@ -107,7 +138,7 @@ func TestAccClusterRSSearchIndex_importBasic(t *testing.T) { name = "name_test" ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasSearchIndexDestroy, Steps: []resource.TestStep{ @@ -190,6 +221,16 @@ func testAccMongoDBAtlasSearchIndexConfig(projectID, clusterName string) string name = "name_test" search_analyzer = "lucene.standard" } + + data "mongodbatlas_search_indexes" "data_index" { + cluster_name = mongodbatlas_search_index.test.cluster_name + project_id = mongodbatlas_search_index.test.project_id + database = "database_test" + collection_name = "collection_test" + page_num = 1 + items_per_page = 100 + + } `, projectID, clusterName) } @@ -295,11 +336,15 @@ func testAccMongoDBAtlasSearchIndexConfigAdvanced(projectID, clusterName string) `, projectID, clusterName) } -func testAccMongoDBAtlasSearchIndexConfigSynonyms(projectID, clusterName string) string { +func testAccMongoDBAtlasSearchIndexConfigSynonyms(orgID, projectName, clusterName string) string { return fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q + } resource "mongodbatlas_cluster" "test_cluster" { - project_id = "%[1]s" - name = "%[2]s" + project_id = mongodbatlas_project.test.id + name = %[3]q disk_size_gb = 10 cluster_type = "REPLICASET" @@ -337,7 +382,22 @@ func testAccMongoDBAtlasSearchIndexConfigSynonyms(projectID, clusterName string) source_collection = "collection_test" } } - `, projectID, clusterName) + + data "mongodbatlas_search_indexes" "data_index" { + cluster_name = mongodbatlas_search_index.test.cluster_name + project_id = mongodbatlas_search_index.test.project_id + database = "database_test" + collection_name = "collection_test" + page_num = 1 + items_per_page = 100 + } + + data "mongodbatlas_search_index" "test_two" { + cluster_name = mongodbatlas_search_index.test.cluster_name + project_id = mongodbatlas_search_index.test.project_id + index_id = mongodbatlas_search_index.test.index_id + } + `, orgID, projectName, clusterName) } func testAccCheckMongoDBAtlasSearchIndexDestroy(state *terraform.State) error { diff --git a/mongodbatlas/resource_mongodbatlas_team_test.go b/mongodbatlas/resource_mongodbatlas_team_test.go index 9f6cff2fc6..311df75808 100644 --- a/mongodbatlas/resource_mongodbatlas_team_test.go +++ b/mongodbatlas/resource_mongodbatlas_team_test.go @@ -15,26 +15,24 @@ import ( ) func TestAccConfigRSTeam_basic(t *testing.T) { - SkipTest(t) var ( team matlas.Team resourceName = "mongodbatlas_teams.test" orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") name = fmt.Sprintf("test-acc-%s", acctest.RandString(10)) updatedName = fmt.Sprintf("test-acc-%s", acctest.RandString(10)) + username = os.Getenv("MONGODB_ATLAS_USERNAME_CLOUD_DEV") ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasTeamDestroy, Steps: []resource.TestStep{ { Config: testAccMongoDBAtlasTeamConfig(orgID, name, []string{ - "mongodbatlas.testing@gmail.com", - "antonio.cabrera@digitalonus.com", - "edgar.lopez@digitalonus.com", + username, }, ), Check: resource.ComposeTestCheckFunc( @@ -42,14 +40,13 @@ func TestAccConfigRSTeam_basic(t *testing.T) { testAccCheckMongoDBAtlasTeamAttributes(&team, name), resource.TestCheckResourceAttrSet(resourceName, "org_id"), resource.TestCheckResourceAttr(resourceName, "name", name), - resource.TestCheckResourceAttr(resourceName, "usernames.#", "3"), + resource.TestCheckResourceAttr(resourceName, "usernames.#", "1"), ), }, { Config: testAccMongoDBAtlasTeamConfig(orgID, updatedName, []string{ - "edgar.lopez@digitalonus.com", - "antonio.cabrera@digitalonus.com", + username, }, ), Check: resource.ComposeTestCheckFunc( @@ -57,15 +54,13 @@ func TestAccConfigRSTeam_basic(t *testing.T) { testAccCheckMongoDBAtlasTeamAttributes(&team, updatedName), resource.TestCheckResourceAttrSet(resourceName, "org_id"), resource.TestCheckResourceAttr(resourceName, "name", updatedName), - resource.TestCheckResourceAttr(resourceName, "usernames.#", "2"), + resource.TestCheckResourceAttr(resourceName, "usernames.#", "1"), ), }, { Config: testAccMongoDBAtlasTeamConfig(orgID, updatedName, []string{ - "edgar.lopez@digitalonus.com", - "mongodbatlas.testing@gmail.com", - "antonio.cabrera@digitalonus.com", + username, }, ), Check: resource.ComposeTestCheckFunc( @@ -73,7 +68,7 @@ func TestAccConfigRSTeam_basic(t *testing.T) { testAccCheckMongoDBAtlasTeamAttributes(&team, updatedName), resource.TestCheckResourceAttrSet(resourceName, "org_id"), resource.TestCheckResourceAttr(resourceName, "name", updatedName), - resource.TestCheckResourceAttr(resourceName, "usernames.#", "3"), + resource.TestCheckResourceAttr(resourceName, "usernames.#", "1"), ), }, }, @@ -84,16 +79,17 @@ func TestAccConfigRSTeam_importBasic(t *testing.T) { var ( resourceName = "mongodbatlas_teams.test" orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + username = os.Getenv("MONGODB_ATLAS_USERNAME_CLOUD_DEV") name = fmt.Sprintf("test-acc-%s", acctest.RandString(10)) ) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProviderFactories: testAccProviderFactories, CheckDestroy: testAccCheckMongoDBAtlasTeamDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasTeamConfig(orgID, name, []string{"mongodbatlas.testing@gmail.com"}), + Config: testAccMongoDBAtlasTeamConfig(orgID, name, []string{username}), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "org_id"), resource.TestCheckResourceAttrSet(resourceName, "name"), diff --git a/mongodbatlas/resource_mongodbatlas_third_party_integration_test.go b/mongodbatlas/resource_mongodbatlas_third_party_integration_test.go index 1459e2891c..1844f1b0ea 100644 --- a/mongodbatlas/resource_mongodbatlas_third_party_integration_test.go +++ b/mongodbatlas/resource_mongodbatlas_third_party_integration_test.go @@ -12,7 +12,7 @@ import ( ) func TestAccConfigRSThirdPartyIntegration_basic(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( targetIntegration = matlas.ThirdPartyIntegration{} projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") @@ -51,7 +51,7 @@ func TestAccConfigRSThirdPartyIntegration_basic(t *testing.T) { } func TestAccConfigRSThirdPartyIntegration_importBasic(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( targetIntegration = matlas.ThirdPartyIntegration{} projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") @@ -95,7 +95,7 @@ func TestAccConfigRSThirdPartyIntegration_importBasic(t *testing.T) { } func TestAccConfigRSThirdPartyIntegration_updateBasic(t *testing.T) { - SkipTest(t) + SkipTestForCI(t) var ( targetIntegration = matlas.ThirdPartyIntegration{} projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")