-
Notifications
You must be signed in to change notification settings - Fork 10
/
data_source_all_domain_details.go
246 lines (241 loc) · 7.1 KB
/
data_source_all_domain_details.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
package athenz
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/AthenZ/terraform-provider-athenz/client"
"github.com/ardielle/ardielle-go/rdl"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceAllDomainDetails() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceAllDomainDetailsRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"gcp_project_id": {
Type: schema.TypeString,
Optional: true,
},
"gcp_project_number": {
Type: schema.TypeString,
Optional: true,
},
"aws_account_id": {
Type: schema.TypeString,
Optional: true,
},
"azure_subscription": {
Type: schema.TypeString,
Optional: true,
},
"description": {
Type: schema.TypeString,
Description: "description for the domain",
Optional: true,
},
"org": {
Type: schema.TypeString,
Description: "audit organization name for the domain",
Optional: true,
},
"application_id": {
Type: schema.TypeString,
Description: "associated application id",
Optional: true,
},
"user_expiry_days": {
Type: schema.TypeInt,
Optional: true,
Description: "all user members in the domain will have specified max expiry days",
},
"token_expiry_mins": {
Type: schema.TypeInt,
Optional: true,
Description: "tokens issued for this domain will have specified max timeout in mins",
},
"service_cert_expiry_mins": {
Type: schema.TypeInt,
Optional: true,
Description: "service identity certs issued for this domain will have specified max timeout in mins",
},
"role_cert_expiry_mins": {
Type: schema.TypeInt,
Optional: true,
Description: "role certs issued for this domain will have specified max timeout in mins",
},
"service_expiry_days": {
Type: schema.TypeInt,
Optional: true,
Description: "all services in the domain roles will have specified max expiry days",
},
"group_expiry_days": {
Type: schema.TypeInt,
Optional: true,
Description: "all groups in the domain roles will have specified max expiry days",
},
"member_purge_expiry_days": {
Type: schema.TypeInt,
Optional: true,
Description: "purge role/group members with expiry date configured days in the past",
},
"user_authority_filter": {
Type: schema.TypeString,
Description: "membership filtered based on user authority configured attributes",
Optional: true,
},
"business_service": {
Type: schema.TypeString,
Description: "associated business service with domain",
Optional: true,
},
"environment": {
Type: schema.TypeString,
Description: "string specifying the environment this domain is used in (production, staging, etc.)",
Optional: true,
},
"tags": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"contacts": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"role_list": {
Type: schema.TypeSet,
Description: "set of all roles",
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"policy_list": {
Type: schema.TypeSet,
Description: "set of all policies",
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"service_list": {
Type: schema.TypeSet,
Description: "set of all services",
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"group_list": {
Type: schema.TypeSet,
Description: "set of all groups",
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
func dataSourceAllDomainDetailsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
zmsClient := meta.(client.ZmsClient)
domainName := d.Get("name").(string)
domain, err := zmsClient.GetDomain(domainName)
switch v := err.(type) {
case rdl.ResourceError:
if v.Code == 404 {
return diag.Errorf("athenz domain %s not found, update your data source query", domainName)
} else {
return diag.Errorf("error retrieving Athenz domain: %s", v)
}
case rdl.Any:
return diag.FromErr(err)
}
if domain == nil {
return diag.Errorf("error retrieving Athenz domain: %s", domainName)
}
d.SetId(string(domain.Name))
if domain.Account != "" {
d.Set("aws_account_id", domain.Account)
}
if domain.GcpProject != "" && domain.GcpProjectNumber != "" {
d.Set("gcp_project_id", domain.GcpProject)
d.Set("gcp_project_number", domain.GcpProjectNumber)
}
if domain.AzureSubscription != "" {
d.Set("azure_subscription", domain.AzureSubscription)
}
if domain.Org != "" {
d.Set("org", domain.Org)
}
if domain.Description != "" {
d.Set("description", domain.Description)
}
if domain.MemberExpiryDays != nil {
d.Set("user_expiry_days", domain.MemberExpiryDays)
}
if domain.ApplicationId != "" {
d.Set("application_id", domain.ApplicationId)
}
if domain.TokenExpiryMins != nil {
d.Set("token_expiry_mins", domain.TokenExpiryMins)
}
if domain.ServiceCertExpiryMins != nil {
d.Set("service_cert_expiry_mins", domain.ServiceCertExpiryMins)
}
if domain.RoleCertExpiryMins != nil {
d.Set("role_cert_expiry_mins", domain.RoleCertExpiryMins)
}
if domain.ServiceExpiryDays != nil {
d.Set("service_expiry_days", domain.ServiceExpiryDays)
}
if domain.GroupExpiryDays != nil {
d.Set("group_expiry_days", domain.GroupExpiryDays)
}
if domain.MemberPurgeExpiryDays != nil {
d.Set("member_purge_expiry_days", domain.MemberPurgeExpiryDays)
}
if domain.UserAuthorityFilter != "" {
d.Set("user_authority_filter", domain.UserAuthorityFilter)
}
if domain.BusinessService != "" {
d.Set("business_service", domain.BusinessService)
}
if domain.Environment != "" {
d.Set("environment", domain.Environment)
}
if domain.Tags != nil {
d.Set("tags", flattenTag(domain.Tags))
}
if domain.Contacts != nil {
d.Set("contacts", domain.Contacts)
}
roleList, err := zmsClient.GetRoleList(domainName, nil, "")
if err != nil {
return diag.FromErr(err)
}
if err = d.Set("role_list", convertEntityNameListToStringList(roleList.Names)); err != nil {
return diag.FromErr(err)
}
policyList, err := zmsClient.GetPolicyList(domainName, nil, "")
if err != nil {
return diag.FromErr(err)
}
if err = d.Set("policy_list", convertEntityNameListToStringList(policyList.Names)); err != nil {
return diag.FromErr(err)
}
serviceList, err := zmsClient.GetServiceIdentityList(domainName, nil, "")
if err != nil {
return diag.FromErr(err)
}
if err = d.Set("service_list", convertEntityNameListToStringList(serviceList.Names)); err != nil {
return diag.FromErr(err)
}
groupList, err := zmsClient.GetGroups(domainName, nil)
if err != nil {
return diag.FromErr(err)
}
if err = d.Set("group_list", getGroupsNames(groupList.List)); err != nil {
return diag.FromErr(err)
}
return nil
}