Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/cloudflare_page_rule: Remove HasChange for edge_cache_ttl #453

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions cloudflare/resource_cloudflare_page_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,6 @@ func transformToCloudflarePageRuleAction(id string, value interface{}, d *schema

pageRuleAction.ID = id

changed := d.HasChange(fmt.Sprintf("actions.0.%s", id))

if strValue, ok := value.(string); ok {
if id == "browser_cache_ttl" {
intValue, err := strconv.Atoi(strValue)
Expand All @@ -621,7 +619,7 @@ func transformToCloudflarePageRuleAction(id string, value interface{}, d *schema
}
}
} else if intValue, ok := value.(int); ok {
if id == "edge_cache_ttl" && intValue > 0 && changed {
if id == "edge_cache_ttl" && intValue > 0 {
pageRuleAction.Value = intValue
} else {
pageRuleAction.Value = nil
Expand Down
53 changes: 53 additions & 0 deletions cloudflare/resource_cloudflare_page_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,34 @@ func TestAccCloudflarePageRule_DeletesBrowserCacheTTLThatRespectsExistingHeaders
})
}

func TestAccCloudflarePageRuleEdgeCacheTTLNotClobbered(t *testing.T) {
var before, after cloudflare.PageRule
zone := os.Getenv("CLOUDFLARE_DOMAIN")
target := fmt.Sprintf("test-edge-cache-ttl-not-clobbered.%s", zone)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudflarePageRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckCloudflarePageRuleConfigWithEdgeCacheTtl(zone, target),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflarePageRuleExists("cloudflare_page_rule.test", &before),
resource.TestCheckResourceAttr("cloudflare_page_rule.test", "actions.0.edge_cache_ttl", "10"),
),
},
{
Config: testAccCheckCloudflarePageRuleConfigWithEdgeCacheTtlAndAlwaysOnline(zone, target),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflarePageRuleExists("cloudflare_page_rule.test", &after),
resource.TestCheckResourceAttr("cloudflare_page_rule.test", "actions.0.edge_cache_ttl", "10"),
),
},
},
})
}

func testAccCheckCloudflarePageRuleRecreated(before, after *cloudflare.PageRule) resource.TestCheckFunc {
return func(s *terraform.State) error {
if before.ID == after.ID {
Expand Down Expand Up @@ -603,6 +631,31 @@ resource "cloudflare_page_rule" "test" {
}`, zone, target)
}

func testAccCheckCloudflarePageRuleConfigWithEdgeCacheTtl(zone, target string) string {
return fmt.Sprintf(`
resource "cloudflare_page_rule" "test" {
zone = "%s"
target = "%s"
actions {
always_online = "on"
ssl = "flexible"
edge_cache_ttl = 10
}
}`, zone, target)
}

func testAccCheckCloudflarePageRuleConfigWithEdgeCacheTtlAndAlwaysOnline(zone, target string) string {
return fmt.Sprintf(`
resource "cloudflare_page_rule" "test" {
zone = "%s"
target = "%s"
actions {
always_online = "on"
edge_cache_ttl = 10
}
}`, zone, target)
}

func buildPageRuleConfig(resourceName string, actions string) string {
zone := os.Getenv("CLOUDFLARE_DOMAIN")
target := fmt.Sprintf("terraform-test.%s", zone)
Expand Down