From 2dc7cae3206941e579ffe2b6deab47948ba53f93 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Mon, 24 Jan 2022 11:51:41 +1100 Subject: [PATCH] resource/cloudflare_ruleset: Yet Another tristate bool fix Updates the check for whether or not to populate the `enabled` flag on category/rule based overrides to use the `GetOkExists` method (not recommended due to undocumented edge cases) to check the existence before converting the pointer to a value. Closes #1403 --- cloudflare/resource_cloudflare_ruleset.go | 2 +- cloudflare/resource_cloudflare_ruleset_test.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cloudflare/resource_cloudflare_ruleset.go b/cloudflare/resource_cloudflare_ruleset.go index 2b952cba3ab..94a26721245 100644 --- a/cloudflare/resource_cloudflare_ruleset.go +++ b/cloudflare/resource_cloudflare_ruleset.go @@ -447,7 +447,7 @@ func buildRulesetRulesFromResource(d *schema.ResourceData) ([]cloudflare.Ruleset rData := rule.(map[string]interface{}) var enabled *bool - if value, ok := d.GetOk(fmt.Sprintf("rules.%d.action_parameters.0.overrides.%d.rules.%d.enabled", rulesCounter, overrideCounter, ruleOverrideCounter)); ok { + if value, ok := d.GetOkExists(fmt.Sprintf("rules.%d.action_parameters.0.overrides.%d.rules.%d.enabled", rulesCounter, overrideCounter, ruleOverrideCounter)); ok { enabled = &[]bool{value.(bool)}[0] } diff --git a/cloudflare/resource_cloudflare_ruleset_test.go b/cloudflare/resource_cloudflare_ruleset_test.go index 36fb5a8db99..eec4cf12ba4 100644 --- a/cloudflare/resource_cloudflare_ruleset_test.go +++ b/cloudflare/resource_cloudflare_ruleset_test.go @@ -475,7 +475,7 @@ func TestAccCloudflareRuleset_WAFManagedRulesetDeployMultipleWithTopSkipAndLastS }) } -func TestAccCloudflareRuleset_WAFManagedRulesetWithCategoryBasedOverrides(t *testing.T) { +func TestAccCloudflareRuleset_WAFManagedRulesetWithCategoryAndRuleBasedOverrides(t *testing.T) { // Temporarily unset CLOUDFLARE_API_TOKEN if it is set as the WAF // service does not yet support the API tokens and it results in // misleading state error messages. @@ -517,6 +517,10 @@ func TestAccCloudflareRuleset_WAFManagedRulesetWithCategoryBasedOverrides(t *tes resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.overrides.0.categories.0.action", "block"), resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.overrides.0.categories.1.category", "joomla"), resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.overrides.0.categories.1.action", "block"), + + resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.overrides.0.rules.#", "1"), + resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.overrides.0.rules.0.id", "e3a567afc347477d9702d9047e97d760"), + resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.overrides.0.rules.0.enabled", "false"), ), }, }, @@ -1598,6 +1602,11 @@ func testAccCheckCloudflareRulesetManagedWAFWithCategoryBasedOverrides(rnd, name action = "block" enabled = true } + + rules { + id = "e3a567afc347477d9702d9047e97d760" + enabled = false + } } }