-
Notifications
You must be signed in to change notification settings - Fork 32
/
resource_avi_applicationprofile_test.go
275 lines (266 loc) · 8.42 KB
/
resource_avi_applicationprofile_test.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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package avi
import (
"fmt"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/vmware/alb-sdk/go/clients"
)
func TestAVIApplicationProfileBasic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAVIApplicationProfileDestroy,
Steps: []resource.TestStep{
{
Config: testAccAVIApplicationProfileConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAVIApplicationProfileExists("avi_applicationprofile.testApplicationProfile"),
resource.TestCheckResourceAttr(
"avi_applicationprofile.testApplicationProfile", "name", "test-System-Secure-HTTP-abc"),
resource.TestCheckResourceAttr(
"avi_applicationprofile.testApplicationProfile", "preserve_client_ip", "false"),
resource.TestCheckResourceAttr(
"avi_applicationprofile.testApplicationProfile", "preserve_client_port", "false"),
),
},
{
Config: testAccAVIApplicationProfileupdatedConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAVIApplicationProfileExists("avi_applicationprofile.testApplicationProfile"),
resource.TestCheckResourceAttr(
"avi_applicationprofile.testApplicationProfile", "name", "test-System-Secure-HTTP-updated"),
resource.TestCheckResourceAttr(
"avi_applicationprofile.testApplicationProfile", "preserve_client_ip", "false"),
resource.TestCheckResourceAttr(
"avi_applicationprofile.testApplicationProfile", "preserve_client_port", "false"),
),
},
{
ResourceName: "avi_applicationprofile.testApplicationProfile",
ImportState: true,
ImportStateVerify: false,
Config: testAccAVIApplicationProfileConfig,
},
},
})
}
func testAccCheckAVIApplicationProfileExists(resourcename string) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*clients.AviClient).AviSession
var obj interface{}
rs, ok := s.RootModule().Resources[resourcename]
if !ok {
return fmt.Errorf("Not found: %s", resourcename)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No AVI ApplicationProfile ID is set")
}
url := strings.SplitN(rs.Primary.ID, "/api", 2)[1]
uuid := strings.Split(url, "#")[0]
path := "api" + uuid
err := conn.Get(path, &obj)
if err != nil {
return err
}
return nil
}
}
func testAccCheckAVIApplicationProfileDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*clients.AviClient).AviSession
var obj interface{}
for _, rs := range s.RootModule().Resources {
if rs.Type != "avi_applicationprofile" {
continue
}
url := strings.SplitN(rs.Primary.ID, "/api", 2)[1]
uuid := strings.Split(url, "#")[0]
path := "api" + uuid
err := conn.Get(path, &obj)
if err != nil {
if strings.Contains(err.Error(), "404") {
return nil
}
return err
}
if len(obj.(map[string]interface{})) > 0 {
return fmt.Errorf("AVI ApplicationProfile still exists")
}
}
return nil
}
const testAccAVIApplicationProfileConfig = `
data "avi_tenant" "default_tenant"{
name= "admin"
}
data "avi_stringgroup" "system_compressiblestringgroup" {
name= "System-Compressible-Content-Types"
}
data "avi_stringgroup" "system_cacheablestringgroup" {
name= "System-Cacheable-Resource-Types"
}
data "avi_stringgroup" "system_mobilestringgroup" {
name = "System-Devices-Mobile"
}
resource "avi_applicationprofile" "testApplicationProfile" {
name = "test-System-Secure-HTTP-abc"
type = "APPLICATION_PROFILE_TYPE_HTTP"
tenant_ref = data.avi_tenant.default_tenant.id
preserve_client_ip = false
http_profile {
max_rps_uri = "0"
keepalive_header = false
max_rps_cip_uri = "0"
x_forwarded_proto_enabled = true
connection_multiplexing_enabled = true
websockets_enabled = true
enable_request_body_buffering = false
hsts_enabled = true
compression_profile {
type = "AUTO_COMPRESSION"
compressible_content_ref = data.avi_stringgroup.system_compressiblestringgroup.id
compression = false
remove_accept_encoding_header = true
mobile_str_ref = data.avi_stringgroup.system_mobilestringgroup.id
}
xff_enabled = true
disable_keepalive_posts_msie6 = true
keepalive_timeout = "30000"
ssl_client_certificate_mode = "SSL_CLIENT_CERTIFICATE_NONE"
http_to_https = true
respond_with_100_continue = true
max_bad_rps_cip_uri = "0"
client_body_timeout = "30000"
httponly_enabled = true
hsts_max_age = "365"
max_bad_rps_cip = "0"
server_side_redirect_to_https = true
client_max_header_size = "12"
client_max_request_size = "48"
cache_config {
min_object_size = "100"
query_cacheable = false
xcache_header = true
age_header = true
enabled = false
default_expire = "600"
max_cache_size = "0"
heuristic_expire = false
date_header = true
aggressive = false
max_object_size = "4194304"
mime_types_group_refs = [data.avi_stringgroup.system_cacheablestringgroup.id]
}
http2_profile {
http2_initial_window_size = "64"
max_http2_concurrent_streams_per_connection = "128"
max_http2_control_frames_per_connection = "1000"
max_http2_empty_data_frames_per_connection = "1000"
max_http2_header_field_size = "4096"
max_http2_queued_frames_to_client_per_connection = "1000"
max_http2_requests_per_connection = "1000"
}
max_rps_unknown_uri = "0"
post_accept_timeout = "30000"
client_header_timeout = "10000"
secure_cookie_enabled = true
max_response_headers_size = "48"
xff_alternate_name = "X-Forwarded-For"
max_rps_cip = "0"
enable_fire_and_forget = false
max_rps_unknown_cip = "0"
allow_dots_in_header_name = false
max_bad_rps_uri = "0"
use_app_keepalive_timeout = false
}
preserve_client_port = false
}
`
const testAccAVIApplicationProfileupdatedConfig = `
data "avi_tenant" "default_tenant"{
name= "admin"
}
data "avi_stringgroup" "system_compressiblestringgroup" {
name= "System-Compressible-Content-Types"
}
data "avi_stringgroup" "system_cacheablestringgroup" {
name= "System-Cacheable-Resource-Types"
}
data "avi_stringgroup" "system_mobilestringgroup" {
name = "System-Devices-Mobile"
}
resource "avi_applicationprofile" "testApplicationProfile" {
name = "test-System-Secure-HTTP-updated"
type = "APPLICATION_PROFILE_TYPE_HTTP"
tenant_ref = data.avi_tenant.default_tenant.id
preserve_client_ip = false
http_profile {
max_rps_uri = "0"
keepalive_header = false
max_rps_cip_uri = "0"
x_forwarded_proto_enabled = true
connection_multiplexing_enabled = true
websockets_enabled = true
enable_request_body_buffering = false
hsts_enabled = true
compression_profile {
type = "AUTO_COMPRESSION"
compressible_content_ref = data.avi_stringgroup.system_compressiblestringgroup.id
compression = false
remove_accept_encoding_header = true
mobile_str_ref = data.avi_stringgroup.system_mobilestringgroup.id
}
xff_enabled = true
disable_keepalive_posts_msie6 = true
keepalive_timeout = "30000"
ssl_client_certificate_mode = "SSL_CLIENT_CERTIFICATE_NONE"
http_to_https = true
respond_with_100_continue = true
max_bad_rps_cip_uri = "0"
client_body_timeout = "30000"
httponly_enabled = true
hsts_max_age = "365"
max_bad_rps_cip = "0"
server_side_redirect_to_https = true
client_max_header_size = "12"
client_max_request_size = "48"
cache_config {
min_object_size = "100"
query_cacheable = false
xcache_header = true
age_header = true
enabled = false
default_expire = "600"
max_cache_size = "0"
heuristic_expire = false
date_header = true
aggressive = false
max_object_size = "4194304"
mime_types_group_refs = [data.avi_stringgroup.system_cacheablestringgroup.id]
}
http2_profile {
http2_initial_window_size = "64"
max_http2_concurrent_streams_per_connection = "128"
max_http2_control_frames_per_connection = "1000"
max_http2_empty_data_frames_per_connection = "1000"
max_http2_header_field_size = "4096"
max_http2_queued_frames_to_client_per_connection = "1000"
max_http2_requests_per_connection = "1000"
}
max_rps_unknown_uri = "0"
post_accept_timeout = "30000"
client_header_timeout = "10000"
secure_cookie_enabled = true
max_response_headers_size = "48"
xff_alternate_name = "X-Forwarded-For"
max_rps_cip = "0"
enable_fire_and_forget = false
max_rps_unknown_cip = "0"
allow_dots_in_header_name = false
max_bad_rps_uri = "0"
use_app_keepalive_timeout = false
}
preserve_client_port = false
}
`