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

Improvements to resource_gitlab_user import #340

Merged
merged 1 commit into from Jun 19, 2020

Conversation

Majkl578
Copy link

@Majkl578 Majkl578 commented Jun 19, 2020

Rebased #288, no other change.

closes #193, closes #288

This change makes three improvements to the gitlab_user resource, resolving Issue #193.

Change #1:
The `password` attribute for gitlab_user has been changed from required to optional. There is no endpoint on the Gitlab `user` API for `password` (see: https://docs.gitlab.com/ee/api/users.html), so it is impossible for us to ever read this attribute to set state. The field should therefore only be necessary when we are performing a Create or Update action on a gitlab_user.

Change #2:
The resource's State Importer originally used `ImportStatePassthrough`, which essentially ensured that `terraform import` could only read the fields defined in the default Read method (in this case, `username`, `name`, `can_create_group`, and `projects_limit`, all of which are called in `resourceGitlabUserSetToState`, inside `resourceGitlabUserRead`). I have replaced the `ImportStatePassthrough` with an anonymous function that reuses `resourceGitlabUserSetToState` and additionally sets `email`, `is_admin`, and `is_external`. I did not modify the fields set in `resourceGitlabUserSetToState` because that function is intended to provide only a basic level of detail about a user (i.e., all the data we'd be able to pull for a user if we didn't have a token with Admin privileges).  These fields can be easily extended in the future if need be.

Change #3:
The test for the gitlab_user resource has been updated to include the mandatory ImportState and ImportStateVerify elements in the final stage, per the Terraform `import` implementation documentation at https://www.terraform.io/docs/extend/resources/import.html. The `password` and `skip_confirmation` attributes are ignored because it is not possible to read them from the API (they are not part of the Read schema: https://docs.gitlab.com/ee/api/users.html)
@ghost ghost added the size/S label Jun 19, 2020
@ringods ringods merged commit 1cbab81 into gitlabhq:master Jun 19, 2020
@Majkl578 Majkl578 deleted the users-improvements branch June 19, 2020 14:19
@Majkl578
Copy link
Author

@ringods Hi, any chance to have a new release with this fix? We're looking forward to this as we need to import users into state on GitLab.com. Thank you. 🤞

@ringods
Copy link
Contributor

ringods commented Jul 24, 2020

Released as v2.11.0. Sorry for the delay but swamped at work.

@Majkl578
Copy link
Author

@ringods Thank you very much, trying it right now! 👏

@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3 participants