Skip to content

Commit 046ff80

Browse files
Ensure that mode updates are always sent when ddos_protection is enabled (#1149)
1 parent 9078660 commit 046ff80

File tree

3 files changed

+92
-9
lines changed

3 files changed

+92
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- fix(header): preserve optional bool field `ignore_if_set` during updates and add acceptance test coverage ([#1142](https://github.com/fastly/terraform-provider-fastly/pull/1142))
1212
- fix(image_optimizer_default_settings): preserve optional bool fields (`allow_video`, `webp`, `upscale`) during updates and add acceptance test coverage ([#1145](https://github.com/fastly/terraform-provider-fastly/pull/1145))
1313
- fix(logging_kafka): preserve optional bool fields (`use_tls`, `parse_log_keyvals`) during updates and add acceptance test coverage ([#1147](https://github.com/fastly/terraform-provider-fastly/pull/1147))
14+
- fix(product_enablement): ensure `ddos_protection` mode updates are applied ([#1149](https://github.com/fastly/terraform-provider-fastly/pull/1149))
1415

1516
### DEPENDENCIES:
1617

fastly/block_fastly_service_product_enablement.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -607,16 +607,14 @@ func (h *ProductEnablementServiceAttributeHandler) Update(ctx context.Context, d
607607
return fmt.Errorf("failed to enable ddos_protection: %w", err)
608608
}
609609

610-
// The operation mode is set by default to "log"
611610
mode := ddp[0].(map[string]any)["mode"].(string)
612-
if mode != "log" {
613-
log.Println("[DEBUG] ddos_protection mode will be updated")
614-
_, err := ddosprotection.UpdateConfiguration(gofastly.NewContextForResourceID(ctx, d.Id()), conn, serviceID, ddosprotection.ConfigureInput{
615-
Mode: mode,
616-
})
617-
if err != nil {
618-
return fmt.Errorf("failed to set the configuration of ddos_protection: %w", err)
619-
}
611+
log.Printf("[DEBUG] ddos_protection mode will be set to %s", mode)
612+
_, err = ddosprotection.UpdateConfiguration(
613+
gofastly.NewContextForResourceID(ctx, d.Id()), conn, serviceID,
614+
ddosprotection.ConfigureInput{Mode: mode},
615+
)
616+
if err != nil {
617+
return fmt.Errorf("failed to set the configuration of ddos_protection: %w", err)
620618
}
621619
} else {
622620
log.Println("[DEBUG] ddos_protection will be disabled")

fastly/block_fastly_service_product_enablement_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,87 @@ func TestAccFastlyServiceVCLProductEnablement_basic(t *testing.T) {
105105
},
106106
})
107107
}
108+
109+
func TestAccFastlyServiceVCLProductEnablement_ddosProtectionModeChange(t *testing.T) {
110+
var service gofastly.ServiceDetail
111+
serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
112+
domainName := fmt.Sprintf("fastly-test.tf-%s.com", acctest.RandString(10))
113+
backendName := fmt.Sprintf("backend-tf-%s", acctest.RandString(10))
114+
backendAddress := "httpbin.org"
115+
116+
initialConfig := fmt.Sprintf(`
117+
resource "fastly_service_vcl" "foo" {
118+
name = "%s"
119+
120+
domain {
121+
name = "%s"
122+
comment = "demo"
123+
}
124+
125+
backend {
126+
address = "%s"
127+
name = "%s"
128+
port = 443
129+
shield = "amsterdam-nl"
130+
}
131+
132+
product_enablement {
133+
ddos_protection {
134+
enabled = true
135+
mode = "block"
136+
}
137+
}
138+
139+
force_destroy = true
140+
}
141+
`, serviceName, domainName, backendAddress, backendName)
142+
143+
updatedConfig := fmt.Sprintf(`
144+
resource "fastly_service_vcl" "foo" {
145+
name = "%s"
146+
147+
domain {
148+
name = "%s"
149+
comment = "demo"
150+
}
151+
152+
backend {
153+
address = "%s"
154+
name = "%s"
155+
port = 443
156+
shield = "amsterdam-nl"
157+
}
158+
159+
product_enablement {
160+
ddos_protection {
161+
enabled = true
162+
mode = "log"
163+
}
164+
}
165+
166+
force_destroy = true
167+
}
168+
`, serviceName, domainName, backendAddress, backendName)
169+
170+
resource.ParallelTest(t, resource.TestCase{
171+
PreCheck: func() { testAccPreCheck(t) },
172+
ProviderFactories: testAccProviders,
173+
CheckDestroy: testAccCheckServiceVCLDestroy,
174+
Steps: []resource.TestStep{
175+
{
176+
Config: initialConfig,
177+
Check: resource.ComposeTestCheckFunc(
178+
testAccCheckServiceExists("fastly_service_vcl.foo", &service),
179+
resource.TestCheckResourceAttr("fastly_service_vcl.foo", "product_enablement.0.ddos_protection.0.mode", "block"),
180+
),
181+
},
182+
{
183+
Config: updatedConfig,
184+
Check: resource.ComposeTestCheckFunc(
185+
testAccCheckServiceExists("fastly_service_vcl.foo", &service),
186+
resource.TestCheckResourceAttr("fastly_service_vcl.foo", "product_enablement.0.ddos_protection.0.mode", "log"),
187+
),
188+
},
189+
},
190+
})
191+
}

0 commit comments

Comments
 (0)