Skip to content

feat: Adds users attribute to mongodbatlas_organization(s) singular and plural data source. #3468

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
Jul 8, 2025

Conversation

csanx
Copy link
Collaborator

@csanx csanx commented Jul 4, 2025

Description

Adds users attribute to mongodbatlas_organization singular data source.
Adds users attribute to mongodbatlas_organizations plural data source.

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

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

@csanx csanx marked this pull request as ready for review July 4, 2025 13:57
@csanx csanx requested review from a team as code owners July 4, 2025 13:57
Copy link
Contributor

github-actions bot commented Jul 4, 2025

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

Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"username": {
Copy link
Member

Choose a reason for hiding this comment

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

is this the same or similar to project ? in case we can have some common schema

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They differ in some fields. Also project uses tpf and org uses sdk v2. See #3451 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

ah, ok, if it's tpf and sdv2 then it's better not to reuse, thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, I think I can extract some of this logic to a common utility when implementing CLOUDP-328757

@@ -17,6 +19,57 @@ func FlattenLinks(links []admin.Link) []map[string]string {
return ret
}

func FlattenUsers(users []admin.OrgUserResponse) []map[string]any {
Copy link
Member

Choose a reason for hiding this comment

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

not sure about having funcs in the common packages if they're only being used in one resource. I would have them here if at least used twice

resource.TestCheckResourceAttrWith(datasourceName, "users.#", acc.IntGreatThan(0)),
resource.TestCheckResourceAttrSet(datasourceName, "users.0.id"),
resource.TestCheckResourceAttrSet(datasourceName, "users.0.username"),
resource.TestCheckResourceAttrSet(datasourceName, "users.0.roles.0.org_roles.#"),
Copy link
Member

@lantoli lantoli Jul 4, 2025

Choose a reason for hiding this comment

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

these only checks that the attribute exists, don't know if we could also assert some expected values

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

@EspenAlbert does the ExpectKnownValue work for SDKv2 based resources as well? asking because in SDKv2, there are no nulls but empty values like ""

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Followup: This was discussed offline with the team. Decided to use regex validation to check that certain attributes (username, last_auth) have the appropriate structure/format rather than exact value matching. The reasoning is that these values can be unpredictable or non-deterministic. See 1d75984

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, only saw this now. @maastha yes, it should also work for SDKv2

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.

Nice. Agree with Leo's comments

* `lastName` - Last name, family name, or surname that belongs to the MongoDB Cloud user.
* `mobileNumber` - Mobile phone number that belongs to the MongoDB Cloud user.

~> **NOTE:** - Does not return pending users invited via the deprecated [Invite One MongoDB Cloud User to Join One Project](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-createprojectinvitation) endpoint or pending invitations created using [`mongodbatlas_project_invitation`](../resources/project_invitation.md) resource.
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we update this message to be consistent with the one mentioned in the tech design doc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done e0aa80a. Added a TODO for completion in the following tickets.

Copy link
Collaborator

Choose a reason for hiding this comment

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

the TODO can be easy to miss since it's inside docs, instead I'd say remove the TODO from this PR & create a JIRA ticket to go over all documentation related to this epic & mention the link in this note may need to be updated

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for the suggestion. JIRA ticket: CLOUDP-329711

Copy link
Contributor

@lmkerbey-mdb lmkerbey-mdb left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Collaborator

@maastha maastha left a comment

Choose a reason for hiding this comment

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

LGTM, one comment related to the docs

@csanx csanx merged commit 5a75bcc into CLOUDP-320243-dev-2.0.0 Jul 8, 2025
41 checks passed
@csanx csanx deleted the CLOUDP-328752-updated branch July 8, 2025 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants