@@ -80,6 +80,7 @@ func TestAccFastlyServiceVCLRequestSetting_basic(t *testing.T) {
80
80
}
81
81
82
82
rq2 := gofastly.RequestSetting {
83
+ Action : gofastly .ToPointer (gofastly .RequestSettingActionLookup ),
83
84
DefaultHost : gofastly .ToPointer ("tftestingother.tftesting.net.s3-website-us-west-2.amazonaws.com" ),
84
85
MaxStaleAge : gofastly .ToPointer (900 ),
85
86
Name : gofastly .ToPointer ("alt_backend" ),
@@ -99,6 +100,31 @@ func TestAccFastlyServiceVCLRequestSetting_basic(t *testing.T) {
99
100
HashKeys : gofastly .ToPointer ("" ),
100
101
TimerSupport : gofastly .ToPointer (false ),
101
102
}
103
+ rq3 := gofastly.RequestSetting {
104
+ Action : gofastly .ToPointer (gofastly .RequestSettingActionUnset ),
105
+ DefaultHost : gofastly .ToPointer ("tftestingother.tftesting.net.s3-website-us-west-2.amazonaws.com" ),
106
+ MaxStaleAge : gofastly .ToPointer (900 ),
107
+ Name : gofastly .ToPointer ("alt_backend" ),
108
+ RequestCondition : gofastly .ToPointer ("serve_alt_backend" ),
109
+ XForwardedFor : gofastly .ToPointer (gofastly .RequestSettingXFFAppend ),
110
+
111
+ // We only set a few attributes in our TF config (see above).
112
+ // For all the other attributes (with the exception of `action` and `xff`,
113
+ // which are only sent to the API if they have a non-zero string value)
114
+ // the default value for their types are still sent to the API
115
+ // and so the API responds with those default values. Hence we have to set
116
+ // those defaults below...
117
+ BypassBusyWait : gofastly .ToPointer (false ),
118
+ ForceMiss : gofastly .ToPointer (false ),
119
+ ForceSSL : gofastly .ToPointer (false ),
120
+ GeoHeaders : gofastly .ToPointer (false ),
121
+ HashKeys : gofastly .ToPointer ("" ),
122
+ TimerSupport : gofastly .ToPointer (false ),
123
+ }
124
+
125
+ createAction := "" // initially we expect no action to be set in HTTP request.
126
+ updateAction1 := "lookup" // give it a value and expect it to be set.
127
+ updateAction2 := "" // set an empty value and expect the empty string to be sent to the API.
102
128
103
129
resource .ParallelTest (t , resource.TestCase {
104
130
PreCheck : func () {
@@ -108,29 +134,44 @@ func TestAccFastlyServiceVCLRequestSetting_basic(t *testing.T) {
108
134
CheckDestroy : testAccCheckServiceVCLDestroy ,
109
135
Steps : []resource.TestStep {
110
136
{
111
- Config : testAccServiceVCLRequestSetting (name , domainName1 , "90" ),
137
+ Config : testAccServiceVCLRequestSetting (name , domainName1 , createAction , "90" ),
112
138
Check : resource .ComposeTestCheckFunc (
113
139
testAccCheckServiceExists ("fastly_service_vcl.foo" , & service ),
114
140
testAccCheckFastlyServiceVCLRequestSettingsAttributes (& service , []* gofastly.RequestSetting {& rq1 }),
115
- resource .TestCheckResourceAttr (
116
- "fastly_service_vcl.foo" , "name" , name ),
117
- resource .TestCheckResourceAttr (
118
- "fastly_service_vcl.foo" , "request_setting.#" , "1" ),
119
- resource .TestCheckResourceAttr (
120
- "fastly_service_vcl.foo" , "condition.#" , "1" ),
141
+ resource .TestCheckResourceAttr ("fastly_service_vcl.foo" , "name" , name ),
142
+ resource .TestCheckResourceAttr ("fastly_service_vcl.foo" , "request_setting.#" , "1" ),
143
+ resource .TestCheckResourceAttr ("fastly_service_vcl.foo" , "condition.#" , "1" ),
144
+ resource .TestCheckTypeSetElemNestedAttrs ("fastly_service_vcl.foo" , "request_setting.*" , map [string ]string {
145
+ "action" : "" , // IMPORTANT: To validate this attribute we need at least one map key to have a non-empty value (hence the `max_stale_age` check below).
146
+ "max_stale_age" : "900" ,
147
+ }),
121
148
),
122
149
},
123
150
{
124
- Config : testAccServiceVCLRequestSetting (name , domainName1 , "900" ),
151
+ Config : testAccServiceVCLRequestSetting (name , domainName1 , updateAction1 , "900" ),
125
152
Check : resource .ComposeTestCheckFunc (
126
153
testAccCheckServiceExists ("fastly_service_vcl.foo" , & service ),
127
154
testAccCheckFastlyServiceVCLRequestSettingsAttributes (& service , []* gofastly.RequestSetting {& rq2 }),
128
- resource .TestCheckResourceAttr (
129
- "fastly_service_vcl.foo" , "name" , name ),
130
- resource .TestCheckResourceAttr (
131
- "fastly_service_vcl.foo" , "request_setting.#" , "1" ),
132
- resource .TestCheckResourceAttr (
133
- "fastly_service_vcl.foo" , "condition.#" , "1" ),
155
+ resource .TestCheckResourceAttr ("fastly_service_vcl.foo" , "name" , name ),
156
+ resource .TestCheckResourceAttr ("fastly_service_vcl.foo" , "request_setting.#" , "1" ),
157
+ resource .TestCheckResourceAttr ("fastly_service_vcl.foo" , "condition.#" , "1" ),
158
+ resource .TestCheckTypeSetElemNestedAttrs ("fastly_service_vcl.foo" , "request_setting.*" , map [string ]string {
159
+ "action" : "lookup" ,
160
+ }),
161
+ ),
162
+ },
163
+ {
164
+ Config : testAccServiceVCLRequestSetting (name , domainName1 , updateAction2 , "900" ),
165
+ Check : resource .ComposeTestCheckFunc (
166
+ testAccCheckServiceExists ("fastly_service_vcl.foo" , & service ),
167
+ testAccCheckFastlyServiceVCLRequestSettingsAttributes (& service , []* gofastly.RequestSetting {& rq3 }),
168
+ resource .TestCheckResourceAttr ("fastly_service_vcl.foo" , "name" , name ),
169
+ resource .TestCheckResourceAttr ("fastly_service_vcl.foo" , "request_setting.#" , "1" ),
170
+ resource .TestCheckResourceAttr ("fastly_service_vcl.foo" , "condition.#" , "1" ),
171
+ resource .TestCheckTypeSetElemNestedAttrs ("fastly_service_vcl.foo" , "request_setting.*" , map [string ]string {
172
+ "action" : "" , // IMPORTANT: To validate this attribute we need at least one map key to have a non-empty value (hence the `max_stale_age` check below).
173
+ "max_stale_age" : "900" ,
174
+ }),
134
175
),
135
176
},
136
177
},
@@ -179,7 +220,7 @@ func testAccCheckFastlyServiceVCLRequestSettingsAttributes(service *gofastly.Ser
179
220
}
180
221
}
181
222
182
- func testAccServiceVCLRequestSetting (name , domain , maxStaleAge string ) string {
223
+ func testAccServiceVCLRequestSetting (name , domain , action , maxStaleAge string ) string {
183
224
return fmt .Sprintf (`
184
225
resource "fastly_service_vcl" "foo" {
185
226
name = "%s"
@@ -209,6 +250,7 @@ resource "fastly_service_vcl" "foo" {
209
250
}
210
251
211
252
request_setting {
253
+ action = "%s"
212
254
default_host = "tftestingother.tftesting.net.s3-website-us-west-2.amazonaws.com"
213
255
name = "alt_backend"
214
256
request_condition = "serve_alt_backend"
@@ -218,5 +260,5 @@ resource "fastly_service_vcl" "foo" {
218
260
default_host = "tftesting.tftesting.net.s3-website-us-west-2.amazonaws.com"
219
261
220
262
force_destroy = true
221
- }` , name , domain , maxStaleAge )
263
+ }` , name , domain , action , maxStaleAge )
222
264
}
0 commit comments