Skip to content

Commit 29fdfdf

Browse files
[CDTOOL-1233] ensure proper optional bool behavior in request_setting (#1165)
1 parent 49b7f97 commit 29fdfdf

File tree

3 files changed

+98
-12
lines changed

3 files changed

+98
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
### ENHANCEMENTS:
66

77
### BUG FIXES:
8+
89
- fix(service/backend): corrected a drift issue caused by the `keepalive_time` attribute ([#1156](https://github.com/fastly/terraform-provider-fastly/pull/1156))
10+
- fix(request_setting): preserve optional bool fields (`force_miss`, `force_ssl`, `bypass_busy_wait`, `timer_support`) during updates and add acceptance test coverage ([#1165](https://github.com/fastly/terraform-provider-fastly/pull/1165))
911

1012
### DEPENDENCIES:
13+
1114
- build(deps): `actions/checkout` from 5 to 6 ([#1159](https://github.com/fastly/terraform-provider-fastly/pull/1159))
1215

1316
### DOCUMENTATION:
@@ -27,6 +30,7 @@
2730
- fix(product_enablement): ensure `ddos_protection` mode updates are applied ([#1149](https://github.com/fastly/terraform-provider-fastly/pull/1149))
2831

2932
### DEPENDENCIES:
33+
3034
- build(deps): `golangci/golangci-lint-action` from 8 to 9 ([#1144](https://github.com/fastly/terraform-provider-fastly/pull/1144))
3135
- build(deps): `golang.org/x/net` from 0.46.0 to 0.47.0 ([#1150](https://github.com/fastly/terraform-provider-fastly/pull/1150))
3236
- build(deps): `golangci/golangci-lint-action` from 8 to 9 ([#1144](https://github.com/fastly/terraform-provider-fastly/pull/1144))

fastly/block_fastly_service_requestsetting.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func (h *RequestSettingServiceAttributeHandler) GetSchema() *schema.Schema {
4646
"bypass_busy_wait": {
4747
Type: schema.TypeBool,
4848
Optional: true,
49+
Default: false,
4950
Description: "Disable collapsed forwarding, so you don't wait for other objects to origin",
5051
},
5152
"default_host": {
@@ -56,11 +57,13 @@ func (h *RequestSettingServiceAttributeHandler) GetSchema() *schema.Schema {
5657
"force_miss": {
5758
Type: schema.TypeBool,
5859
Optional: true,
60+
Default: false,
5961
Description: "Force a cache miss for the request. If specified, can be `true` or `false`",
6062
},
6163
"force_ssl": {
6264
Type: schema.TypeBool,
6365
Optional: true,
66+
Default: false,
6467
Description: "Forces the request to use SSL (Redirects a non-SSL request to SSL)",
6568
},
6669
"hash_keys": {
@@ -87,6 +90,7 @@ func (h *RequestSettingServiceAttributeHandler) GetSchema() *schema.Schema {
8790
"timer_support": {
8891
Type: schema.TypeBool,
8992
Optional: true,
93+
Default: false,
9094
Description: "Injects the X-Timer info into the request for viewing origin fetch durations",
9195
},
9296
"xff": {
@@ -145,12 +149,12 @@ func (h *RequestSettingServiceAttributeHandler) Update(ctx context.Context, d *s
145149
Name: resource["name"].(string),
146150
}
147151

148-
if v, ok := modified["force_miss"]; ok {
149-
opts.ForceMiss = gofastly.ToPointer(gofastly.Compatibool(v.(bool)))
150-
}
151-
if v, ok := modified["force_ssl"]; ok {
152-
opts.ForceSSL = gofastly.ToPointer(gofastly.Compatibool(v.(bool)))
153-
}
152+
// Always preserve optional boolean fields
153+
opts.ForceMiss = gofastly.ToPointer(gofastly.Compatibool(resource["force_miss"].(bool)))
154+
opts.ForceSSL = gofastly.ToPointer(gofastly.Compatibool(resource["force_ssl"].(bool)))
155+
opts.BypassBusyWait = gofastly.ToPointer(gofastly.Compatibool(resource["bypass_busy_wait"].(bool)))
156+
opts.TimerSupport = gofastly.ToPointer(gofastly.Compatibool(resource["timer_support"].(bool)))
157+
154158
if v, ok := modified["action"]; ok {
155159
switch strings.ToLower(v.(string)) {
156160
case "lookup":
@@ -161,9 +165,6 @@ func (h *RequestSettingServiceAttributeHandler) Update(ctx context.Context, d *s
161165
opts.Action = gofastly.ToPointer(gofastly.RequestSettingActionUnset)
162166
}
163167
}
164-
if v, ok := modified["bypass_busy_wait"]; ok {
165-
opts.BypassBusyWait = gofastly.ToPointer(gofastly.Compatibool(v.(bool)))
166-
}
167168
if v, ok := modified["max_stale_age"]; ok {
168169
opts.MaxStaleAge = gofastly.ToPointer(v.(int))
169170
}
@@ -184,9 +185,6 @@ func (h *RequestSettingServiceAttributeHandler) Update(ctx context.Context, d *s
184185
opts.XForwardedFor = gofastly.ToPointer(gofastly.RequestSettingXFFOverwrite)
185186
}
186187
}
187-
if v, ok := modified["timer_support"]; ok {
188-
opts.TimerSupport = gofastly.ToPointer(gofastly.Compatibool(v.(bool)))
189-
}
190188
if v, ok := modified["default_host"]; ok {
191189
opts.DefaultHost = gofastly.ToPointer(v.(string))
192190
}

fastly/block_fastly_service_requestsetting_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,61 @@ func TestAccFastlyServiceVCLRequestSetting_basic(t *testing.T) {
176176
})
177177
}
178178

179+
func TestAccFastlyServiceVCLRequestSetting_PreserveBooleansDuringUpdate(t *testing.T) {
180+
var service gofastly.ServiceDetail
181+
serviceName := acctest.RandomWithPrefix("tf-rs")
182+
domainName := fmt.Sprintf("test.%s.com", acctest.RandString(10))
183+
184+
rsName := "rs-update"
185+
186+
// Optional boolean values we want to preserve
187+
forceMiss := true
188+
forceSSL := false
189+
bypassBusyWait := true
190+
timerSupport := true
191+
192+
initialDefaultHost := "initial.example.com"
193+
updatedDefaultHost := "updated.example.com"
194+
195+
resource.ParallelTest(t, resource.TestCase{
196+
PreCheck: func() { testAccPreCheck(t) },
197+
ProviderFactories: testAccProviders,
198+
CheckDestroy: testAccCheckServiceVCLDestroy,
199+
Steps: []resource.TestStep{
200+
{
201+
Config: testAccServiceVCLRequestSettingWithBooleansAndHost(serviceName, domainName, rsName, initialDefaultHost, forceMiss, forceSSL, bypassBusyWait, timerSupport),
202+
Check: resource.ComposeTestCheckFunc(
203+
testAccCheckServiceExists("fastly_service_vcl.foo", &service),
204+
resource.TestCheckResourceAttr("fastly_service_vcl.foo", "request_setting.#", "1"),
205+
resource.TestCheckTypeSetElemNestedAttrs("fastly_service_vcl.foo", "request_setting.*", map[string]string{
206+
"name": rsName,
207+
"default_host": initialDefaultHost,
208+
"force_miss": fmt.Sprintf("%t", forceMiss),
209+
"force_ssl": fmt.Sprintf("%t", forceSSL),
210+
"bypass_busy_wait": fmt.Sprintf("%t", bypassBusyWait),
211+
"timer_support": fmt.Sprintf("%t", timerSupport),
212+
}),
213+
),
214+
},
215+
{
216+
Config: testAccServiceVCLRequestSettingWithBooleansAndHost(serviceName, domainName, rsName, updatedDefaultHost, forceMiss, forceSSL, bypassBusyWait, timerSupport),
217+
Check: resource.ComposeTestCheckFunc(
218+
testAccCheckServiceExists("fastly_service_vcl.foo", &service),
219+
resource.TestCheckResourceAttr("fastly_service_vcl.foo", "request_setting.#", "1"),
220+
resource.TestCheckTypeSetElemNestedAttrs("fastly_service_vcl.foo", "request_setting.*", map[string]string{
221+
"name": rsName,
222+
"default_host": updatedDefaultHost,
223+
"force_miss": fmt.Sprintf("%t", forceMiss),
224+
"force_ssl": fmt.Sprintf("%t", forceSSL),
225+
"bypass_busy_wait": fmt.Sprintf("%t", bypassBusyWait),
226+
"timer_support": fmt.Sprintf("%t", timerSupport),
227+
}),
228+
),
229+
},
230+
},
231+
})
232+
}
233+
179234
func testAccCheckFastlyServiceVCLRequestSettingsAttributes(service *gofastly.ServiceDetail, rqs []*gofastly.RequestSetting) resource.TestCheckFunc {
180235
return func(_ *terraform.State) error {
181236
conn := testAccProvider.Meta().(*APIClient).conn
@@ -261,3 +316,32 @@ resource "fastly_service_vcl" "foo" {
261316
force_destroy = true
262317
}`, name, domain, action, maxStaleAge)
263318
}
319+
320+
func testAccServiceVCLRequestSettingWithBooleansAndHost(serviceName, domainName, rsName, defaultHost string, forceMiss, forceSSL, bypassBusyWait, timerSupport bool) string {
321+
return fmt.Sprintf(`
322+
resource "fastly_service_vcl" "foo" {
323+
name = "%s"
324+
325+
domain {
326+
name = "%s"
327+
comment = "test domain"
328+
}
329+
330+
backend {
331+
address = "http-me.fastly.dev"
332+
name = "main-backend"
333+
port = 80
334+
}
335+
336+
request_setting {
337+
name = "%s"
338+
default_host = "%s"
339+
force_miss = %t
340+
force_ssl = %t
341+
bypass_busy_wait = %t
342+
timer_support = %t
343+
}
344+
345+
force_destroy = true
346+
}`, serviceName, domainName, rsName, defaultHost, forceMiss, forceSSL, bypassBusyWait, timerSupport)
347+
}

0 commit comments

Comments
 (0)