/
resource_ddos_dst_entry_src_dst_pair_l4_type_src_dst.go
149 lines (141 loc) · 5.21 KB
/
resource_ddos_dst_entry_src_dst_pair_l4_type_src_dst.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
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 resourceDdosDstEntrySrcDstPairL4TypeSrcDst() *schema.Resource {
return &schema.Resource{
Description: "`thunder_ddos_dst_entry_src_dst_pair_l4_type_src_dst`: DDOS L4 type\n\n__PLACEHOLDER__",
CreateContext: resourceDdosDstEntrySrcDstPairL4TypeSrcDstCreate,
UpdateContext: resourceDdosDstEntrySrcDstPairL4TypeSrcDstUpdate,
ReadContext: resourceDdosDstEntrySrcDstPairL4TypeSrcDstRead,
DeleteContext: resourceDdosDstEntrySrcDstPairL4TypeSrcDstDelete,
Schema: map[string]*schema.Schema{
"deny": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Blacklist and Drop all incoming packets for protocol",
},
"glid": {
Type: schema.TypeString, Optional: true, Description: "Global limit ID",
},
"protocol": {
Type: schema.TypeString, Required: true, Description: "'tcp': tcp; 'udp': udp; 'icmp': icmp; 'other': other;",
},
"template": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tcp": {
Type: schema.TypeString, Optional: true, Description: "DDOS TCP template",
},
"udp": {
Type: schema.TypeString, Optional: true, Description: "DDOS UDP template",
},
"other": {
Type: schema.TypeString, Optional: true, Description: "DDOS OTHER template",
},
"template_icmp_v4": {
Type: schema.TypeString, Optional: true, Description: "DDOS icmp-v4 template",
},
"template_icmp_v6": {
Type: schema.TypeString, Optional: true, Description: "DDOS icmp-v6 template",
},
},
},
},
"user_tag": {
Type: schema.TypeString, Optional: true, Description: "Customized tag",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
"dst_entry_name": {
Type: schema.TypeString, Required: true, Description: "DstEntryName",
},
},
}
}
func resourceDdosDstEntrySrcDstPairL4TypeSrcDstCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosDstEntrySrcDstPairL4TypeSrcDstCreate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosDstEntrySrcDstPairL4TypeSrcDst(d)
d.SetId(obj.GetId())
err := obj.Post(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceDdosDstEntrySrcDstPairL4TypeSrcDstRead(ctx, d, meta)
}
return diags
}
func resourceDdosDstEntrySrcDstPairL4TypeSrcDstUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosDstEntrySrcDstPairL4TypeSrcDstUpdate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosDstEntrySrcDstPairL4TypeSrcDst(d)
err := obj.Put(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceDdosDstEntrySrcDstPairL4TypeSrcDstRead(ctx, d, meta)
}
return diags
}
func resourceDdosDstEntrySrcDstPairL4TypeSrcDstDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosDstEntrySrcDstPairL4TypeSrcDstDelete()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosDstEntrySrcDstPairL4TypeSrcDst(d)
err := obj.Delete(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func resourceDdosDstEntrySrcDstPairL4TypeSrcDstRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosDstEntrySrcDstPairL4TypeSrcDstRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosDstEntrySrcDstPairL4TypeSrcDst(d)
err := obj.Get(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func getObjectDdosDstEntrySrcDstPairL4TypeSrcDstTemplate(d []interface{}) edpt.DdosDstEntrySrcDstPairL4TypeSrcDstTemplate {
count1 := len(d)
var ret edpt.DdosDstEntrySrcDstPairL4TypeSrcDstTemplate
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Tcp = in["tcp"].(string)
ret.Udp = in["udp"].(string)
ret.Other = in["other"].(string)
ret.TemplateIcmpV4 = in["template_icmp_v4"].(string)
ret.TemplateIcmpV6 = in["template_icmp_v6"].(string)
}
return ret
}
func dataToEndpointDdosDstEntrySrcDstPairL4TypeSrcDst(d *schema.ResourceData) edpt.DdosDstEntrySrcDstPairL4TypeSrcDst {
var ret edpt.DdosDstEntrySrcDstPairL4TypeSrcDst
ret.Inst.Deny = d.Get("deny").(int)
ret.Inst.Glid = d.Get("glid").(string)
ret.Inst.Protocol = d.Get("protocol").(string)
ret.Inst.Template = getObjectDdosDstEntrySrcDstPairL4TypeSrcDstTemplate(d.Get("template").([]interface{}))
ret.Inst.UserTag = d.Get("user_tag").(string)
//omit uuid
ret.Inst.DstEntryName = d.Get("dst_entry_name").(string)
return ret
}