forked from fortinetdev/terraform-provider-fortios
/
data_source_firewallservice_categorylist.go
79 lines (64 loc) · 1.72 KB
/
data_source_firewallservice_categorylist.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
// Copyright 2020 Fortinet, Inc. All rights reserved.
// Author: Frank Shen (@frankshen01), Hongbin Lu (@fgtdev-hblu)
// Documentation:
// Frank Shen (@frankshen01), Hongbin Lu (@fgtdev-hblu),
// Xing Li (@lix-fortinet), Yue Wang (@yuew-ftnt), Yuffie Zhu (@yuffiezhu)
package fortios
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceFirewallServiceCategoryList() *schema.Resource {
return &schema.Resource{
Read: dataSourceFirewallServiceCategoryListRead,
Schema: map[string]*schema.Schema{
"vdomparam": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"filter": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"namelist": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
func dataSourceFirewallServiceCategoryListRead(d *schema.ResourceData, m interface{}) error {
c := m.(*FortiClient).Client
c.Retries = 1
vdomparam := ""
if v, ok := d.GetOk("vdomparam"); ok {
if s, ok := v.(string); ok {
vdomparam = s
}
}
filter := d.Get("filter").(string)
if filter != "" {
filter = escapeFilter(filter)
}
o, err := c.GenericGroupRead("/api/v2/cmdb/firewall.service/category", filter, vdomparam)
if err != nil {
return fmt.Errorf("Error describing FirewallServiceCategory: %v", err)
}
var tmps []string
if o != nil {
if len(o) == 0 || o[0] == nil {
return nil
}
for _, r := range o {
i := r.(map[string]interface{})
if _, ok := i["name"]; ok {
tmps = append(tmps, fortiStringValue(i["name"]))
}
}
}
d.Set("namelist", tmps)
d.SetId("DataSourceFirewallServiceCategoryList" + filter)
return nil
}