-
Notifications
You must be signed in to change notification settings - Fork 14
/
data_source_zpa_pra_portal_controller.go
137 lines (131 loc) · 4.3 KB
/
data_source_zpa_pra_portal_controller.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
package zpa
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/zscaler/zscaler-sdk-go/v2/zpa/services/privilegedremoteaccess/praportal"
)
func dataSourcePRAPortalController() *schema.Resource {
return &schema.Resource{
Read: dataSourcePRAPortalControllerRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Optional: true,
Description: "The unique identifier of the privileged portal",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the privileged portal",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the privileged portal",
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether or not the privileged portal is enabled",
},
"cname": {
Type: schema.TypeString,
Computed: true,
Description: "The canonical name (CNAME DNS records) associated with the privileged portal",
},
"domain": {
Type: schema.TypeString,
Computed: true,
Description: "The domain of the privileged portal",
},
"certificate_id": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier of the certificate",
},
"certificate_name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the certificate",
},
"user_notification": {
Type: schema.TypeString,
Computed: true,
Description: "The notification message displayed in the banner of the privileged portallink, if enabled",
},
"user_notification_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates if the Notification Banner is enabled (true) or disabled (false)",
},
"creation_time": {
Type: schema.TypeString,
Computed: true,
Description: "The time the privileged portal is created",
},
"modified_by": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier of the tenant who modified the privileged portal",
},
"modified_time": {
Type: schema.TypeString,
Computed: true,
Description: "The time the privileged portal is modified",
},
"microtenant_id": {
Type: schema.TypeString,
Computed: 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 dataSourcePRAPortalControllerRead(d *schema.ResourceData, m interface{}) error {
service := m.(*Client).praportal.WithMicroTenant(GetString(d.Get("microtenant_id")))
var resp *praportal.PRAPortal
id, ok := d.Get("id").(string)
if ok && id != "" {
log.Printf("[INFO] Getting data for pra portal controller %s\n", id)
res, _, err := service.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 pra portal controller name %s\n", name)
res, _, err := service.GetByName(name)
if err != nil {
return err
}
resp = res
}
if resp != nil {
d.SetId(resp.ID)
_ = d.Set("name", resp.Name)
_ = d.Set("description", resp.Description)
_ = d.Set("enabled", resp.Enabled)
_ = d.Set("cname", resp.CName)
_ = d.Set("domain", resp.Domain)
_ = d.Set("certificate_id", resp.CertificateID)
_ = d.Set("certificate_name", resp.CertificateName)
_ = d.Set("user_notification", resp.UserNotification)
_ = d.Set("user_notification_enabled", resp.UserNotificationEnabled)
_ = d.Set("creation_time", resp.CreationTime)
_ = d.Set("modified_by", resp.ModifiedBy)
_ = d.Set("modified_time", resp.ModifiedTime)
_ = d.Set("microtenant_id", resp.MicroTenantID)
_ = d.Set("microtenant_name", resp.MicroTenantName)
} else {
return fmt.Errorf("couldn't find any pra portal controller with name '%s' or id '%s'", name, id)
}
return nil
}