/
resource_fw_session_aging_tcp.go
159 lines (151 loc) · 5.9 KB
/
resource_fw_session_aging_tcp.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
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 resourceFwSessionAgingTcp() *schema.Resource {
return &schema.Resource{
Description: "`thunder_fw_session_aging_tcp`: TCP Aging options\n\n__PLACEHOLDER__",
CreateContext: resourceFwSessionAgingTcpCreate,
UpdateContext: resourceFwSessionAgingTcpUpdate,
ReadContext: resourceFwSessionAgingTcpRead,
DeleteContext: resourceFwSessionAgingTcpDelete,
Schema: map[string]*schema.Schema{
"force_delete_timeout": {
Type: schema.TypeInt, Optional: true, Description: "The maximum time that a session can stay in the system before being deleted, default is off (number (second))",
},
"force_delete_timeout_100ms": {
Type: schema.TypeInt, Optional: true, Description: "The maximum time that a session can stay in the system before being deleted, default is off (number in 100ms)",
},
"half_close_idle_timeout": {
Type: schema.TypeInt, Optional: true, Description: "TCP Half Close Idle Timeout (sec), default is off (number)",
},
"half_open_idle_timeout": {
Type: schema.TypeInt, Optional: true, Description: "TCP Half Open Idle Timeout (sec), default is off (number)",
},
"port_cfg": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tcp_port": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"tcp_idle_timeout": {
Type: schema.TypeInt, Optional: true, Description: "Idle Timeout (sec), default is 600 (number)",
},
"half_open_idle_timeout": {
Type: schema.TypeInt, Optional: true, Description: "TCP Half Open Idle Timeout (sec), default is off (number)",
},
"half_close_idle_timeout": {
Type: schema.TypeInt, Optional: true, Description: "TCP Half Close Idle Timeout (sec), default is off (number)",
},
"force_delete_timeout": {
Type: schema.TypeInt, Optional: true, Description: "The maximum time that a session can stay in the system before being deleted, default is off (number (second))",
},
"force_delete_timeout_100ms": {
Type: schema.TypeInt, Optional: true, Description: "The maximum time that a session can stay in the system before being deleted, default is off (number in 100ms)",
},
},
},
},
"tcp_idle_timeout": {
Type: schema.TypeInt, Optional: true, Default: 600, Description: "Idle Timeout (sec), default is 600 (number)",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
"name": {
Type: schema.TypeString, Required: true, Description: "Name",
},
},
}
}
func resourceFwSessionAgingTcpCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceFwSessionAgingTcpCreate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointFwSessionAgingTcp(d)
d.SetId(obj.GetId())
err := obj.Post(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceFwSessionAgingTcpRead(ctx, d, meta)
}
return diags
}
func resourceFwSessionAgingTcpUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceFwSessionAgingTcpUpdate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointFwSessionAgingTcp(d)
err := obj.Put(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceFwSessionAgingTcpRead(ctx, d, meta)
}
return diags
}
func resourceFwSessionAgingTcpDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceFwSessionAgingTcpDelete()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointFwSessionAgingTcp(d)
err := obj.Delete(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func resourceFwSessionAgingTcpRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceFwSessionAgingTcpRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointFwSessionAgingTcp(d)
err := obj.Get(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func getSliceFwSessionAgingTcpPortCfg(d []interface{}) []edpt.FwSessionAgingTcpPortCfg {
count1 := len(d)
ret := make([]edpt.FwSessionAgingTcpPortCfg, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.FwSessionAgingTcpPortCfg
oi.TcpPort = in["tcp_port"].(int)
oi.TcpIdleTimeout = in["tcp_idle_timeout"].(int)
oi.HalfOpenIdleTimeout = in["half_open_idle_timeout"].(int)
oi.HalfCloseIdleTimeout = in["half_close_idle_timeout"].(int)
oi.ForceDeleteTimeout = in["force_delete_timeout"].(int)
oi.ForceDeleteTimeout100ms = in["force_delete_timeout_100ms"].(int)
ret = append(ret, oi)
}
return ret
}
func dataToEndpointFwSessionAgingTcp(d *schema.ResourceData) edpt.FwSessionAgingTcp {
var ret edpt.FwSessionAgingTcp
ret.Inst.ForceDeleteTimeout = d.Get("force_delete_timeout").(int)
ret.Inst.ForceDeleteTimeout100ms = d.Get("force_delete_timeout_100ms").(int)
ret.Inst.HalfCloseIdleTimeout = d.Get("half_close_idle_timeout").(int)
ret.Inst.HalfOpenIdleTimeout = d.Get("half_open_idle_timeout").(int)
ret.Inst.PortCfg = getSliceFwSessionAgingTcpPortCfg(d.Get("port_cfg").([]interface{}))
ret.Inst.TcpIdleTimeout = d.Get("tcp_idle_timeout").(int)
//omit uuid
ret.Inst.Name = d.Get("name").(string)
return ret
}