-
Notifications
You must be signed in to change notification settings - Fork 365
/
resource_group_role.go
30 lines (27 loc) · 1.04 KB
/
resource_group_role.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package scim
import (
"context"
"fmt"
"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/terraform-provider-databricks/common"
)
// ResourceGroupRole bind group with role
func ResourceGroupRole() common.Resource {
return common.NewPairID("group_id", "role").BindResource(common.BindResource{
CreateContext: func(ctx context.Context, groupID, role string, c *common.DatabricksClient) error {
return NewGroupsAPI(ctx, c).Patch(groupID, PatchRequestWithValue("add", "roles", role))
},
ReadContext: func(ctx context.Context, groupID, role string, c *common.DatabricksClient) error {
group, err := NewGroupsAPI(ctx, c).Read(groupID, "roles")
hasRole := ComplexValues(group.Roles).HasValue(role)
if err == nil && !hasRole {
return apierr.NotFound("Group has no role")
}
return err
},
DeleteContext: func(ctx context.Context, groupID, role string, c *common.DatabricksClient) error {
return NewGroupsAPI(ctx, c).Patch(groupID, PatchRequest(
"remove", fmt.Sprintf(`roles[value eq "%s"]`, role)))
},
})
}