-
Notifications
You must be signed in to change notification settings - Fork 117
/
resource_bigip_ltm_profile_fasthttp.go
242 lines (214 loc) · 7.24 KB
/
resource_bigip_ltm_profile_fasthttp.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
/*
Original work from https://github.com/DealerDotCom/terraform-provider-bigip
Modifications Copyright 2019 F5 Networks Inc.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package bigip
import (
"context"
"log"
bigip "github.com/f5devcentral/go-bigip"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceBigipLtmProfileFasthttp() *schema.Resource {
return &schema.Resource{
CreateContext: resourceBigipLtmProfileFasthttpCreate,
UpdateContext: resourceBigipLtmProfileFasthttpUpdate,
ReadContext: resourceBigipLtmProfileFasthttpRead,
DeleteContext: resourceBigipLtmProfileFasthttpDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Name of the Fasthttp Profile",
},
"defaults_from": {
Type: schema.TypeString,
Optional: true,
Description: "Use the parent Fasthttp profile",
},
"idle_timeout": {
Type: schema.TypeInt,
Optional: true,
Description: "integer value",
// Default: 300,
Computed: true,
},
"connpoolidle_timeoutoverride": {
Type: schema.TypeInt,
Optional: true,
Description: "idle_timeout can be given value",
Computed: true,
},
"connpool_maxreuse": {
Type: schema.TypeInt,
Optional: true,
Description: "connpool_maxreuse timer",
// Default: 0,
Computed: true,
},
"connpool_maxsize": {
Type: schema.TypeInt,
Optional: true,
Description: "timer integer",
Computed: true,
},
"connpool_minsize": {
Type: schema.TypeInt,
Optional: true,
Description: "Pool min size",
Computed: true,
},
"connpool_replenish": {
Type: schema.TypeString,
Optional: true,
Description: "enabled or disabled",
// Default: "enabled",
Computed: true,
},
"connpool_step": {
Type: schema.TypeInt,
Optional: true,
Description: "integer value",
// Default: 4,
Computed: true,
},
"forcehttp_10response": {
Type: schema.TypeString,
Optional: true,
Description: "disabled or enabled ",
// Default: "",
Computed: true,
},
"maxheader_size": {
Type: schema.TypeInt,
Optional: true,
Description: "integer value",
// Default: 32768,
Computed: true,
},
},
}
}
func resourceBigipLtmProfileFasthttpCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*bigip.BigIP)
name := d.Get("name").(string)
defaultsFrom := d.Get("defaults_from").(string)
idleTimeout := d.Get("idle_timeout").(int)
connpoolIdleTimeoutOverride := d.Get("connpoolidle_timeoutoverride").(int)
connpoolMaxReuse := d.Get("connpool_maxreuse").(int)
connpoolMaxSize := d.Get("connpool_maxsize").(int)
connpoolMinSize := d.Get("connpool_minsize").(int)
connpoolReplenish := d.Get("connpool_replenish").(string)
connpoolStep := d.Get("connpool_step").(int)
forcehttp10response := d.Get("forcehttp_10response").(string)
maxHeaderSize := d.Get("maxheader_size").(int)
log.Println("[INFO] Creating Fasthttp profile")
r := &bigip.Fasthttp{
Name: name,
DefaultsFrom: defaultsFrom,
IdleTimeout: idleTimeout,
ConnpoolIdleTimeoutOverride: connpoolIdleTimeoutOverride,
ConnpoolMaxReuse: connpoolMaxReuse,
ConnpoolMaxSize: connpoolMaxSize,
ConnpoolMinSize: connpoolMinSize,
ConnpoolReplenish: connpoolReplenish,
ConnpoolStep: connpoolStep,
ForceHttp_10Response: forcehttp10response,
MaxHeaderSize: maxHeaderSize,
}
err := client.CreateFasthttp(r)
if err != nil {
log.Printf("[ERROR] Unable to Create Fasthttp (%s) (%v) ", name, err)
return diag.FromErr(err)
}
d.SetId(name)
return resourceBigipLtmProfileFasthttpRead(ctx, d, meta)
}
func resourceBigipLtmProfileFasthttpUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*bigip.BigIP)
name := d.Id()
r := &bigip.Fasthttp{
Name: name,
DefaultsFrom: d.Get("defaults_from").(string),
IdleTimeout: d.Get("idle_timeout").(int),
ConnpoolIdleTimeoutOverride: d.Get("connpoolidle_timeoutoverride").(int),
ConnpoolMaxReuse: d.Get("connpool_maxreuse").(int),
ConnpoolMaxSize: d.Get("connpool_maxsize").(int),
ConnpoolMinSize: d.Get("connpool_minsize").(int),
ConnpoolReplenish: d.Get("connpool_replenish").(string),
ConnpoolStep: d.Get("connpool_step").(int),
ForceHttp_10Response: d.Get("forcehttp_10response").(string),
MaxHeaderSize: d.Get("maxheader_size").(int),
}
err := client.ModifyFasthttp(name, r)
if err != nil {
log.Printf("[ERROR] Unable to Modify Fasthttp (%s) (%v) ", name, err)
return diag.FromErr(err)
}
return resourceBigipLtmProfileFasthttpRead(ctx, d, meta)
}
func resourceBigipLtmProfileFasthttpRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*bigip.BigIP)
name := d.Id()
obj, err := client.GetFasthttp(name)
if err != nil {
log.Printf("[ERROR] Unable to Retrieve Fasthttp (%s) (%v) ", name, err)
return diag.FromErr(err)
}
if obj == nil {
log.Printf("[WARN] Fasthttp profile (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
_ = d.Set("name", name)
if _, ok := d.GetOk("defaults_from"); ok {
_ = d.Set("defaults_from", obj.DefaultsFrom)
}
if _, ok := d.GetOk("idle_timeout"); ok {
_ = d.Set("idle_timeout", obj.IdleTimeout)
}
if _, ok := d.GetOk("connpoolidle_timeoutoverride"); ok {
_ = d.Set("connpoolidle_timeoutoverride", obj.ConnpoolIdleTimeoutOverride)
}
if _, ok := d.GetOk("connpool_maxreuse"); ok {
_ = d.Set("connpool_maxreuse", obj.ConnpoolMaxReuse)
}
if _, ok := d.GetOk("connpool_maxsize"); ok {
_ = d.Set("connpool_maxsize", obj.ConnpoolMaxSize)
}
if _, ok := d.GetOk("connpool_minsize"); ok {
_ = d.Set("connpool_minsize", obj.ConnpoolMinSize)
}
if _, ok := d.GetOk("connpool_replenish"); ok {
_ = d.Set("connpool_replenish", obj.ConnpoolReplenish)
}
if _, ok := d.GetOk("connpool_step"); ok {
_ = d.Set("connpool_step", obj.ConnpoolStep)
}
if _, ok := d.GetOk("forcehttp_10response"); ok {
_ = d.Set("forcehttp_10response", obj.ForceHttp_10Response)
}
if _, ok := d.GetOk("maxheader_size"); ok {
_ = d.Set("maxheader_size", obj.MaxHeaderSize)
}
return nil
}
func resourceBigipLtmProfileFasthttpDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*bigip.BigIP)
name := d.Id()
log.Println("[INFO] Deleting Fasthttp Profile " + name)
err := client.DeleteFasthttp(name)
if err != nil {
log.Printf("[ERROR] Unable to Delete Fasthttp (%s) (%v) ", name, err)
return diag.FromErr(err)
}
d.SetId("")
return nil
}