/
resource_ddos_dst_dynamic_entry_overflow_policy_l4_type.go
219 lines (207 loc) · 8.67 KB
/
resource_ddos_dst_dynamic_entry_overflow_policy_l4_type.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
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 resourceDdosDstDynamicEntryOverflowPolicyL4Type() *schema.Resource {
return &schema.Resource{
Description: "`thunder_ddos_dst_dynamic_entry_overflow_policy_l4_type`: DDOS L4 type\n\n__PLACEHOLDER__",
CreateContext: resourceDdosDstDynamicEntryOverflowPolicyL4TypeCreate,
UpdateContext: resourceDdosDstDynamicEntryOverflowPolicyL4TypeUpdate,
ReadContext: resourceDdosDstDynamicEntryOverflowPolicyL4TypeRead,
DeleteContext: resourceDdosDstDynamicEntryOverflowPolicyL4TypeDelete,
Schema: map[string]*schema.Schema{
"deny": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Blacklist and Drop all incoming packets for protocol",
},
"drop_frag_pkt": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Drop fragmented packets",
},
"drop_on_no_port_match": {
Type: schema.TypeString, Optional: true, Default: "enable", Description: "'disable': disable; 'enable': enable;",
},
"glid": {
Type: schema.TypeString, Optional: true, Description: "Global limit ID",
},
"max_rexmit_syn_per_flow": {
Type: schema.TypeInt, Optional: true, Description: "Maximum number of re-transmit SYN per flow. Exceed action set to Drop",
},
"protocol": {
Type: schema.TypeString, Required: true, Description: "'tcp': tcp; 'udp': udp; 'icmp': icmp; 'other': other;",
},
"stateful": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable stateful tracking of sessions (Default is stateless)",
},
"syn_auth": {
Type: schema.TypeString, Optional: true, Default: "send-rst", Description: "'send-rst': Send RST to client upon client ACK; 'force-rst-by-ack': Force client RST via the use of ACK; 'force-rst-by-synack': Force client RST via the use of bad SYN|ACK; 'disable': Disable TCP SYN Authentication;",
},
"syn_cookie": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable SYN Cookie",
},
"tcp_reset_client": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Send reset to client when rate exceeds or session ages out",
},
"tcp_reset_server": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Send reset to server when rate exceeds or session ages out",
},
"tunnel_decap": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_decap": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable IP Tunnel decapsulation",
},
"gre_decap": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable GRE Tunnel decapsulation",
},
"key_cfg": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString, Optional: true, Description: "Only decapsulate GRE packet with this key (Hexadecimal 0x0-0xFFFFFFFF,decimal 0-4294967295)",
},
},
},
},
},
},
},
"tunnel_rate_limit": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_rate_limit": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable inner IP rate limiting on IPinIP traffic",
},
"gre_rate_limit": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable inner IP rate limiting on GRE traffic",
},
},
},
},
"user_tag": {
Type: schema.TypeString, Optional: true, Description: "Customized tag",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
"default_address_type": {
Type: schema.TypeString, Required: true, Description: "DefaultAddressType",
},
},
}
}
func resourceDdosDstDynamicEntryOverflowPolicyL4TypeCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosDstDynamicEntryOverflowPolicyL4TypeCreate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosDstDynamicEntryOverflowPolicyL4Type(d)
d.SetId(obj.GetId())
err := obj.Post(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceDdosDstDynamicEntryOverflowPolicyL4TypeRead(ctx, d, meta)
}
return diags
}
func resourceDdosDstDynamicEntryOverflowPolicyL4TypeUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosDstDynamicEntryOverflowPolicyL4TypeUpdate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosDstDynamicEntryOverflowPolicyL4Type(d)
err := obj.Put(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceDdosDstDynamicEntryOverflowPolicyL4TypeRead(ctx, d, meta)
}
return diags
}
func resourceDdosDstDynamicEntryOverflowPolicyL4TypeDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosDstDynamicEntryOverflowPolicyL4TypeDelete()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosDstDynamicEntryOverflowPolicyL4Type(d)
err := obj.Delete(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func resourceDdosDstDynamicEntryOverflowPolicyL4TypeRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosDstDynamicEntryOverflowPolicyL4TypeRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosDstDynamicEntryOverflowPolicyL4Type(d)
err := obj.Get(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func getObjectDdosDstDynamicEntryOverflowPolicyL4TypeTunnelDecap(d []interface{}) edpt.DdosDstDynamicEntryOverflowPolicyL4TypeTunnelDecap {
count1 := len(d)
var ret edpt.DdosDstDynamicEntryOverflowPolicyL4TypeTunnelDecap
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.IpDecap = in["ip_decap"].(int)
ret.GreDecap = in["gre_decap"].(int)
ret.KeyCfg = getSliceDdosDstDynamicEntryOverflowPolicyL4TypeTunnelDecapKeyCfg(in["key_cfg"].([]interface{}))
}
return ret
}
func getSliceDdosDstDynamicEntryOverflowPolicyL4TypeTunnelDecapKeyCfg(d []interface{}) []edpt.DdosDstDynamicEntryOverflowPolicyL4TypeTunnelDecapKeyCfg {
count1 := len(d)
ret := make([]edpt.DdosDstDynamicEntryOverflowPolicyL4TypeTunnelDecapKeyCfg, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.DdosDstDynamicEntryOverflowPolicyL4TypeTunnelDecapKeyCfg
oi.Key = in["key"].(string)
ret = append(ret, oi)
}
return ret
}
func getObjectDdosDstDynamicEntryOverflowPolicyL4TypeTunnelRateLimit(d []interface{}) edpt.DdosDstDynamicEntryOverflowPolicyL4TypeTunnelRateLimit {
count1 := len(d)
var ret edpt.DdosDstDynamicEntryOverflowPolicyL4TypeTunnelRateLimit
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.IpRateLimit = in["ip_rate_limit"].(int)
ret.GreRateLimit = in["gre_rate_limit"].(int)
}
return ret
}
func dataToEndpointDdosDstDynamicEntryOverflowPolicyL4Type(d *schema.ResourceData) edpt.DdosDstDynamicEntryOverflowPolicyL4Type {
var ret edpt.DdosDstDynamicEntryOverflowPolicyL4Type
ret.Inst.Deny = d.Get("deny").(int)
ret.Inst.DropFragPkt = d.Get("drop_frag_pkt").(int)
ret.Inst.DropOnNoPortMatch = d.Get("drop_on_no_port_match").(string)
ret.Inst.Glid = d.Get("glid").(string)
ret.Inst.MaxRexmitSynPerFlow = d.Get("max_rexmit_syn_per_flow").(int)
ret.Inst.Protocol = d.Get("protocol").(string)
ret.Inst.Stateful = d.Get("stateful").(int)
ret.Inst.SynAuth = d.Get("syn_auth").(string)
ret.Inst.SynCookie = d.Get("syn_cookie").(int)
ret.Inst.TcpResetClient = d.Get("tcp_reset_client").(int)
ret.Inst.TcpResetServer = d.Get("tcp_reset_server").(int)
ret.Inst.TunnelDecap = getObjectDdosDstDynamicEntryOverflowPolicyL4TypeTunnelDecap(d.Get("tunnel_decap").([]interface{}))
ret.Inst.TunnelRateLimit = getObjectDdosDstDynamicEntryOverflowPolicyL4TypeTunnelRateLimit(d.Get("tunnel_rate_limit").([]interface{}))
ret.Inst.UserTag = d.Get("user_tag").(string)
//omit uuid
ret.Inst.DefaultAddressType = d.Get("default_address_type").(string)
return ret
}