-
Notifications
You must be signed in to change notification settings - Fork 14
/
data_source_zpa_application_segment_by_type.go
119 lines (108 loc) · 3.96 KB
/
data_source_zpa_application_segment_by_type.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
package zpa
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceApplicationSegmentByType() *schema.Resource {
return &schema.Resource{
Read: dataSourceApplicationSegmentByTypeRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier of the Browser Access application",
},
"app_id": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier of the application",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the Browser Access application",
},
"application_type": {
Type: schema.TypeString,
Required: true,
Description: "The type of application, BROWSER_ACCESS, INSPECT or SECURE_REMOTE_ACCESS",
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether the Browser Access application is enabled or not",
},
"domain": {
Type: schema.TypeString,
Computed: true,
Description: "The domain of the Browser Access application",
},
"application_port": {
Type: schema.TypeString,
Computed: true,
Description: "The port for the Browser Access application",
},
"application_protocol": {
Type: schema.TypeString,
Computed: true,
Description: "The protocol for the Browser Access application",
},
"certificate_id": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier of the Browser Access certificate",
},
"certificate_name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the Browser Access certificate",
},
"microtenant_id": {
Type: schema.TypeString,
Optional: true,
Description: "The unique identifier of the Microtenant for the ZPA tenant. If you are within the Default Microtenant, pass microtenantId as 0 when making requests to retrieve data from the Default Microtenant. Pass microtenantId as null to retrieve data from all customers associated with the tenant",
},
"microtenant_name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the Microtenant",
},
},
}
}
func dataSourceApplicationSegmentByTypeRead(d *schema.ResourceData, m interface{}) error {
client := m.(*Client)
service := client.applicationsegmentbytype.WithMicroTenant(GetString(d.Get("microtenant_id")))
applicationType := d.Get("application_type").(string)
if applicationType != "BROWSER_ACCESS" && applicationType != "SECURE_REMOTE_ACCESS" && applicationType != "INSPECT" {
return fmt.Errorf("invalid application_type '%s'. Valid types are 'BROWSER_ACCESS', 'SECURE_REMOTE_ACCESS', 'INSPECT'", applicationType)
}
name := d.Get("name").(string)
log.Printf("[INFO] Getting data for application segment with type %s", applicationType)
if name != "" {
log.Printf("[INFO] Getting data for application segment with name %s and type %s", name, applicationType)
}
// Call the SDK function
resp, _, err := service.GetByApplicationType(name, applicationType, true)
if err != nil {
return err
}
if len(resp) == 0 {
return fmt.Errorf("no application segment found for name '%s' and type '%s'", name, applicationType)
}
// Assuming we are only interested in the first result for simplicity
appSegment := resp[0]
d.SetId(appSegment.ID)
_ = d.Set("app_id", appSegment.AppID)
_ = d.Set("name", appSegment.Name)
_ = d.Set("enabled", appSegment.Enabled)
_ = d.Set("domain", appSegment.Domain)
_ = d.Set("application_port", appSegment.ApplicationPort)
_ = d.Set("application_protocol", appSegment.ApplicationProtocol)
_ = d.Set("certificate_id", appSegment.CertificateID)
_ = d.Set("certificate_name", appSegment.CertificateName)
_ = d.Set("microtenant_id", appSegment.MicroTenantID)
_ = d.Set("microtenant_name", appSegment.MicroTenantName)
return nil
}