/
resource_ddos_dst_zone_ip_proto_proto_number_src_based_policy_policy_class_list.go
255 lines (241 loc) · 10.8 KB
/
resource_ddos_dst_zone_ip_proto_proto_number_src_based_policy_policy_class_list.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
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 resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassList() *schema.Resource {
return &schema.Resource{
Description: "`thunder_ddos_dst_zone_ip_proto_proto_number_src_based_policy_policy_class_list`: Configure class-list\n\n__PLACEHOLDER__",
CreateContext: resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListCreate,
UpdateContext: resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListUpdate,
ReadContext: resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListRead,
DeleteContext: resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListDelete,
Schema: map[string]*schema.Schema{
"action": {
Type: schema.TypeString, Optional: true, Description: "'bypass': Always permit for the Source to bypass all feature & limit checks; 'deny': Blacklist incoming packets for service;",
},
"class_list_name": {
Type: schema.TypeString, Required: true, Description: "Class-list name",
},
"class_list_overflow_policy_list": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dummy_name": {
Type: schema.TypeString, Required: true, Description: "'configuration': Configure overflow policy for class-list;",
},
"glid": {
Type: schema.TypeString, Optional: true, Description: "Global limit ID",
},
"action": {
Type: schema.TypeString, Optional: true, Description: "'bypass': Always permit for the Source to bypass all feature & limit checks; 'deny': Blacklist incoming packets for service;",
},
"log_enable": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable logging",
},
"log_periodic": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable log periodic",
},
"zone_template": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_proto": {
Type: schema.TypeString, Optional: true, Description: "DDOS ip-proto template",
},
},
},
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
"user_tag": {
Type: schema.TypeString, Optional: true, Description: "Customized tag",
},
},
},
},
"glid": {
Type: schema.TypeString, Optional: true, Description: "Global limit ID",
},
"glid_action": {
Type: schema.TypeString, Optional: true, Description: "'drop': Drop packets for glid exceed (Default); 'blacklist-src': Blacklist-src for glid exceed; 'ignore': Do nothing for glid exceed;",
},
"log_enable": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable logging",
},
"log_periodic": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable log periodic",
},
"max_dynamic_entry_count": {
Type: schema.TypeInt, Optional: true, Description: "Maximum count for dynamic source zone service entry allowed for this class-list",
},
"sampling_enable": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"counters1": {
Type: schema.TypeString, Optional: true, Description: "'all': all; 'packet_received': Packets Received; 'packet_dropped': Packets Dropped; 'entry_learned': Entry Learned; 'entry_count_overflow': Entry Count Overflow;",
},
},
},
},
"user_tag": {
Type: schema.TypeString, Optional: true, Description: "Customized tag",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
"zone_template": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"logging": {
Type: schema.TypeString, Optional: true, Description: "DDOS logging template",
},
"ip_proto": {
Type: schema.TypeString, Optional: true, Description: "DDOS ip-proto template",
},
},
},
},
"src_based_policy_name": {
Type: schema.TypeString, Required: true, Description: "SrcBasedPolicyName",
},
"zone_name": {
Type: schema.TypeString, Required: true, Description: "ZoneName",
},
"protocol_num": {
Type: schema.TypeString, Required: true, Description: "ProtocolNum",
},
},
}
}
func resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListCreate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassList(d)
d.SetId(obj.GetId())
err := obj.Post(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListRead(ctx, d, meta)
}
return diags
}
func resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListUpdate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassList(d)
err := obj.Put(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListRead(ctx, d, meta)
}
return diags
}
func resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListDelete()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassList(d)
err := obj.Delete(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassList(d)
err := obj.Get(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func getSliceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListClassListOverflowPolicyList(d []interface{}) []edpt.DdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListClassListOverflowPolicyList {
count1 := len(d)
ret := make([]edpt.DdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListClassListOverflowPolicyList, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.DdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListClassListOverflowPolicyList
oi.DummyName = in["dummy_name"].(string)
oi.Glid = in["glid"].(string)
oi.Action = in["action"].(string)
oi.LogEnable = in["log_enable"].(int)
oi.LogPeriodic = in["log_periodic"].(int)
oi.ZoneTemplate = getObjectDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListClassListOverflowPolicyListZoneTemplate(in["zone_template"].([]interface{}))
//omit uuid
oi.UserTag = in["user_tag"].(string)
ret = append(ret, oi)
}
return ret
}
func getObjectDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListClassListOverflowPolicyListZoneTemplate(d []interface{}) edpt.DdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListClassListOverflowPolicyListZoneTemplate {
count1 := len(d)
var ret edpt.DdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListClassListOverflowPolicyListZoneTemplate
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.IpProto = in["ip_proto"].(string)
}
return ret
}
func getSliceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListSamplingEnable(d []interface{}) []edpt.DdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListSamplingEnable {
count1 := len(d)
ret := make([]edpt.DdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListSamplingEnable, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.DdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListSamplingEnable
oi.Counters1 = in["counters1"].(string)
ret = append(ret, oi)
}
return ret
}
func getObjectDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListZoneTemplate(d []interface{}) edpt.DdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListZoneTemplate {
count1 := len(d)
var ret edpt.DdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListZoneTemplate
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Logging = in["logging"].(string)
ret.IpProto = in["ip_proto"].(string)
}
return ret
}
func dataToEndpointDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassList(d *schema.ResourceData) edpt.DdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassList {
var ret edpt.DdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassList
ret.Inst.Action = d.Get("action").(string)
ret.Inst.ClassListName = d.Get("class_list_name").(string)
ret.Inst.ClassListOverflowPolicyList = getSliceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListClassListOverflowPolicyList(d.Get("class_list_overflow_policy_list").([]interface{}))
ret.Inst.Glid = d.Get("glid").(string)
ret.Inst.GlidAction = d.Get("glid_action").(string)
ret.Inst.LogEnable = d.Get("log_enable").(int)
ret.Inst.LogPeriodic = d.Get("log_periodic").(int)
ret.Inst.MaxDynamicEntryCount = d.Get("max_dynamic_entry_count").(int)
ret.Inst.SamplingEnable = getSliceDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListSamplingEnable(d.Get("sampling_enable").([]interface{}))
ret.Inst.UserTag = d.Get("user_tag").(string)
//omit uuid
ret.Inst.ZoneTemplate = getObjectDdosDstZoneIpProtoProtoNumberSrcBasedPolicyPolicyClassListZoneTemplate(d.Get("zone_template").([]interface{}))
ret.Inst.SrcBasedPolicyName = d.Get("src_based_policy_name").(string)
ret.Inst.ZoneName = d.Get("zone_name").(string)
ret.Inst.ProtocolNum = d.Get("protocol_num").(string)
return ret
}