From 53253f0da83411562838f043c02618fb456d123e Mon Sep 17 00:00:00 2001 From: Steve Hodgkiss Date: Mon, 24 Jun 2019 15:45:16 +0400 Subject: [PATCH] Convert browser_cache_ttl to integer regardless of whether it's changed There's an issue where changing an unrelated value will result in the value being sent to CloudFlare as a string rather than an integer. --- cloudflare/resource_cloudflare_page_rule.go | 2 +- .../resource_cloudflare_page_rule_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cloudflare/resource_cloudflare_page_rule.go b/cloudflare/resource_cloudflare_page_rule.go index 774c09cef2..4e91409909 100644 --- a/cloudflare/resource_cloudflare_page_rule.go +++ b/cloudflare/resource_cloudflare_page_rule.go @@ -595,7 +595,7 @@ func transformToCloudflarePageRuleAction(id string, value interface{}, d *schema changed := d.HasChange(fmt.Sprintf("actions.0.%s", id)) if strValue, ok := value.(string); ok { - if id == "browser_cache_ttl" && changed { + if id == "browser_cache_ttl" { intValue, err := strconv.Atoi(strValue) if err == nil { pageRuleAction.Value = intValue diff --git a/cloudflare/resource_cloudflare_page_rule_test.go b/cloudflare/resource_cloudflare_page_rule_test.go index a17e52cb6f..7f9f3a2f81 100644 --- a/cloudflare/resource_cloudflare_page_rule_test.go +++ b/cloudflare/resource_cloudflare_page_rule_test.go @@ -297,6 +297,24 @@ func TestAccCloudflarePageRule_CreatesBrowserCacheTTLThatRespectsExistingHeaders }) } +func TestAccCloudflarePageRule_UpdatesBrowserCacheTTLToSameValue(t *testing.T) { + var pageRule cloudflare.PageRule + testAccRunResourceTestSteps(t, []resource.TestStep{ + { + Config: buildPageRuleConfig("test", "browser_cache_ttl = 1"), + }, + { + Config: buildPageRuleConfig("test", `browser_cache_ttl = 1 +browser_check = "on"`), + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudflarePageRuleExists("cloudflare_page_rule.test", &pageRule), + testAccCheckCloudflarePageRuleHasAction(&pageRule, "browser_cache_ttl", float64(1)), + resource.TestCheckResourceAttr("cloudflare_page_rule.test", "actions.0.browser_cache_ttl", "1"), + ), + }, + }) +} + func TestAccCloudflarePageRule_UpdatesBrowserCacheTTLThatRespectsExistingHeaders(t *testing.T) { var pageRule cloudflare.PageRule testAccRunResourceTestSteps(t, []resource.TestStep{