Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/data-sources/global_role_binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ data "rancher2_global_role_binding" "foo" {
* `id` - (Computed) The ID of the resource (string)
* `group_principal_id` - (Computed) The group principal ID to assign global role binding. Rancher v2.4.0 or higher is required (string)
* `user_id` - (Computed) The user ID to assign global role binding (string)
* `user_principal_id` - (Computed) The user principal ID to assign global role binding (string)
* `annotations` - (Computed) Annotations of the resource (map)
* `labels` - (Computed) Labels of the resource (map)
11 changes: 9 additions & 2 deletions docs/resources/global_role_binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ resource "rancher2_global_role_binding" "foo" {
global_role_id = "admin"
user_id = "user-XXXXX"
}
# Create a new rancher2 Global Role Binding using group_principal_id
# Create a new rancher2 Global Role Binding using user_principal_id
resource "rancher2_global_role_binding" "foo2" {
name = "foo2"
global_role_id = "admin"
user_principal_id = "local://user-XXXXX"
}
# Create a new rancher2 Global Role Binding using group_principal_id
resource "rancher2_global_role_binding" "foo3" {
name = "foo3"
global_role_id = "admin"
group_principal_id = "local://g-XXXXX"
}
```
Expand All @@ -30,11 +36,12 @@ The following arguments are supported:
* `global_role_id` - (Required/ForceNew) The role id from create global role binding (string)
* `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)
* `user_id` - (Optional/Computed/ForceNew) The user ID to assign global role binding (string)
* `user_principal_id` - (Optional/Computed/ForceNew) The user principal ID to assign global role binding (string)
* `name` - (Optional/Computed/ForceNew) The name of the global role binding (string)
* `annotations` - (Optional/Computed) Annotations for global role binding (map)
* `labels` - (Optional/Computed) Labels for global role binding (map)

**Note:** user `user_id` OR group `group_principal_id` must be defined
**Note:** user `user_id` or `user_principal_id` OR group `group_principal_id` must be defined

## Attributes Reference

Expand Down
4 changes: 4 additions & 0 deletions rancher2/data_source_rancher2_global_role_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func dataSourceRancher2GlobalRoleBinding() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"user_principal_id": {
Type: schema.TypeString,
Computed: true,
},
"group_principal_id": {
Type: schema.TypeString,
Computed: true,
Expand Down
8 changes: 7 additions & 1 deletion rancher2/schema_global_role_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

// Shemas
// Schemas

func globalRoleBindingFields() map[string]*schema.Schema {
s := map[string]*schema.Schema{
Expand All @@ -19,6 +19,12 @@ func globalRoleBindingFields() map[string]*schema.Schema {
Computed: true,
ForceNew: true,
},
"user_principal_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down
2 changes: 2 additions & 0 deletions rancher2/structure_global_role_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func flattenGlobalRoleBinding(d *schema.ResourceData, in *managementClient.Globa
d.SetId(in.ID)
d.Set("global_role_id", in.GlobalRoleID)
d.Set("user_id", in.UserID)
d.Set("user_principal_id", in.UserPrincipalID)
d.Set("name", in.Name)

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

obj.GlobalRoleID = in.Get("global_role_id").(string)
obj.UserID = in.Get("user_id").(string)
obj.UserPrincipalID = in.Get("user_principal_id").(string)
obj.Name = in.Get("name").(string)

if v, ok := in.Get("group_principal_id").(string); ok && len(v) > 0 {
Expand Down
18 changes: 10 additions & 8 deletions rancher2/structure_global_role_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ var (

func init() {
testGlobalRoleBindingConf = &managementClient.GlobalRoleBinding{
GlobalRoleID: "global_role_id",
GroupPrincipalID: "group_principal_id",
UserID: "user-test",
Name: "test",
GlobalRoleID: "global_role_id",
GroupPrincipalID: "group_principal_id",
UserPrincipalID: "user_principal_id",
UserID: "user-test",
Name: "test",
}
testGlobalRoleBindingInterface = map[string]interface{}{
"global_role_id": "global_role_id",
"group_principal_id": "group_principal_id",
"user_id": "user-test",
"name": "test",
"global_role_id": "global_role_id",
"group_principal_id": "group_principal_id",
"user_principal_id": "user_principal_id",
"user_id": "user-test",
"name": "test",
}
}

Expand Down
Loading