Skip to content

Commit 917bfe0

Browse files
adding migration test with test case removing root project id
1 parent 76795e7 commit 917bfe0

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package mongodbatlas
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
9+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
)
11+
12+
func TestAccMigrationConfigRSProjectAPIKey_RemovingOptionalRootProjectID(t *testing.T) {
13+
var (
14+
resourceName = "mongodbatlas_project_api_key.test"
15+
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
16+
projectName = acctest.RandomWithPrefix("test-acc")
17+
description = fmt.Sprintf("test-acc-project-api_key-%s", acctest.RandString(5))
18+
roleName = "GROUP_OWNER"
19+
)
20+
21+
resource.ParallelTest(t, resource.TestCase{
22+
PreCheck: func() { testAccPreCheckBasic(t) },
23+
CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy,
24+
Steps: []resource.TestStep{
25+
{
26+
ExternalProviders: map[string]resource.ExternalProvider{
27+
"mongodbatlas": {
28+
VersionConstraint: "1.13.1", // fixed version as this is the last version where root project id was required.
29+
Source: "mongodb/mongodbatlas",
30+
},
31+
},
32+
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true),
33+
Check: resource.ComposeTestCheckFunc(
34+
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
35+
resource.TestCheckResourceAttr(resourceName, "description", description),
36+
resource.TestCheckResourceAttrSet(resourceName, "public_key"),
37+
resource.TestCheckResourceAttr(resourceName, "project_assignment.#", "1"),
38+
),
39+
},
40+
{
41+
ProtoV6ProviderFactories: testAccProviderV6Factories,
42+
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true),
43+
Check: resource.ComposeTestCheckFunc(
44+
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
45+
resource.TestCheckResourceAttr(resourceName, "description", description),
46+
resource.TestCheckResourceAttrSet(resourceName, "public_key"),
47+
resource.TestCheckResourceAttr(resourceName, "project_assignment.#", "1"),
48+
),
49+
},
50+
{
51+
ProtoV6ProviderFactories: testAccProviderV6Factories,
52+
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, false),
53+
Check: resource.ComposeTestCheckFunc(
54+
resource.TestCheckResourceAttr(resourceName, "description", description),
55+
resource.TestCheckResourceAttrSet(resourceName, "public_key"),
56+
resource.TestCheckResourceAttr(resourceName, "project_assignment.#", "1"),
57+
),
58+
},
59+
},
60+
})
61+
}

0 commit comments

Comments
 (0)