@@ -80,6 +80,7 @@ func TestAccFastlyServiceVCLRequestSetting_basic(t *testing.T) {
8080 }
8181
8282 rq2 := gofastly.RequestSetting {
83+ Action : gofastly .ToPointer (gofastly .RequestSettingActionLookup ),
8384 DefaultHost : gofastly .ToPointer ("tftestingother.tftesting.net.s3-website-us-west-2.amazonaws.com" ),
8485 MaxStaleAge : gofastly .ToPointer (900 ),
8586 Name : gofastly .ToPointer ("alt_backend" ),
@@ -99,6 +100,31 @@ func TestAccFastlyServiceVCLRequestSetting_basic(t *testing.T) {
99100 HashKeys : gofastly .ToPointer ("" ),
100101 TimerSupport : gofastly .ToPointer (false ),
101102 }
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.
102128
103129 resource .ParallelTest (t , resource.TestCase {
104130 PreCheck : func () {
@@ -108,29 +134,44 @@ func TestAccFastlyServiceVCLRequestSetting_basic(t *testing.T) {
108134 CheckDestroy : testAccCheckServiceVCLDestroy ,
109135 Steps : []resource.TestStep {
110136 {
111- Config : testAccServiceVCLRequestSetting (name , domainName1 , "90" ),
137+ Config : testAccServiceVCLRequestSetting (name , domainName1 , createAction , "90" ),
112138 Check : resource .ComposeTestCheckFunc (
113139 testAccCheckServiceExists ("fastly_service_vcl.foo" , & service ),
114140 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+ }),
121148 ),
122149 },
123150 {
124- Config : testAccServiceVCLRequestSetting (name , domainName1 , "900" ),
151+ Config : testAccServiceVCLRequestSetting (name , domainName1 , updateAction1 , "900" ),
125152 Check : resource .ComposeTestCheckFunc (
126153 testAccCheckServiceExists ("fastly_service_vcl.foo" , & service ),
127154 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+ }),
134175 ),
135176 },
136177 },
@@ -179,7 +220,7 @@ func testAccCheckFastlyServiceVCLRequestSettingsAttributes(service *gofastly.Ser
179220 }
180221}
181222
182- func testAccServiceVCLRequestSetting (name , domain , maxStaleAge string ) string {
223+ func testAccServiceVCLRequestSetting (name , domain , action , maxStaleAge string ) string {
183224 return fmt .Sprintf (`
184225resource "fastly_service_vcl" "foo" {
185226 name = "%s"
@@ -209,6 +250,7 @@ resource "fastly_service_vcl" "foo" {
209250 }
210251
211252 request_setting {
253+ action = "%s"
212254 default_host = "tftestingother.tftesting.net.s3-website-us-west-2.amazonaws.com"
213255 name = "alt_backend"
214256 request_condition = "serve_alt_backend"
@@ -218,5 +260,5 @@ resource "fastly_service_vcl" "foo" {
218260 default_host = "tftesting.tftesting.net.s3-website-us-west-2.amazonaws.com"
219261
220262 force_destroy = true
221- }` , name , domain , maxStaleAge )
263+ }` , name , domain , action , maxStaleAge )
222264}
0 commit comments