Skip to content

Commit

Permalink
Fix default values for redirect list updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
orium committed Jun 30, 2022
1 parent 82bff15 commit be5dd62
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/provider/resource_cloudflare_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ func buildListItemsCreateRequest(resource *schema.ResourceData, items []interfac
var preservePathSuffix *bool = nil

hasField := func(field string) bool {
_, has := resource.GetOkExists(fmt.Sprintf("item.%d.value.0.redirect.0.%s", i, field))
return has
v := getRawValue(fmt.Sprintf("item.%d.value.0.redirect.0.%s", i, field), resource.GetRawConfig())
return !v.IsNull()
}

if hasField("include_subdomains") {
Expand Down
39 changes: 37 additions & 2 deletions internal/provider/resource_cloudflare_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ func TestAccCloudflareList_Update(t *testing.T) {
resource.TestCheckResourceAttr(nameRedirect, "item.#", "2"),
),
},
{
PreConfig: func() {
initialID = list.ID
},
Config: testAccCheckCloudflareListRedirectUpdateTargetUrl(rndRedirect, rndRedirect, rndRedirect, accountID),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflareListExists(nameRedirect, &list),
func(state *terraform.State) error {
if initialID != list.ID {
return fmt.Errorf("wanted update but List got recreated (id changed %q -> %q)", initialID, list.ID)
}
return nil
},
resource.TestCheckResourceAttr(nameRedirect, "item.#", "2"),
),
},
},
})
}
Expand Down Expand Up @@ -252,8 +268,8 @@ func testAccCheckCloudflareListRedirectUpdate(ID, name, description, accountID s
redirect {
source_url = "cloudflare.com/blog"
target_url = "https://blog.cloudflare.com"
}
}
}
}
comment = "one"
}
Expand All @@ -273,3 +289,22 @@ func testAccCheckCloudflareListRedirectUpdate(ID, name, description, accountID s
}
}`, ID, name, description, accountID)
}

func testAccCheckCloudflareListRedirectUpdateTargetUrl(ID, name, description, accountID string) string {
return fmt.Sprintf(`
resource "cloudflare_list" "%[1]s" {
account_id = "%[4]s"
name = "%[2]s"
description = "%[3]s"
kind = "redirect"
item {
value {
redirect {
source_url = "cloudflare.com/blog"
target_url = "https://theblog.cloudflare.com"
}
}
}
}`, ID, name, description, accountID)
}

0 comments on commit be5dd62

Please sign in to comment.