[Feature] Add user principal id to global role binding#2153
Conversation
Add user_principal_id field to enable assigning global roles to remote users via their principal ID, matching the pattern used in cluster_role_template_binding and project_role_template_binding. This fixes rancher#2152 Made with OpenCode using Qwen3.6-35B-A3B
|
Have you tested "ForceNew" here? Does it cause existing configurations which upgrade to the new version to need to be recreated? If so, that would be a breaking change. |
There was a problem hiding this comment.
Pull request overview
Adds support for assigning rancher2_global_role_binding to remote users via user_principal_id, bringing the global role binding resource/data source in line with the existing patterns for cluster/project role template bindings.
Changes:
- Extend the global role binding schema/resource flatten+expand to include
user_principal_id. - Expose
user_principal_idon therancher2_global_role_bindingdata source. - Update docs and structure tests to cover the new attribute.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
rancher2/schema_global_role_binding.go |
Adds user_principal_id to the resource schema. |
rancher2/structure_global_role_binding.go |
Adds flatten/expand wiring for UserPrincipalID. |
rancher2/data_source_rancher2_global_role_binding.go |
Adds computed user_principal_id to the data source schema. |
rancher2/structure_global_role_binding_test.go |
Updates flatten/expand tests to include user_principal_id. |
docs/resources/global_role_binding.md |
Documents user_principal_id and adds an example for it. |
docs/data-sources/global_role_binding.md |
Documents the new computed attribute. |
Comments suppressed due to low confidence (1)
rancher2/structure_global_role_binding.go:23
flattenGlobalRoleBindingonly setsgroup_principal_idwhen the API value is non-empty. If the binding changes on the server (e.g., from group-based to user-based), the prior non-emptygroup_principal_idcan remain in Terraform state because it is never explicitly cleared. Consider always callingd.Set("group_principal_id", in.GroupPrincipalID)(even when empty) to keep state accurate and consistent with other *RoleTemplateBinding flatteners in this repo.
d.Set("user_principal_id", in.UserPrincipalID)
d.Set("name", in.Name)
if len(in.GroupPrincipalID) > 0 {
d.Set("group_principal_id", in.GroupPrincipalID)
}
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@matttrach how do I test it? Is there a test that will do it or do I need write a Tofu module that uses this provider to test this situation? |
I ran a analysis using my LLM; Yes, it is a breaking change. Here's the analysis: What's happeningThe Rancher API's
The So knowing this is a breaking change (the field is immutable at the API level), what should I do? |
|
I updated the description of the PR with a breaking change notice. |
|
@matttrach do I need to do anything to get this moving along? |
|
Hi @Raboo, I am getting the appropriate team to review, sorry for the wait. |
JonCrowther
left a comment
There was a problem hiding this comment.
LGTM. Thanks for contributing!
|
Thanks guys! Will this be a part of v15.0.0? |
Summary
user_principal_idfield torancher2_global_role_bindingresource, enabling assignment of global roles to remote users via their principal IDrancher2_cluster_role_template_bindingandrancher2_project_role_template_bindinguser_principal_idto the data source as well for completenessRelated
Fixes #2152
Changes
rancher2/schema_global_role_binding.gouser_principal_idfield to schemarancher2/structure_global_role_binding.goUserPrincipalIDrancher2/data_source_rancher2_global_role_binding.gouser_principal_idcomputed attributerancher2/structure_global_role_binding_test.gouser_principal_iddocs/resources/global_role_binding.mddocs/data-sources/global_role_binding.mdTesting
TestFlattenGlobalRoleBinding— PASSTestExpandGlobalRoleBinding— PASSgo build ./...— compiles cleanlyBreaking Change Notice
This is a breaking change for existing
rancher2_global_role_bindingresources.The
user_principal_idfield usesForceNew: true, which means that on upgrade, Terraform will detect a diff between the config (which does not specifyuser_principal_id) and the state (which will be populated from the Rancher API during refresh). This triggers a destroy and recreate of all existing global role bindings managed by Terraform.This matches the pattern used in
rancher2_cluster_role_template_bindingandrancher2_project_role_template_binding, whereForceNew: truewas eventually adopted for identity-related fields. The field is immutable at the Rancher API level — a global role binding's principal cannot be changed without recreating the binding.Generated with
This PR was made with OpenCode using model Qwen3.6-35B-A3B.