From b541715db094635709fe00692c5a1855b21cc2c5 Mon Sep 17 00:00:00 2001 From: Nikolai Mishin Date: Sun, 17 Dec 2023 21:26:57 +0100 Subject: [PATCH 1/2] Fix behaviour of block_page_enabled block --- .changelog/3010.txt | 4 ++++ internal/sdkv2provider/resource_cloudflare_teams_rules.go | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 .changelog/3010.txt diff --git a/.changelog/3010.txt b/.changelog/3010.txt new file mode 100644 index 0000000000..649162c4e8 --- /dev/null +++ b/.changelog/3010.txt @@ -0,0 +1,4 @@ +```release-note:bug +resource/cloudflare_teams_rules: fix block_page_enabled behaviour +``` + diff --git a/internal/sdkv2provider/resource_cloudflare_teams_rules.go b/internal/sdkv2provider/resource_cloudflare_teams_rules.go index 3ad813fccf..ac9999b20f 100644 --- a/internal/sdkv2provider/resource_cloudflare_teams_rules.go +++ b/internal/sdkv2provider/resource_cloudflare_teams_rules.go @@ -74,7 +74,7 @@ func resourceCloudflareTeamsRuleRead(ctx context.Context, d *schema.ResourceData return diag.FromErr(fmt.Errorf("error parsing rule version")) } - if err := d.Set("rule_settings", flattenTeamsRuleSettings(&rule.RuleSettings)); err != nil { + if err := d.Set("rule_settings", flattenTeamsRuleSettings(d, &rule.RuleSettings)); err != nil { return diag.FromErr(fmt.Errorf("error parsing rule settings")) } @@ -197,15 +197,15 @@ func resourceCloudflareTeamsRuleImport(ctx context.Context, d *schema.ResourceDa return []*schema.ResourceData{d}, nil } -func flattenTeamsRuleSettings(settings *cloudflare.TeamsRuleSettings) []interface{} { - if len(settings.OverrideIPs) == 0 && +func flattenTeamsRuleSettings(d *schema.ResourceData, settings *cloudflare.TeamsRuleSettings) []interface{} { + if _, ok := d.GetOkExists("block_page_enabled"); ok && + len(settings.OverrideIPs) == 0 && settings.BlockReason == "" && settings.OverrideHost == "" && settings.BISOAdminControls == nil && settings.L4Override == nil && len(settings.AddHeaders) == 0 && settings.CheckSession == nil && - settings.BlockPageEnabled == false && settings.InsecureDisableDNSSECValidation == false && settings.EgressSettings == nil && settings.UntrustedCertSettings == nil && From 8c73c18db9e206ada179376bdcade833a38cdaf4 Mon Sep 17 00:00:00 2001 From: Nikolai Mishin Date: Thu, 21 Dec 2023 23:36:07 +0100 Subject: [PATCH 2/2] Add fix and update tests --- internal/sdkv2provider/resource_cloudflare_teams_rules.go | 2 +- .../sdkv2provider/resource_cloudflare_teams_rules_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/sdkv2provider/resource_cloudflare_teams_rules.go b/internal/sdkv2provider/resource_cloudflare_teams_rules.go index fc01e63737..96838939e3 100644 --- a/internal/sdkv2provider/resource_cloudflare_teams_rules.go +++ b/internal/sdkv2provider/resource_cloudflare_teams_rules.go @@ -198,7 +198,7 @@ func resourceCloudflareTeamsRuleImport(ctx context.Context, d *schema.ResourceDa } func flattenTeamsRuleSettings(d *schema.ResourceData, settings *cloudflare.TeamsRuleSettings) []interface{} { - if _, ok := d.GetOkExists("block_page_enabled"); ok && + if _, ok := d.GetOkExists("block_page_enabled"); !ok && len(settings.OverrideIPs) == 0 && settings.BlockReason == "" && settings.OverrideHost == "" && diff --git a/internal/sdkv2provider/resource_cloudflare_teams_rules_test.go b/internal/sdkv2provider/resource_cloudflare_teams_rules_test.go index 8217dc64e1..465376030b 100644 --- a/internal/sdkv2provider/resource_cloudflare_teams_rules_test.go +++ b/internal/sdkv2provider/resource_cloudflare_teams_rules_test.go @@ -42,7 +42,7 @@ func TestAccCloudflareTeamsRule_Basic(t *testing.T) { resource.TestCheckResourceAttr(name, "filters.0", "dns"), resource.TestCheckResourceAttr(name, "traffic", "any(dns.domains[*] == \"example.com\")"), resource.TestCheckResourceAttr(name, "rule_settings.#", "1"), - resource.TestCheckResourceAttr(name, "rule_settings.0.block_page_enabled", "false"), + resource.TestCheckResourceAttr(name, "rule_settings.0.block_page_enabled", "true"), resource.TestCheckResourceAttr(name, "rule_settings.0.block_page_reason", "cuz"), resource.TestCheckResourceAttr(name, "rule_settings.0.insecure_disable_dnssec_validation", "false"), resource.TestCheckResourceAttr(name, "rule_settings.0.egress.0.ipv4", "203.0.113.1"), @@ -66,7 +66,7 @@ resource "cloudflare_teams_rule" "%[1]s" { filters = ["dns"] traffic = "any(dns.domains[*] == \"example.com\")" rule_settings { - block_page_enabled = false + block_page_enabled = true block_page_reason = "cuz" insecure_disable_dnssec_validation = false egress {