-
Notifications
You must be signed in to change notification settings - Fork 14
/
data_source_zpa_lss_config_status_codes.go
79 lines (69 loc) · 1.78 KB
/
data_source_zpa_lss_config_status_codes.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
package zpa
import (
"encoding/json"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceLSSStatusCodes() *schema.Resource {
return &schema.Resource{
Read: dataSourceLSSStatusCodesRead,
Importer: &schema.ResourceImporter{},
Schema: map[string]*schema.Schema{
"zpn_auth_log": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"zpn_ast_auth_log": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"zpn_trans_log": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"zpn_sys_auth_log": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}
func toMapString(v map[string]interface{}) map[string]string {
result := make(map[string]string)
for key, val := range v {
data, err := json.MarshalIndent(&val, "", " ")
if err != nil {
log.Printf("[ERROR] MarshalIndent failed %v\n", err)
continue
}
result[key] = string(data)
}
return result
}
func dataSourceLSSStatusCodesRead(d *schema.ResourceData, m interface{}) error {
zClient := m.(*Client)
log.Printf("[INFO] Getting data for LSS Status Codes set\n")
resp, _, err := zClient.lssconfigcontroller.GetStatusCodes()
if err != nil {
return err
}
log.Printf("[INFO] Getting LSS Status Codes:\n%+v\n", resp)
d.SetId("lss_status_codes")
_ = d.Set("zpn_auth_log", toMapString(resp.ZPNAstAuthLog))
_ = d.Set("zpn_ast_auth_log", toMapString(resp.ZPNAstAuthLog))
_ = d.Set("zpn_trans_log", toMapString(resp.ZPNTransLog))
_ = d.Set("zpn_sys_auth_log", toMapString(resp.ZPNSysAuthLog))
return nil
}