Skip to content

feat: Adds support for new description field in mongodbatlas_resource_policy resource & data sources #3214

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

Merged
merged 17 commits into from
Mar 31, 2025

Conversation

maastha
Copy link
Collaborator

@maastha maastha commented Mar 26, 2025

Description

Adds support for new description field in mongodbatlas_resource_policy resource & data sources

Link to any related issue(s): CLOUDP-295768

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. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • 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 have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

@maastha maastha changed the title feat: Adds support for new Description field in mongodbatlas_resource_policy resource & data sources feat: Adds support for new description field in mongodbatlas_resource_policy resource & data sources Mar 26, 2025
@maastha
Copy link
Collaborator Author

maastha commented Mar 26, 2025

Fixing the examples check

@maastha maastha marked this pull request as ready for review March 26, 2025 15:01
@maastha maastha requested review from a team as code owners March 26, 2025 15:01
Copy link
Contributor

APIx bot: a message has been sent to Docs Slack channel

Comment on lines 142 to 143
if editAdmin.Description == nil {
editAdmin.Description = conversion.Pointer("")
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this needed?

Copy link
Member

Choose a reason for hiding this comment

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

what behavior do we want to have if description is not in the config, setting to empty o keeping the description? (for example in case they change description in the UI, or it's an imported resource with a description but it's not in specified in the config)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it will be null by default. This particular change is added as it is an optional attribute, so if user wants to "unset" the value/remove it from the config then we send an empty string to the API to do that in the PATCH.

Copy link
Member

@lantoli lantoli Mar 26, 2025

Choose a reason for hiding this comment

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

sorry not clear, first sentence and code seem contradictory, and also same question as Oriol, when it's not in the config we want to set it to empty, or leave what it is?
do we need that this code?:

if editAdmin.Description == nil {
		editAdmin.Description = conversion.Pointer("")

Copy link
Member

Choose a reason for hiding this comment

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

let makes sure to capture the API and intended terraform behaviour in a code comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have simplified the implementation & added a comment, lmk if it makes the behavior clearer to understand.

Copy link
Collaborator Author

@maastha maastha Mar 27, 2025

Choose a reason for hiding this comment

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

when it's not in the config we want to set it to empty, or leave what it is?

@lantoli when it's not in the config we want it to be null, since it is optional. The question is during an update, how do we tell the API to reset it to null in the PATCH request? If we do editAdmin.Description = nil then it will never be included in the request due to` json:"description,omitempty"``. To address this, we set it to an empty string which the API interprets as nil.

Copy link
Member

Choose a reason for hiding this comment

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

that's fine, thanks

Copy link

@JuliaMongo JuliaMongo left a comment

Choose a reason for hiding this comment

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

LGTM, with a few comments. I will also ask @erabil-mdb to review since she documented Atlas resource policies.

}

func configWithPolicyBodies(orgID, policyName string, bodies ...string) string {
func configWithPolicyBodies(orgID, policyName string, description *string, bodies ...string) string {
Copy link
Member

@lantoli lantoli Mar 26, 2025

Choose a reason for hiding this comment

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

nit: you can pass description as a string instead of pointer and use it if != ""

@@ -203,7 +213,7 @@ data "mongodbatlas_resource_policy" "test" {
data "mongodbatlas_resource_policies" "test" {
org_id = mongodbatlas_resource_policy.test.org_id
}
`, orgID, policyName, policies)
`, orgID, policyName, descriptionStr, policies)
Copy link
Member

@lantoli lantoli Mar 26, 2025

Choose a reason for hiding this comment

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

we don't need a check for the resource as it's optional but would be useful for the data sources as the field will be computed there

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

Copy link
Collaborator

@EspenAlbert EspenAlbert left a comment

Choose a reason for hiding this comment

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

Only nit comments

Copy link
Member

@AgustinBettati AgustinBettati left a comment

Choose a reason for hiding this comment

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

LGTM, lets just clarify the removal aspect

Comment on lines 142 to 143
if editAdmin.Description == nil {
editAdmin.Description = conversion.Pointer("")
Copy link
Member

Choose a reason for hiding this comment

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

let makes sure to capture the API and intended terraform behaviour in a code comment

@maastha maastha merged commit 149c5c0 into master Mar 31, 2025
40 checks passed
@maastha maastha deleted the CLOUDP-295768-rp-description branch March 31, 2025 14:03
svc-apix-Bot added a commit that referenced this pull request Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants