You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[FEAT] Support managing github_membership by stable user_id
Add an optional 'user_id' input (mutually exclusive with 'username',
both ForceNew) so org memberships can be addressed by GitHub's stable
numeric user ID. This makes the resource resilient to the user renaming
their GitHub account: Read resolves the current login via GET /user/{id}
and silently updates the 'username' attribute in state, producing no
diff.
Resource ID format changes from 'org:username' to 'org:user_id' for new
resources. Read performs a lazy migration: when an existing state has an
ID of the old shape, the username is resolved to its numeric ID and the
ID is rewritten in place. Imports support both legacy 'org:username' and
the new 'org:user_id' shape.
Includes an acceptance test (TestAccGithubMembershipRenameResilience)
that exercises the rename path end-to-end. The test requires
GH_TEST_EXTERNAL_USER_TOKEN since PATCH /user only works for the
authenticated user and skips otherwise.
Closes#524
Using `user_id` instead of `username` makes the membership resilient to the user renaming their GitHub account. After a rename, the next `terraform refresh` updates the `username` attribute in state with no diff, and the resource continues to manage the same membership.
26
+
27
+
```terraform
28
+
# Manage organization membership by stable GitHub user ID.
29
+
# Recommended over `username` for production: if the user renames their
30
+
# account, the membership stays in sync without drift.
-`username` - (Required) The user to add to the organization.
41
+
Exactly one of:
42
+
43
+
-`username` - (Optional) The user (login) to add to the organization. Note: usernames can change; if the user renames themselves, the resource will recreate unless `user_id` is used instead.
44
+
-`user_id` - (Optional) The GitHub numeric user ID to add to the organization. Stable across username changes. Recommended for production use.
45
+
46
+
Other arguments:
47
+
28
48
-`role` - (Optional) The role of the user within the organization. Must be one of `member` or `admin`. Defaults to `member`. `admin` role represents the `owner` role available via GitHub UI.
29
49
-`downgrade_on_destroy` - (Optional) Defaults to `false`. If set to true, when this resource is destroyed, the member will not be removed from the organization. Instead, the member's role will be downgraded to 'member'.
30
50
51
+
## Attributes Reference
52
+
53
+
-`username` - The user's current login. When the resource is identified by `user_id`, this attribute tracks the user's live login at refresh time.
54
+
-`user_id` - The GitHub numeric user ID.
55
+
-`etag` - The etag of the membership object.
56
+
31
57
## Import
32
58
33
-
GitHub Membership can be imported using an ID made up of `organization:username`, e.g.
59
+
GitHub Membership can be imported using an ID made up of `organization:user_id`, e.g.
Description: "The user to add to the organization.",
33
+
ExactlyOneOf: []string{"username", "user_id"},
34
+
Description: "The user (login) to add to the organization. Exactly one of `username` or `user_id` must be set.",
35
+
},
36
+
"user_id": {
37
+
Type: schema.TypeInt,
38
+
Optional: true,
39
+
Computed: true,
40
+
ForceNew: true,
41
+
ExactlyOneOf: []string{"username", "user_id"},
42
+
Description: "The GitHub numeric user ID to add to the organization. Stable across username changes; recommended over `username` for production usage. Exactly one of `username` or `user_id` must be set.",
32
43
},
33
44
"role": {
34
45
Type: schema.TypeString,
@@ -58,14 +69,19 @@ func resourceGithubMembershipCreateOrUpdate(ctx context.Context, d *schema.Resou
0 commit comments