From 9669bf92151686ff2698b01bd04263eff5ee25bd Mon Sep 17 00:00:00 2001 From: Michele Russo Date: Tue, 10 Dec 2024 10:27:05 +0100 Subject: [PATCH 1/3] Fix update method --- .../service/leaked_credential_check_rule/resource.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/framework/service/leaked_credential_check_rule/resource.go b/internal/framework/service/leaked_credential_check_rule/resource.go index 454fc00701..1e90cf7625 100644 --- a/internal/framework/service/leaked_credential_check_rule/resource.go +++ b/internal/framework/service/leaked_credential_check_rule/resource.go @@ -113,6 +113,14 @@ func (r *LeakedCredentialCheckRuleResource) Update(ctx context.Context, req reso if resp.Diagnostics.HasError() { return } + var state LeakedCredentialCheckRulesModel + diags = req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + data.ID = state.ID + zoneID := cloudflare.ZoneIdentifier(data.ZoneID.ValueString()) _, err := r.client.V1.LeakedCredentialCheckUpdateDetection(ctx, zoneID, cloudflare.LeakedCredentialCheckUpdateDetectionParams{ LeakedCredentialCheckDetectionEntry: cloudflare.LeakedCredentialCheckDetectionEntry{ From 4595f238114d802563ef2d6b63855c1a6569d046 Mon Sep 17 00:00:00 2001 From: Michele Russo Date: Tue, 10 Dec 2024 10:27:23 +0100 Subject: [PATCH 2/3] Expand acceptance test --- .../resource_test.go | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/internal/framework/service/leaked_credential_check_rule/resource_test.go b/internal/framework/service/leaked_credential_check_rule/resource_test.go index 62714a892d..14643192bf 100644 --- a/internal/framework/service/leaked_credential_check_rule/resource_test.go +++ b/internal/framework/service/leaked_credential_check_rule/resource_test.go @@ -46,7 +46,7 @@ func testSweepCloudflareLCCRules(r string) error { tflog.Error(ctx, fmt.Sprintf("Error deleting a user-defined detection patter for Leaked Credential Check: %s", err)) } } - + return nil } @@ -68,6 +68,18 @@ func TestAccCloudflareLeakedCredentialCheckRule_Basic(t *testing.T) { resource.TestCheckResourceAttr(name+"_first", "username", "lookup_json_string(http.request.body.raw, \"user\")"), resource.TestCheckResourceAttr(name+"_first", "password", "lookup_json_string(http.request.body.raw, \"pass\")"), + resource.TestCheckResourceAttr(name+"_second", "zone_id", zoneID), + resource.TestCheckResourceAttr(name+"_second", "username", "lookup_json_string(http.request.body.raw, \"id\")"), + resource.TestCheckResourceAttr(name+"_second", "password", "lookup_json_string(http.request.body.raw, \"secret\")"), + ), + }, + { + Config: testAccConfigAddHeader(rnd, zoneID, testAccLCCUpdateOneRule(rnd)), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(name+"_first", "zone_id", zoneID), + resource.TestCheckResourceAttr(name+"_first", "username", "lookup_json_string(http.request.body.raw, \"username\")"), + resource.TestCheckResourceAttr(name+"_first", "password", "lookup_json_string(http.request.body.raw, \"password\")"), + resource.TestCheckResourceAttr(name+"_second", "zone_id", zoneID), resource.TestCheckResourceAttr(name+"_second", "username", "lookup_json_string(http.request.body.raw, \"id\")"), resource.TestCheckResourceAttr(name+"_second", "password", "lookup_json_string(http.request.body.raw, \"secret\")"), @@ -100,3 +112,18 @@ func testAccLCCTwoSimpleRules(name string) string { password = "lookup_json_string(http.request.body.raw, \"secret\")" }`, name) } + +func testAccLCCUpdateOneRule(name string) string { + return fmt.Sprintf(` + resource "cloudflare_leaked_credential_check_rule" "%[1]s_first" { + zone_id = cloudflare_leaked_credential_check.%[1]s.zone_id + username = "lookup_json_string(http.request.body.raw, \"username\")" + password = "lookup_json_string(http.request.body.raw, \"password\")" + } + + resource "cloudflare_leaked_credential_check_rule" "%[1]s_second" { + zone_id = cloudflare_leaked_credential_check.%[1]s.zone_id + username = "lookup_json_string(http.request.body.raw, \"id\")" + password = "lookup_json_string(http.request.body.raw, \"secret\")" + }`, name) +} From 01883bcb5fd36123375d8ec574c8ed84e1d6e24e Mon Sep 17 00:00:00 2001 From: Michele Russo Date: Tue, 10 Dec 2024 10:36:57 +0100 Subject: [PATCH 3/3] Add changelog --- .changelog/4741.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/4741.txt diff --git a/.changelog/4741.txt b/.changelog/4741.txt new file mode 100644 index 0000000000..4c9de3b447 --- /dev/null +++ b/.changelog/4741.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/cloudflare_leaked_credential_check_rule: Fix bug in update method +``` \ No newline at end of file