Skip to content

Commit

Permalink
Merge pull request #3010 from Nmishin/feat/2923
Browse files Browse the repository at this point in the history
Fix behaviour of block_page_enabled block
  • Loading branch information
jacobbednarz authored Dec 27, 2023
2 parents e830a26 + 8c73c18 commit fac8cbc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .changelog/3010.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
resource/cloudflare_teams_rules: fix block_page_enabled behaviour
```

8 changes: 4 additions & 4 deletions internal/sdkv2provider/resource_cloudflare_teams_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

Expand Down Expand Up @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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 {
Expand Down

0 comments on commit fac8cbc

Please sign in to comment.