-
Notifications
You must be signed in to change notification settings - Fork 16
/
data_source_zpa_application_segment_browser_access.go
249 lines (239 loc) · 6.66 KB
/
data_source_zpa_application_segment_browser_access.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
package zpa
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/zscaler/zscaler-sdk-go/v2/zpa/services/browseraccess"
)
func dataSourceApplicationSegmentBrowserAccess() *schema.Resource {
return &schema.Resource{
Read: dataSourceApplicationSegmentBrowserAccessRead,
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,
},
"tcp_port_range": resourceNetworkPortsSchema("tcp port range"),
"udp_port_range": resourceNetworkPortsSchema("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},
},
"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.",
},
"clientless_apps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"allow_options": {
Type: schema.TypeBool,
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,
},
"cname": {
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,
},
"id": {
Type: schema.TypeString,
Computed: true,
},
"local_domain": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"path": {
Type: schema.TypeString,
Computed: true,
},
"trust_untrusted_cert": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"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 dataSourceApplicationSegmentBrowserAccessRead(d *schema.ResourceData, m interface{}) error {
zClient := m.(*Client)
var resp *browseraccess.BrowserAccess
id, ok := d.Get("id").(string)
if ok && id != "" {
log.Printf("[INFO] Getting data for browser access application %s\n", id)
res, _, err := zClient.browseraccess.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 browser access application name %s\n", name)
res, _, err := zClient.browseraccess.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("clientless_apps", flattenBaClientlessApps(resp)); err != nil {
return fmt.Errorf("failed to read clientless apps %s", err)
}
if err := d.Set("server_groups", flattenClientlessAppServerGroups(resp.AppServerGroups)); 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
}