Skip to content

Commit 84dc033

Browse files
github-actions[bot]RabooCopilotmatttrach
authored
feat!: Add user principal id to global role binding (#2252)
Co-authored-by: Elias Abacioglu <1148206+Raboo@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Matt Trachier <matt.trachier@suse.com>
1 parent 4865835 commit 84dc033

6 files changed

Lines changed: 33 additions & 11 deletions

docs/data-sources/global_role_binding.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ data "rancher2_global_role_binding" "foo" {
2525
* `id` - (Computed) The ID of the resource (string)
2626
* `group_principal_id` - (Computed) The group principal ID to assign global role binding. Rancher v2.4.0 or higher is required (string)
2727
* `user_id` - (Computed) The user ID to assign global role binding (string)
28+
* `user_principal_id` - (Computed) The user principal ID to assign global role binding (string)
2829
* `annotations` - (Computed) Annotations of the resource (map)
2930
* `labels` - (Computed) Labels of the resource (map)

docs/resources/global_role_binding.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ resource "rancher2_global_role_binding" "foo" {
1515
global_role_id = "admin"
1616
user_id = "user-XXXXX"
1717
}
18-
# Create a new rancher2 Global Role Binding using group_principal_id
18+
# Create a new rancher2 Global Role Binding using user_principal_id
1919
resource "rancher2_global_role_binding" "foo2" {
2020
name = "foo2"
2121
global_role_id = "admin"
22+
user_principal_id = "local://user-XXXXX"
23+
}
24+
# Create a new rancher2 Global Role Binding using group_principal_id
25+
resource "rancher2_global_role_binding" "foo3" {
26+
name = "foo3"
27+
global_role_id = "admin"
2228
group_principal_id = "local://g-XXXXX"
2329
}
2430
```
@@ -30,11 +36,12 @@ The following arguments are supported:
3036
* `global_role_id` - (Required/ForceNew) The role id from create global role binding (string)
3137
* `group_principal_id` - (Optional/Computed/ForceNew) The group principal ID to assign global role binding (only works with external auth providers that support groups). Rancher v2.4.0 or higher is required (string)
3238
* `user_id` - (Optional/Computed/ForceNew) The user ID to assign global role binding (string)
39+
* `user_principal_id` - (Optional/Computed/ForceNew) The user principal ID to assign global role binding (string)
3340
* `name` - (Optional/Computed/ForceNew) The name of the global role binding (string)
3441
* `annotations` - (Optional/Computed) Annotations for global role binding (map)
3542
* `labels` - (Optional/Computed) Labels for global role binding (map)
3643

37-
**Note:** user `user_id` OR group `group_principal_id` must be defined
44+
**Note:** user `user_id` or `user_principal_id` OR group `group_principal_id` must be defined
3845

3946
## Attributes Reference
4047

rancher2/data_source_rancher2_global_role_binding.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ func dataSourceRancher2GlobalRoleBinding() *schema.Resource {
2424
Type: schema.TypeString,
2525
Computed: true,
2626
},
27+
"user_principal_id": {
28+
Type: schema.TypeString,
29+
Computed: true,
30+
},
2731
"group_principal_id": {
2832
Type: schema.TypeString,
2933
Computed: true,

rancher2/schema_global_role_binding.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
55
)
66

7-
// Shemas
7+
// Schemas
88

99
func globalRoleBindingFields() map[string]*schema.Schema {
1010
s := map[string]*schema.Schema{
@@ -19,6 +19,12 @@ func globalRoleBindingFields() map[string]*schema.Schema {
1919
Computed: true,
2020
ForceNew: true,
2121
},
22+
"user_principal_id": {
23+
Type: schema.TypeString,
24+
Optional: true,
25+
Computed: true,
26+
ForceNew: true,
27+
},
2228
"name": {
2329
Type: schema.TypeString,
2430
Optional: true,

rancher2/structure_global_role_binding.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func flattenGlobalRoleBinding(d *schema.ResourceData, in *managementClient.Globa
1515
d.SetId(in.ID)
1616
d.Set("global_role_id", in.GlobalRoleID)
1717
d.Set("user_id", in.UserID)
18+
d.Set("user_principal_id", in.UserPrincipalID)
1819
d.Set("name", in.Name)
1920

2021
if len(in.GroupPrincipalID) > 0 {
@@ -49,6 +50,7 @@ func expandGlobalRoleBinding(in *schema.ResourceData) *managementClient.GlobalRo
4950

5051
obj.GlobalRoleID = in.Get("global_role_id").(string)
5152
obj.UserID = in.Get("user_id").(string)
53+
obj.UserPrincipalID = in.Get("user_principal_id").(string)
5254
obj.Name = in.Get("name").(string)
5355

5456
if v, ok := in.Get("group_principal_id").(string); ok && len(v) > 0 {

rancher2/structure_global_role_binding_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ var (
1616

1717
func init() {
1818
testGlobalRoleBindingConf = &managementClient.GlobalRoleBinding{
19-
GlobalRoleID: "global_role_id",
20-
GroupPrincipalID: "group_principal_id",
21-
UserID: "user-test",
22-
Name: "test",
19+
GlobalRoleID: "global_role_id",
20+
GroupPrincipalID: "group_principal_id",
21+
UserPrincipalID: "user_principal_id",
22+
UserID: "user-test",
23+
Name: "test",
2324
}
2425
testGlobalRoleBindingInterface = map[string]interface{}{
25-
"global_role_id": "global_role_id",
26-
"group_principal_id": "group_principal_id",
27-
"user_id": "user-test",
28-
"name": "test",
26+
"global_role_id": "global_role_id",
27+
"group_principal_id": "group_principal_id",
28+
"user_principal_id": "user_principal_id",
29+
"user_id": "user-test",
30+
"name": "test",
2931
}
3032
}
3133

0 commit comments

Comments
 (0)