generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 44
/
data_source_usergroup.go
151 lines (136 loc) · 4.05 KB
/
data_source_usergroup.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package usergroup
import (
"context"
"errors"
"net/http"
"github.com/harness/harness-go-sdk/harness/nextgen"
"github.com/harness/terraform-provider-harness/helpers"
"github.com/harness/terraform-provider-harness/internal"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceUserGroup() *schema.Resource {
resource := &schema.Resource{
Description: "Data source for retrieving a Harness User Group.",
ReadContext: dataSourceUserGroupRead,
Schema: map[string]*schema.Schema{
"linked_sso_id": {
Description: "The SSO account ID that the user group is linked to.",
Type: schema.TypeString,
Computed: true,
},
"externally_managed": {
Description: "Whether the user group is externally managed.",
Type: schema.TypeBool,
Computed: true,
},
"users": {
Description: "List of users in the UserGroup.",
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"notification_configs": {
Description: "List of notification settings.",
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Description: "Can be one of EMAIL, SLACK, PAGERDUTY, MSTEAMS.",
Type: schema.TypeString,
Computed: true,
},
"slack_webhook_url": {
Description: "Url of slack webhook.",
Type: schema.TypeString,
Computed: true,
},
"microsoft_teams_webhook_url": {
Description: "Url of Microsoft teams webhook.",
Type: schema.TypeString,
Computed: true,
},
"pager_duty_key": {
Description: "Pager duty key.",
Type: schema.TypeString,
Computed: true,
},
"group_email": {
Description: "Group email.",
Type: schema.TypeString,
Computed: true,
},
"send_email_to_all_users": {
Description: "Send email to all the group members.",
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"linked_sso_display_name": {
Description: "Name of the linked SSO.",
Type: schema.TypeString,
Computed: true,
},
"sso_group_id": {
Description: "Identifier of the userGroup in SSO.",
Type: schema.TypeString,
Computed: true,
},
"sso_group_name": {
Description: "Name of the SSO userGroup.",
Type: schema.TypeString,
Computed: true,
},
"linked_sso_type": {
Description: "Type of linked SSO.",
Type: schema.TypeString,
Computed: true,
},
"sso_linked": {
Description: "Whether sso is linked or not.",
Type: schema.TypeBool,
Computed: true,
},
},
}
helpers.SetMultiLevelDatasourceSchema(resource.Schema)
return resource
}
func dataSourceUserGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
var ug *nextgen.UserGroup
var err error
var httpResp *http.Response
id := d.Get("identifier").(string)
name := d.Get("name").(string)
if id != "" {
var resp nextgen.ResponseDtoUserGroup
resp, httpResp, err = c.UserGroupApi.GetUserGroup(ctx, c.AccountId, id, &nextgen.UserGroupApiGetUserGroupOpts{
OrgIdentifier: helpers.BuildField(d, "org_id"),
ProjectIdentifier: helpers.BuildField(d, "project_id"),
})
ug = resp.Data
} else if name != "" {
ug, httpResp, err = c.UserGroupApi.GetUserGroupByName(ctx, c.AccountId, name, &nextgen.UserGroupApiGetUserGroupByNameOpts{
OrgIdentifier: helpers.BuildField(d, "org_id"),
ProjectIdentifier: helpers.BuildField(d, "project_id"),
})
} else {
return diag.FromErr(errors.New("either identifier or name must be specified"))
}
if err != nil {
return helpers.HandleApiError(err, d, httpResp)
}
if ug == nil {
d.SetId("")
d.MarkNewResource()
return nil
}
readUserGroup(d, ug)
return nil
}