-
Notifications
You must be signed in to change notification settings - Fork 14
/
data_source_zpa_cloud_browser_isolation_banner.go
93 lines (86 loc) · 2.11 KB
/
data_source_zpa_cloud_browser_isolation_banner.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
package zpa
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/zscaler/zscaler-sdk-go/v2/zpa/services/cloudbrowserisolation/cbibannercontroller"
)
func dataSourceCBIBanners() *schema.Resource {
return &schema.Resource{
Read: dataSourceCBIBannersRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Optional: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
},
"primary_color": {
Type: schema.TypeString,
Computed: true,
},
"text_color": {
Type: schema.TypeString,
Computed: true,
},
"notification_title": {
Type: schema.TypeString,
Computed: true,
},
"notification_text": {
Type: schema.TypeString,
Computed: true,
},
"logo": {
Type: schema.TypeString,
Computed: true,
},
"banner": {
Type: schema.TypeBool,
Computed: true,
},
"is_default": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}
func dataSourceCBIBannersRead(d *schema.ResourceData, m interface{}) error {
zClient := m.(*Client)
var resp *cbibannercontroller.CBIBannerController
id, ok := d.Get("id").(string)
if ok && id != "" {
log.Printf("[INFO] Getting data for cbi banner %s\n", id)
res, _, err := zClient.cbibannercontroller.Get(id)
if err != nil {
return err
}
resp = res
}
name, ok := d.Get("name").(string)
if id == "" && ok && name != "" {
log.Printf("[INFO] Getting data cbi banner name %s\n", name)
res, _, err := zClient.cbibannercontroller.GetByName(name)
if err != nil {
return err
}
resp = res
}
if resp != nil {
d.SetId(resp.ID)
_ = d.Set("name", resp.Name)
_ = d.Set("primary_color", resp.PrimaryColor)
_ = d.Set("text_color", resp.TextColor)
_ = d.Set("notification_title", resp.NotificationTitle)
_ = d.Set("notification_text", resp.NotificationText)
_ = d.Set("logo", resp.Logo)
_ = d.Set("banner", resp.Banner)
_ = d.Set("is_default", resp.IsDefault)
} else {
return fmt.Errorf("couldn't find any cbi banner with name '%s' or id '%s'", name, id)
}
return nil
}