-
Notifications
You must be signed in to change notification settings - Fork 372
/
resource_secret_acl.go
84 lines (79 loc) · 1.98 KB
/
resource_secret_acl.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package secrets
import (
"context"
"github.com/databricks/databricks-sdk-go/service/workspace"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
// ResourceSecretACL manages access to secret scopes
func ResourceSecretACL() common.Resource {
p := common.NewPairSeparatedID("scope", "principal", "|||")
s := map[string]*schema.Schema{
"scope": {
Type: schema.TypeString,
ValidateFunc: validScope,
Required: true,
ForceNew: true,
},
"principal": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"permission": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
}
return common.Resource{
Schema: s,
Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
w, err := c.WorkspaceClient()
if err != nil {
return err
}
var req workspace.PutAcl
common.DataToStructPointer(d, s, &req)
err = w.Secrets.PutAcl(ctx, req)
if err != nil {
return err
}
// TODO: check what happens if ID is set before error happens in create
p.Pack(d)
return nil
},
Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
scope, principal, err := p.Unpack(d)
if err != nil {
return err
}
w, err := c.WorkspaceClient()
if err != nil {
return err
}
secretACL, err := w.Secrets.GetAcl(ctx, workspace.GetAclRequest{
Scope: scope,
Principal: principal,
})
if err != nil {
return err
}
return d.Set("permission", secretACL.Permission.String())
},
Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
scope, principal, err := p.Unpack(d)
if err != nil {
return err
}
w, err := c.WorkspaceClient()
if err != nil {
return err
}
return w.Secrets.DeleteAcl(ctx, workspace.DeleteAcl{
Scope: scope,
Principal: principal,
})
},
}
}