/
resource_netflow_monitor_disable_log_by_destination_ip.go
167 lines (157 loc) · 6 KB
/
resource_netflow_monitor_disable_log_by_destination_ip.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package thunder
import (
"context"
edpt "github.com/a10networks/terraform-provider-thunder/thunder/axapi/endpoint"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceNetflowMonitorDisableLogByDestinationIp() *schema.Resource {
return &schema.Resource{
Description: "`thunder_netflow_monitor_disable_log_by_destination_ip`: Configure a filter IP enrty\n\n__PLACEHOLDER__",
CreateContext: resourceNetflowMonitorDisableLogByDestinationIpCreate,
UpdateContext: resourceNetflowMonitorDisableLogByDestinationIpUpdate,
ReadContext: resourceNetflowMonitorDisableLogByDestinationIpRead,
DeleteContext: resourceNetflowMonitorDisableLogByDestinationIpDelete,
Schema: map[string]*schema.Schema{
"icmp": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Disable logging for icmp traffic",
},
"ipv4_addr": {
Type: schema.TypeString, Required: true, Description: "Configure an IP subnet",
},
"others": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Disable logging for other L4 protocols",
},
"tcp_list": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tcp_port_start": {
Type: schema.TypeInt, Optional: true, Description: "Destination Port (Single Destination Port or Port Range Start)",
},
"tcp_port_end": {
Type: schema.TypeInt, Optional: true, Description: "Port Range End",
},
},
},
},
"udp_list": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"udp_port_start": {
Type: schema.TypeInt, Optional: true, Description: "Destination Port (Single Destination Port or Port Range Start)",
},
"udp_port_end": {
Type: schema.TypeInt, Optional: true, Description: "Port Range End",
},
},
},
},
"user_tag": {
Type: schema.TypeString, Optional: true, Description: "Customized tag",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
"name": {
Type: schema.TypeString, Required: true, Description: "Name",
},
},
}
}
func resourceNetflowMonitorDisableLogByDestinationIpCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceNetflowMonitorDisableLogByDestinationIpCreate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointNetflowMonitorDisableLogByDestinationIp(d)
d.SetId(obj.GetId())
err := obj.Post(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceNetflowMonitorDisableLogByDestinationIpRead(ctx, d, meta)
}
return diags
}
func resourceNetflowMonitorDisableLogByDestinationIpUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceNetflowMonitorDisableLogByDestinationIpUpdate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointNetflowMonitorDisableLogByDestinationIp(d)
err := obj.Put(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceNetflowMonitorDisableLogByDestinationIpRead(ctx, d, meta)
}
return diags
}
func resourceNetflowMonitorDisableLogByDestinationIpDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceNetflowMonitorDisableLogByDestinationIpDelete()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointNetflowMonitorDisableLogByDestinationIp(d)
err := obj.Delete(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func resourceNetflowMonitorDisableLogByDestinationIpRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceNetflowMonitorDisableLogByDestinationIpRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointNetflowMonitorDisableLogByDestinationIp(d)
err := obj.Get(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func getSliceNetflowMonitorDisableLogByDestinationIpTcpList(d []interface{}) []edpt.NetflowMonitorDisableLogByDestinationIpTcpList {
count1 := len(d)
ret := make([]edpt.NetflowMonitorDisableLogByDestinationIpTcpList, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.NetflowMonitorDisableLogByDestinationIpTcpList
oi.TcpPortStart = in["tcp_port_start"].(int)
oi.TcpPortEnd = in["tcp_port_end"].(int)
ret = append(ret, oi)
}
return ret
}
func getSliceNetflowMonitorDisableLogByDestinationIpUdpList(d []interface{}) []edpt.NetflowMonitorDisableLogByDestinationIpUdpList {
count1 := len(d)
ret := make([]edpt.NetflowMonitorDisableLogByDestinationIpUdpList, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.NetflowMonitorDisableLogByDestinationIpUdpList
oi.UdpPortStart = in["udp_port_start"].(int)
oi.UdpPortEnd = in["udp_port_end"].(int)
ret = append(ret, oi)
}
return ret
}
func dataToEndpointNetflowMonitorDisableLogByDestinationIp(d *schema.ResourceData) edpt.NetflowMonitorDisableLogByDestinationIp {
var ret edpt.NetflowMonitorDisableLogByDestinationIp
ret.Inst.Icmp = d.Get("icmp").(int)
ret.Inst.Ipv4Addr = d.Get("ipv4_addr").(string)
ret.Inst.Others = d.Get("others").(int)
ret.Inst.TcpList = getSliceNetflowMonitorDisableLogByDestinationIpTcpList(d.Get("tcp_list").([]interface{}))
ret.Inst.UdpList = getSliceNetflowMonitorDisableLogByDestinationIpUdpList(d.Get("udp_list").([]interface{}))
ret.Inst.UserTag = d.Get("user_tag").(string)
//omit uuid
ret.Inst.Name = d.Get("name").(string)
return ret
}