-
Notifications
You must be signed in to change notification settings - Fork 31
/
permission.go
69 lines (61 loc) · 2.39 KB
/
permission.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
package mgmz
import (
"fmt"
"github.com/dynatrace-oss/terraform-provider-dynatrace/terraform/hcl"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
type Permission struct {
EnvironmentID string
GroupID string
ManagementZoneID string
Permissions []string
}
func (me *Permission) Name() string {
return fmt.Sprintf("%s#-#%s#-#%s", me.EnvironmentID, me.GroupID, me.ManagementZoneID)
}
func (me *Permission) Schema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"environment": {
Type: schema.TypeString,
Required: true,
Description: "The UUID of the environment",
},
"group": {
Type: schema.TypeString,
Required: true,
Description: "The ID of the group the permissions are valid for. You may refer to the id of a resource `dynatrace_user_group` here",
},
"management_zone": {
Type: schema.TypeString,
Required: true,
Description: "The ID of the management zone the permissions are valid for. When referring to resource `dynatrace_management_zone_v2` or data source `dynatrace_management_zone` you need to refer to the attribute `legacy_id`.",
},
"permissions": {
Type: schema.TypeSet,
Required: true,
MinItems: 1,
Description: "The permissions to assign for that management zone. Allowed values are `DEMO_USER`, `LOG_VIEWER`, `MANAGE_SECURITY_PROBLEMS`, `MANAGE_SETTINGS`, `REPLAY_SESSION_DATA`, `REPLAY_SESSION_DATA_WITHOUT_MASKING`, `VIEWER`, `VIEW_SENSITIVE_REQUEST_DATA`",
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"DEMO_USER", "LOG_VIEWER", "MANAGE_SECURITY_PROBLEMS", "MANAGE_SETTINGS", "REPLAY_SESSION_DATA", "REPLAY_SESSION_DATA_WITHOUT_MASKING", "VIEWER", "VIEW_SENSITIVE_REQUEST_DATA"}, false),
},
},
}
}
func (me *Permission) MarshalHCL(properties hcl.Properties) error {
return properties.EncodeAll(map[string]any{
"environment": me.EnvironmentID,
"group": me.GroupID,
"management_zone": me.ManagementZoneID,
"permissions": me.Permissions,
})
}
func (me *Permission) UnmarshalHCL(decoder hcl.Decoder) error {
return decoder.DecodeAll(map[string]any{
"environment": &me.EnvironmentID,
"group": &me.GroupID,
"management_zone": &me.ManagementZoneID,
"permissions": &me.Permissions,
})
}