-
Notifications
You must be signed in to change notification settings - Fork 14
/
data_source_zpa_application_segment_pra.go
273 lines (259 loc) · 7.46 KB
/
data_source_zpa_application_segment_pra.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package zpa
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/zscaler/zscaler-sdk-go/zpa/services/applicationsegmentpra"
)
func dataSourceApplicationSegmentPRA() *schema.Resource {
return &schema.Resource{
Read: dataSourceApplicationSegmentPRARead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Optional: true,
},
"segment_group_id": {
Type: schema.TypeString,
Computed: true,
},
"segment_group_name": {
Type: schema.TypeString,
Computed: true,
},
"bypass_type": {
Type: schema.TypeString,
Computed: true,
},
"config_space": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Description of the application.",
},
"domain_names": {
Type: schema.TypeList,
Computed: true,
Description: "List of domains and IPs.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"double_encrypt": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether Double Encryption is enabled or disabled for the app.",
},
"health_check_type": {
Type: schema.TypeString,
Computed: true,
},
"passive_health_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"health_reporting": {
Type: schema.TypeString,
Computed: true,
Description: "Whether health reporting for the app is Continuous or On Access. Supported values: NONE, ON_ACCESS, CONTINUOUS.",
},
"ip_anchored": {
Type: schema.TypeBool,
Computed: true,
},
"is_cname_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates if the Zscaler Client Connector (formerly Zscaler App or Z App) receives CNAME DNS records from the connectors.",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Name of the application.",
},
"sra_apps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"app_id": {
Type: schema.TypeString,
Computed: true,
},
"application_port": {
Type: schema.TypeString,
Computed: true,
},
"application_protocol": {
Type: schema.TypeString,
Computed: true,
},
"certificate_id": {
Type: schema.TypeString,
Computed: true,
},
"certificate_name": {
Type: schema.TypeString,
Computed: true,
},
"connection_security": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"domain": {
Type: schema.TypeString,
Computed: true,
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"hidden": {
Type: schema.TypeBool,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"portal": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"tcp_port_range": resourceAppSegmentPortRange("tcp port range"),
"udp_port_range": resourceAppSegmentPortRange("udp port range"),
"tcp_port_ranges": {
Type: schema.TypeList,
Computed: true,
Description: "TCP port ranges used to access the app.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"udp_port_ranges": {
Type: schema.TypeList,
Computed: true,
Description: "UDP port ranges used to access the app.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"server_groups": {
Type: schema.TypeSet,
Computed: true,
Description: "List of the server group IDs.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
}
}
func dataSourceApplicationSegmentPRARead(d *schema.ResourceData, m interface{}) error {
zClient := m.(*Client)
var resp *applicationsegmentpra.AppSegmentPRA
id, ok := d.Get("id").(string)
if ok && id != "" {
log.Printf("[INFO] Getting data for sra application %s\n", id)
res, _, err := zClient.applicationsegmentpra.Get(id)
if err != nil {
return err
}
resp = res
}
name, ok := d.Get("name").(string)
if id == "" && ok && name != "" {
log.Printf("[INFO] Getting data for sra application name %s\n", name)
res, _, err := zClient.applicationsegmentpra.GetByName(name)
if err != nil {
return err
}
resp = res
}
if resp != nil {
d.SetId(resp.ID)
_ = d.Set("segment_group_id", resp.SegmentGroupID)
_ = d.Set("segment_group_name", resp.SegmentGroupName)
_ = d.Set("bypass_type", resp.BypassType)
_ = d.Set("config_space", resp.ConfigSpace)
_ = d.Set("domain_names", resp.DomainNames)
_ = d.Set("name", resp.Name)
_ = d.Set("description", resp.Description)
_ = d.Set("enabled", resp.Enabled)
_ = d.Set("passive_health_enabled", resp.PassiveHealthEnabled)
_ = d.Set("double_encrypt", resp.DoubleEncrypt)
_ = d.Set("health_check_type", resp.HealthCheckType)
_ = d.Set("is_cname_enabled", resp.IsCnameEnabled)
_ = d.Set("ip_anchored", resp.IpAnchored)
_ = d.Set("health_reporting", resp.HealthReporting)
_ = d.Set("tcp_port_ranges", resp.TCPPortRanges)
_ = d.Set("udp_port_ranges", resp.UDPPortRanges)
if err := d.Set("sra_apps", flattenSRAApps(resp)); err != nil {
return fmt.Errorf("failed to read sra apps %s", err)
}
if err := d.Set("server_groups", flattenSRAAppServerGroups(resp.ServerGroups)); err != nil {
return fmt.Errorf("failed to read app server groups %s", err)
}
if err := d.Set("tcp_port_range", flattenNetworkPorts(resp.TCPAppPortRange)); err != nil {
return err
}
if err := d.Set("tcp_port_range", flattenNetworkPorts(resp.UDPAppPortRange)); err != nil {
return err
}
} else {
return fmt.Errorf("couldn't find any browser access application with name '%s' or id '%s'", name, id)
}
return nil
}
func flattenSRAAppServerGroups(appServerGroup []applicationsegmentpra.AppServerGroups) []interface{} {
result := make([]interface{}, 1)
mapIds := make(map[string]interface{})
ids := make([]string, len(appServerGroup))
for i, serverGroup := range appServerGroup {
ids[i] = serverGroup.ID
}
mapIds["id"] = ids
result[0] = mapIds
return result
}
func flattenSRAApps(sraApp *applicationsegmentpra.AppSegmentPRA) []interface{} {
sraApps := make([]interface{}, len(sraApp.SRAAppsDto))
for i, val := range sraApp.SRAAppsDto {
sraApps[i] = map[string]interface{}{
"id": val.ID,
"app_id": val.AppID,
"application_port": val.ApplicationPort,
"application_protocol": val.ApplicationProtocol,
"certificate_id": val.CertificateID,
"certificate_name": val.CertificateName,
"connection_security": val.ConnectionSecurity,
"description": val.Description,
"domain": val.Domain,
"enabled": val.Enabled,
"hidden": val.Hidden,
"name": val.Name,
"portal": val.Portal,
}
}
return sraApps
}