Commit 8eb4960
Improvements to resource_gitlab_user Import (#193)
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)1 parent 08bba6a commit 8eb4960
2 files changed
+28
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
20 | 36 | | |
21 | 37 | | |
22 | 38 | | |
| |||
26 | 42 | | |
27 | 43 | | |
28 | 44 | | |
29 | | - | |
| 45 | + | |
30 | 46 | | |
31 | 47 | | |
32 | 48 | | |
| |||
109 | 125 | | |
110 | 126 | | |
111 | 127 | | |
112 | | - | |
| 128 | + | |
113 | 129 | | |
114 | 130 | | |
115 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
77 | 86 | | |
78 | 87 | | |
79 | 88 | | |
| |||
0 commit comments