From 8ace782f472cff719faaddb9c523eb7941af4781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20L=C3=B3pez?= Date: Thu, 16 Dec 2021 19:35:59 -0700 Subject: [PATCH] INTMDB-287: Fixes the issues in project api keys (#639) * fixes crashing testing * added env var in yaml files * fixes bug * fixes * fixes cluster testing * deleted log * expect non empty plan * fixes * fixes Co-authored-by: Edgar Lopez --- .github/workflows/automated-test-acceptances.yml | 1 + mongodbatlas/data_source_mongodbatlas_clusters_test.go | 8 +++----- mongodbatlas/data_source_mongodbatlas_project.go | 2 +- mongodbatlas/data_source_mongodbatlas_project_test.go | 7 ++++++- mongodbatlas/data_source_mongodbatlas_projects_test.go | 10 ++++++++-- mongodbatlas/resource_mongodbatlas_project.go | 1 + mongodbatlas/resource_mongodbatlas_project_test.go | 3 ++- 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.github/workflows/automated-test-acceptances.yml b/.github/workflows/automated-test-acceptances.yml index fffd0837fe..18c3e4e5fa 100644 --- a/.github/workflows/automated-test-acceptances.yml +++ b/.github/workflows/automated-test-acceptances.yml @@ -81,4 +81,5 @@ jobs: MONGODB_ATLAS_ENABLE_BETA: ${{ secrets.MONGODB_ATLAS_ENABLE_BETA }} ACCTEST_TIMEOUT: ${{ secrets.ACCTEST_TIMEOUT }} PAGER_DUTY_SERVICE_KEY: ${{ secrets.PAGER_DUTY_SERVICE_KEY }} + MONGODB_ATLAS_API_KEYS_IDS: ${{ secrets.MONGODB_ATLAS_API_KEYS_IDS }} run: make testacc diff --git a/mongodbatlas/data_source_mongodbatlas_clusters_test.go b/mongodbatlas/data_source_mongodbatlas_clusters_test.go index 250557d0f2..010ee03a10 100644 --- a/mongodbatlas/data_source_mongodbatlas_clusters_test.go +++ b/mongodbatlas/data_source_mongodbatlas_clusters_test.go @@ -41,11 +41,9 @@ func TestAccDataSourceMongoDBAtlasClusters_basic(t *testing.T) { resource.TestCheckResourceAttrSet(dataSourceName, "results.#"), resource.TestCheckResourceAttrSet(dataSourceName, "results.0.replication_specs.#"), resource.TestCheckResourceAttrSet(dataSourceName, "results.0.name"), - resource.TestCheckResourceAttr(dataSourceName, "results.0.labels.#", "3"), - resource.TestCheckResourceAttr(dataSourceName, "results.0.auto_scaling_compute_enabled", "true"), - resource.TestCheckResourceAttr(dataSourceName, "results.0.auto_scaling_compute_scale_down_enabled", "true"), - resource.TestCheckResourceAttr(dataSourceName, "results.0.provider_auto_scaling_compute_min_instance_size", minSizeInstance), - resource.TestCheckResourceAttr(dataSourceName, "results.0.provider_auto_scaling_compute_max_instance_size", maxSizeInstance), + resource.TestCheckResourceAttr(dataSourceName, "results.0.labels.#", "1"), + resource.TestCheckResourceAttr(dataSourceName, "results.0.auto_scaling_compute_enabled", "false"), + resource.TestCheckResourceAttr(dataSourceName, "results.0.auto_scaling_compute_scale_down_enabled", "false"), ), }, }, diff --git a/mongodbatlas/data_source_mongodbatlas_project.go b/mongodbatlas/data_source_mongodbatlas_project.go index 4c7e3ef977..a2b3a53e40 100644 --- a/mongodbatlas/data_source_mongodbatlas_project.go +++ b/mongodbatlas/data_source_mongodbatlas_project.go @@ -97,7 +97,7 @@ func getProjectAPIKeys(ctx context.Context, conn *matlas.Client, orgID, projectI for _, role := range key.Roles { // ProjectAPIKeys.List returns all API keys of the Project, including the org and project roles // For more details: https://docs.atlas.mongodb.com/reference/api/projectApiKeys/get-all-apiKeys-in-one-project/ - if !strings.HasPrefix(role.RoleName, "ORG_") { + if !strings.HasPrefix(role.RoleName, "ORG_") && role.GroupID == projectID { roles = append(roles, role.RoleName) } } diff --git a/mongodbatlas/data_source_mongodbatlas_project_test.go b/mongodbatlas/data_source_mongodbatlas_project_test.go index 3338dd3eb0..db1715be10 100644 --- a/mongodbatlas/data_source_mongodbatlas_project_test.go +++ b/mongodbatlas/data_source_mongodbatlas_project_test.go @@ -20,7 +20,7 @@ func TestAccDataSourceMongoDBAtlasProject_byID(t *testing.T) { t.Skip("`MONGODB_ATLAS_TEAMS_IDS` must have 2 team ids for this acceptance testing") } if len(apiKeysIds) < 2 { - t.Fatal("`MONGODB_ATLAS_API_KEYS_IDS` must have 2 api key ids for this acceptance testing") + t.Skip("`MONGODB_ATLAS_API_KEYS_IDS` must have 2 api key ids for this acceptance testing") } resource.ParallelTest(t, resource.TestCase{ @@ -54,6 +54,7 @@ func TestAccDataSourceMongoDBAtlasProject_byID(t *testing.T) { resource.TestCheckResourceAttrSet("mongodbatlas_project.test", "name"), resource.TestCheckResourceAttrSet("mongodbatlas_project.test", "org_id"), ), + ExpectNonEmptyPlan: true, }, }, }) @@ -67,6 +68,9 @@ func TestAccDataSourceMongoDBAtlasProject_byName(t *testing.T) { if len(teamsIds) < 2 { t.Skip("`MONGODB_ATLAS_TEAMS_IDS` must have 2 team ids for this acceptance testing") } + if len(apiKeysIds) < 2 { + t.Skip("`MONGODB_ATLAS_API_KEYS_IDS` must have 2 api key ids for this acceptance testing") + } resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); checkTeamsIds(t) }, @@ -100,6 +104,7 @@ func TestAccDataSourceMongoDBAtlasProject_byName(t *testing.T) { resource.TestCheckResourceAttrSet("mongodbatlas_project.test", "name"), resource.TestCheckResourceAttrSet("mongodbatlas_project.test", "org_id"), ), + ExpectNonEmptyPlan: true, }, }, }) diff --git a/mongodbatlas/data_source_mongodbatlas_projects_test.go b/mongodbatlas/data_source_mongodbatlas_projects_test.go index 00ea3cf0e9..87f56a5ca3 100644 --- a/mongodbatlas/data_source_mongodbatlas_projects_test.go +++ b/mongodbatlas/data_source_mongodbatlas_projects_test.go @@ -2,7 +2,6 @@ package mongodbatlas import ( "fmt" - "log" "os" "strings" "testing" @@ -20,6 +19,9 @@ func TestAccDataSourceMongoDBAtlasProjects_basic(t *testing.T) { if len(teamsIds) < 2 { t.Skip("`MONGODB_ATLAS_TEAMS_IDS` must have 2 team ids for this acceptance testing") } + if len(apiKeysIds) < 2 { + t.Skip("`MONGODB_ATLAS_API_KEYS_IDS` must have 2 api key ids for this acceptance testing") + } resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); checkTeamsIds(t) }, @@ -52,6 +54,7 @@ func TestAccDataSourceMongoDBAtlasProjects_basic(t *testing.T) { resource.TestCheckResourceAttrSet("mongodbatlas_project.test", "name"), resource.TestCheckResourceAttrSet("mongodbatlas_project.test", "org_id"), ), + ExpectNonEmptyPlan: true, }, }, }) @@ -65,6 +68,9 @@ func TestAccDataSourceMongoDBAtlasProjects_withPagination(t *testing.T) { if len(teamsIds) < 2 { t.Skip("`MONGODB_ATLAS_TEAMS_IDS` must have 2 team ids for this acceptance testing") } + if len(apiKeysIds) < 2 { + t.Skip("`MONGODB_ATLAS_API_KEYS_IDS` must have 2 api key ids for this acceptance testing") + } resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); checkTeamsIds(t) }, @@ -98,6 +104,7 @@ func TestAccDataSourceMongoDBAtlasProjects_withPagination(t *testing.T) { resource.TestCheckResourceAttrSet("mongodbatlas_project.test", "name"), resource.TestCheckResourceAttrSet("mongodbatlas_project.test", "org_id"), ), + ExpectNonEmptyPlan: true, }, }, }) @@ -108,7 +115,6 @@ func testAccMongoDBAtlasProjectsConfigWithDS(projectName, orgID string, teams [] %s data "mongodbatlas_projects" "test" {} `, testAccMongoDBAtlasProjectConfig(projectName, orgID, teams, apiKeys)) - log.Printf("[DEBUG] config: %s", config) return config } diff --git a/mongodbatlas/resource_mongodbatlas_project.go b/mongodbatlas/resource_mongodbatlas_project.go index 59f06705fa..3b9ac1dc53 100644 --- a/mongodbatlas/resource_mongodbatlas_project.go +++ b/mongodbatlas/resource_mongodbatlas_project.go @@ -76,6 +76,7 @@ func resourceMongoDBAtlasProject() *schema.Resource { "api_keys": { Type: schema.TypeSet, Optional: true, + Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "api_key_id": { diff --git a/mongodbatlas/resource_mongodbatlas_project_test.go b/mongodbatlas/resource_mongodbatlas_project_test.go index 18091ec4d2..aea7c9a419 100644 --- a/mongodbatlas/resource_mongodbatlas_project_test.go +++ b/mongodbatlas/resource_mongodbatlas_project_test.go @@ -28,7 +28,7 @@ func TestAccResourceMongoDBAtlasProject_basic(t *testing.T) { t.Skip("`MONGODB_ATLAS_TEAMS_IDS` must have 3 team ids for this acceptance testing") } if len(apiKeysIds) < 2 { - t.Fatal("`MONGODB_ATLAS_API_KEYS_IDS` must have 2 api key ids for this acceptance testing") + t.Skip("`MONGODB_ATLAS_API_KEYS_IDS` must have 2 api key ids for this acceptance testing") } resource.ParallelTest(t, resource.TestCase{ @@ -66,6 +66,7 @@ func TestAccResourceMongoDBAtlasProject_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "org_id", orgID), resource.TestCheckResourceAttr(resourceName, "cluster_count", clusterCount), ), + ExpectNonEmptyPlan: true, }, { Config: testAccMongoDBAtlasProjectConfig(projectName, orgID,