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: define project_assignment block in mongodbatlas_project_api_key as required to avoid plugin crash #1663

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

AgustinBettati
Copy link
Member

@AgustinBettati AgustinBettati commented Nov 23, 2023

Description

Link to any related issue(s): Not strictly related to INTMDB-1296, but helps understand how this resource is being used.

Given the current definition of the project_api_key resource, it is only usable if at least one project_assignment block is defined.

Example:

resource "mongodbatlas_project_api_key" "test" {
	project_id     = mongodbatlas_project.test.id
	description  = %[3]q
	project_assignment  {
		project_id = mongodbatlas_project.test.id
		role_names = [%[4]q]
	}
}

If project_assignment is not defined, there is no way to create an API Key as no role_names are defined. The error returned in this case is:

Error: The terraform-provider-mongodbatlas plugin crashed!
panic: runtime error: invalid memory address or nil pointer dereference

This is not considered a breaking change as it is simply improving the error message users receive if they do not define the project_assignment block.

For reference this attribute was originally defined as optional because role_names could be defined at root level. However this attribute was deleted in 1.12.0 (#1418).

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contribution guidelines
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals, I defined an isolated PR with a relevant title as it will be used in the auto-generated changelog.

Further comments

@github-actions github-actions bot added the bug label Nov 23, 2023
Copy link
Contributor

Code Coverage

Package Line Rate Health
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas 3%
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/framework/validator 68%
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/testutils 46%
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/util 17%
Summary 3% (328 / 10474)

@AgustinBettati AgustinBettati marked this pull request as ready for review November 23, 2023 17:04
@AgustinBettati AgustinBettati requested a review from a team as a code owner November 23, 2023 17:04
@@ -46,7 +46,8 @@ func resourceMongoDBAtlasProjectAPIKey() *schema.Resource {
},
"project_assignment": {
Type: schema.TypeSet,
Optional: true,
Required: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it useful to create/modify a test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests/examples are already defining at least on project_assignment. Don't see much value in testing empty project_assignment as it is validated by schema + makes no real sense.

@AgustinBettati AgustinBettati merged commit 86df112 into master Nov 24, 2023
32 checks passed
@AgustinBettati AgustinBettati deleted the INTMDB-1296-required-proj-assignment branch November 24, 2023 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants