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

add all_users_data_source.go and tests #513

Merged
merged 19 commits into from
Sep 2, 2021

Conversation

Threpio
Copy link
Contributor

@Threpio Threpio commented Aug 11, 2021

For issue: #512

This datasource is to be used to retrieve all users within the AAD (not restricted to groups) and so is a catchall.

The datasource does not currently return the mail_nicknames like some of the other generalised data_sources.

The tests are minimal and I understand if other tests need to be put into place but I am not sure of the scenarios that could be explored. Without more input params or config I do not believe that there is more to tests.

Please let me know if anything needs to be changed/refactored as this is my first PR against this repo.

Added Documentation for the datasource.
@manicminer
Copy link
Member

manicminer commented Aug 11, 2021

Hi @Threpio, thanks for this PR!

Quoting your comment on the issue (#512 (comment)):

@manicminer - We did consider developing it as an extension as the azuread_users datasource but figured that the majority of the times that we use that datasource we DO NOT want a result that is not queried/filtered to be returned. So for us it means that if we mis-configure the datasource then it can look to be correct even when not filtered. (Happy to be overrule in this for the greater project)

It could be deigned as a all_users flag against the azuread_users datasource but I can't see how the ExactlyOneOf functionality for those inputs would work additionally with a boolean flag?

I do think this would be better implemented in the existing azuread_users data source, assuming no blockers arise from trying that. I agree it would be sensible to gate this with a boolean field. For the schema, I think we can add ExactlyOneOf to the boolean field as well and include it in the set of mutually exclusive fields? In the event that it is set to false, and the other fields are not specified, we'd likely have to check this in a CustomizeDiff function, e.g. if show_all_users is false and mail_nicknames, object_ids, user_principal_names are all empty then raise an error

@Threpio
Copy link
Contributor Author

Threpio commented Aug 11, 2021

@manicminer Thanks for the input. I will endeavour to implement it as that flag instead.

Would you like me to abandon this PR and branch or implement it here?

@manicminer
Copy link
Member

Keeping it in the same PR is better, don't worry too much about your commit history as we can squash that at merge time :)

- Added show_all_users flag
- Implemented cross flag logic
- fetched all users logic and append to list
- Added basic test for showAllUsers flag
- Started second test to check for error but couldn't get it to work.
@github-actions github-actions bot added size/M and removed size/L labels Aug 11, 2021
@Threpio
Copy link
Contributor Author

Threpio commented Aug 11, 2021

@manicminer - Changes have been pushed and I believe this works. I cannot work out how to test for if an error is thrown. Do you have any examples/documentation for what I could do to test that an error is thrown?

(more specifically with this framework for the showAllusers and ignoreMissing flags both being set to true.

@Threpio
Copy link
Contributor Author

Threpio commented Aug 13, 2021

@manicminer - Sorry for the ping. I have attempted to fix the formatting and pass the linting stage but are still failing.

Any chance you could take a quick look and point out where I have mucked up? I have run the different fmt'ing commands with no changes. Feel free to push to the branch.

@manicminer
Copy link
Member

@Threpio No problem at all, it looks like the linter is complaining about line 222 of users_data_source_test.go - it looks like there's a tab indenting this line however Terraform configs should be indented by 2 spaces.

I'm going to queue this for v2.1.0 since we're currently working on some outstanding bugs and getting v2.0.0 ready for release. As it's possible the same files could change in the meantime, once 2.0.0 is out I'll circle back and give a proper review.

@manicminer manicminer added this to the v2.1.0 milestone Aug 15, 2021
@manicminer manicminer linked an issue Aug 19, 2021 that may be closed by this pull request
@Threpio
Copy link
Contributor Author

Threpio commented Sep 2, 2021

@manicminer I have fixed the merge conflicts - Apologies for the delay.

…y-time validation, rename `show_all_user` to `return_all_users`
Copy link
Member

@manicminer manicminer left a comment

Choose a reason for hiding this comment

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

Thanks @Threpio, this is looking good. I pushed some small changes:

  • I renamed show_all_users to return_all
  • We can use ConflictsWith between ignore_missing and return_all, and move the block that makes the API call to the if-else block, and then there's no need to do any apply-time validation :)

Many thanks for the contribution!

Test results:
Screenshot 2021-09-02 at 10 41 41

@manicminer manicminer merged commit dd84294 into hashicorp:main Sep 2, 2021
manicminer added a commit that referenced this pull request Sep 2, 2021
@Threpio Threpio deleted the feature/add_all_users_datasource branch September 2, 2021 11:11
@github-actions
Copy link

github-actions bot commented Sep 2, 2021

This functionality has been released in v2.1.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

github-actions bot commented Oct 3, 2021

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: datasource all_users_datasource.go
2 participants