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

fix: : Provider crash when an invalid role name is specified to mongodbatlas_project_api_key #1720

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Changes from 1 commit
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
Next Next commit
CLOUDP-216402: Provider crash when an invalid role name is specified …
…to mongodbatlas_project_api_key
andreaangiolillo committed Dec 7, 2023
commit b0475ae7a017d95a03a283b4412f610e240c8d96
2 changes: 2 additions & 0 deletions internal/service/projectapikey/resource_project_api_key.go
Original file line number Diff line number Diff line change
@@ -104,6 +104,8 @@ func resourceMongoDBAtlasProjectAPIKeyCreate(ctx context.Context, d *schema.Reso
d.SetId("")
return nil
}

return diag.FromErr(err)
}

// assign created api key to remaining project assignments
28 changes: 28 additions & 0 deletions internal/service/projectapikey/resource_project_api_key_test.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"regexp"
"strings"
"testing"

@@ -342,6 +343,33 @@ func testAccCheckMongoDBAtlasProjectAPIKeyDestroy(s *terraform.State) error {
return nil
}

func TestAccConfigRSProjectAPIKey_Invalid_Role(t *testing.T) {
var (
resourceName = "mongodbatlas_project_api_key.test"
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 = "INVALID_ROLE"
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy,
Steps: []resource.TestStep{
{
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "description", description),
resource.TestCheckResourceAttrSet(resourceName, "public_key"),
resource.TestCheckResourceAttr(resourceName, "project_assignment.#", "1"),
),
ExpectError: regexp.MustCompile("INVALID_ENUM_VALUE"),
},
},
})
}

func testAccCheckMongoDBAtlasProjectAPIKeyImportStateIDFunc(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[resourceName]