Skip to content

Commit 76795e7

Browse files
adjust acceptance test removing legacy attribute and leaving one test case with old behavior
1 parent 9b3f5b4 commit 76795e7

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

mongodbatlas/resource_mongodbatlas_project_api_key_test.go

+13-16
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ func TestAccConfigRSProjectAPIKey_Basic(t *testing.T) {
2828
CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy,
2929
Steps: []resource.TestStep{
3030
{
31-
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true),
31+
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, false),
3232
Check: resource.ComposeTestCheckFunc(
33-
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
34-
resource.TestCheckResourceAttrSet(resourceName, "description"),
3533
resource.TestCheckResourceAttr(resourceName, "description", description),
34+
resource.TestCheckResourceAttrSet(resourceName, "public_key"),
35+
resource.TestCheckResourceAttr(resourceName, "project_assignment.#", "1"),
3636
),
3737
},
3838
},
3939
})
4040
}
4141

42-
func TestAccConfigRSProjectAPIKey_BasicWithNoRootProjectID(t *testing.T) {
42+
func TestAccConfigRSProjectAPIKey_BasicWithLegacyRootProjectID(t *testing.T) {
4343
var (
4444
resourceName = "mongodbatlas_project_api_key.test"
4545
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
@@ -54,8 +54,9 @@ func TestAccConfigRSProjectAPIKey_BasicWithNoRootProjectID(t *testing.T) {
5454
CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy,
5555
Steps: []resource.TestStep{
5656
{
57-
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, false),
57+
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true),
5858
Check: resource.ComposeTestCheckFunc(
59+
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
5960
resource.TestCheckResourceAttr(resourceName, "description", description),
6061
resource.TestCheckResourceAttrSet(resourceName, "public_key"),
6162
resource.TestCheckResourceAttr(resourceName, "project_assignment.#", "1"),
@@ -153,7 +154,6 @@ func TestAccConfigRSProjectAPIKey_Multiple(t *testing.T) {
153154
{
154155
Config: testAccMongoDBAtlasProjectAPIKeyConfigMultiple(orgID, projectName, description, roleName),
155156
Check: resource.ComposeTestCheckFunc(
156-
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
157157
resource.TestCheckResourceAttrSet(resourceName, "description"),
158158
resource.TestCheckResourceAttr(resourceName, "description", description),
159159
resource.TestCheckResourceAttrSet(resourceName, "project_assignment.0.project_id"),
@@ -186,17 +186,15 @@ func TestAccConfigRSProjectAPIKey_UpdateDescription(t *testing.T) {
186186
CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy,
187187
Steps: []resource.TestStep{
188188
{
189-
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true),
189+
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, false),
190190
Check: resource.ComposeTestCheckFunc(
191-
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
192191
resource.TestCheckResourceAttrSet(resourceName, "description"),
193192
resource.TestCheckResourceAttr(resourceName, "description", description),
194193
),
195194
},
196195
{
197-
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, updatedDescription, roleName, true),
196+
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, updatedDescription, roleName, false),
198197
Check: resource.ComposeTestCheckFunc(
199-
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
200198
resource.TestCheckResourceAttrSet(resourceName, "description"),
201199
resource.TestCheckResourceAttr(resourceName, "description", updatedDescription),
202200
),
@@ -220,7 +218,7 @@ func TestAccConfigRSProjectAPIKey_importBasic(t *testing.T) {
220218
CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy,
221219
Steps: []resource.TestStep{
222220
{
223-
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true),
221+
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, false),
224222
},
225223
{
226224
ResourceName: resourceName,
@@ -242,7 +240,7 @@ func TestAccConfigRSProjectAPIKey_RecreateWhenDeletedExternally(t *testing.T) {
242240
roleName = "GROUP_OWNER"
243241
)
244242

245-
projectAPIKeyConfig := testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true)
243+
projectAPIKeyConfig := testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, false)
246244

247245
resource.ParallelTest(t, resource.TestCase{
248246
PreCheck: func() { testAccPreCheckBasic(t) },
@@ -252,7 +250,6 @@ func TestAccConfigRSProjectAPIKey_RecreateWhenDeletedExternally(t *testing.T) {
252250
{
253251
Config: projectAPIKeyConfig,
254252
Check: resource.ComposeTestCheckFunc(
255-
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
256253
resource.TestCheckResourceAttrSet(resourceName, "description"),
257254
),
258255
},
@@ -349,7 +346,9 @@ func testAccCheckMongoDBAtlasProjectAPIKeyImportStateIDFunc(resourceName string)
349346
return "", fmt.Errorf("not found: %s", resourceName)
350347
}
351348

352-
return fmt.Sprintf("%s-%s", rs.Primary.Attributes["project_id"], rs.Primary.Attributes["api_key_id"]), nil
349+
projectID := rs.Primary.Attributes["project_assignment.0.project_id"]
350+
351+
return fmt.Sprintf("%s-%s", projectID, rs.Primary.Attributes["api_key_id"]), nil
353352
}
354353
}
355354

@@ -403,7 +402,6 @@ func testAccMongoDBAtlasProjectAPIKeyConfigMultiple(orgID, projectName, descript
403402
org_id = %[1]q
404403
}
405404
resource "mongodbatlas_project_api_key" "test" {
406-
project_id = mongodbatlas_project.test.id
407405
description = %[3]q
408406
project_assignment {
409407
project_id = mongodbatlas_project.test.id
@@ -446,7 +444,6 @@ func testAccMongoDBAtlasProjectAPIKeyConfigDeletedProjectAndAssignment(orgID, pr
446444
}
447445
%[3]s
448446
resource "mongodbatlas_project_api_key" "test" {
449-
project_id = mongodbatlas_project.project1.id
450447
description = %[4]q
451448
project_assignment {
452449
project_id = mongodbatlas_project.project1.id

0 commit comments

Comments
 (0)