Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTMDB-287: Fixes the issues in project api keys #639

Merged
merged 9 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/automated-test-acceptances.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 3 additions & 5 deletions mongodbatlas/data_source_mongodbatlas_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down
2 changes: 1 addition & 1 deletion mongodbatlas/data_source_mongodbatlas_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
7 changes: 6 additions & 1 deletion mongodbatlas/data_source_mongodbatlas_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
},
},
})
Expand All @@ -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) },
Expand Down Expand Up @@ -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,
},
},
})
Expand Down
10 changes: 8 additions & 2 deletions mongodbatlas/data_source_mongodbatlas_projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mongodbatlas

import (
"fmt"
"log"
"os"
"strings"
"testing"
Expand All @@ -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) },
Expand Down Expand Up @@ -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,
},
},
})
Expand All @@ -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) },
Expand Down Expand Up @@ -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,
},
},
})
Expand All @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions mongodbatlas/resource_mongodbatlas_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion mongodbatlas/resource_mongodbatlas_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand Down