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

Allow full deletion of pop_pools, country_pools, region_pools on load balancer updates #2673

Merged
merged 1 commit into from
Aug 9, 2023
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
3 changes: 3 additions & 0 deletions .changelog/2673.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_load_balancer: fix full deletion of pop_pools, region_pools, country_pools on update
```
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,53 @@ func TestAccCloudflareLoadBalancer_RandomSteering(t *testing.T) {
})
}

func TestAccCloudflareLoadBalancer_GeoBalancedUpdate(t *testing.T) {
t.Parallel()
var loadBalancer cloudflare.LoadBalancer
zone := os.Getenv("CLOUDFLARE_DOMAIN")
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
name := "cloudflare_load_balancer." + rnd

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: testAccCheckCloudflareLoadBalancerDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckCloudflareLoadBalancerConfigGeoBalancedPoPCountry(zoneID, zone, rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflareLoadBalancerExists(name, &loadBalancer),
testAccCheckCloudflareLoadBalancerIDIsValid(name, zoneID),
// checking our overrides of default values worked
resource.TestCheckResourceAttr(name, "description", "tf-acctest load balancer using pop/country geo-balancing"),
resource.TestCheckResourceAttr(name, "proxied", "true"),
resource.TestCheckResourceAttr(name, "ttl", "0"),
resource.TestCheckResourceAttr(name, "steering_policy", "geo"),
resource.TestCheckResourceAttr(name, "pop_pools.#", "1"),
resource.TestCheckResourceAttr(name, "country_pools.#", "1"),
resource.TestCheckResourceAttr(name, "region_pools.#", "0"),
),
},
{
Config: testAccCheckCloudflareLoadBalancerConfigGeoBalancedPoPCountryToRegionUpdate(zoneID, zone, rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflareLoadBalancerExists(name, &loadBalancer),
testAccCheckCloudflareLoadBalancerIDIsValid(name, zoneID),
// checking our updates to geo steering with only a region defined worked
resource.TestCheckResourceAttr(name, "description", "tf-acctest load balancer using pop/country geo-balancing updated to region geo-balancing"),
resource.TestCheckResourceAttr(name, "proxied", "true"),
resource.TestCheckResourceAttr(name, "ttl", "0"),
resource.TestCheckResourceAttr(name, "steering_policy", "geo"),
resource.TestCheckResourceAttr(name, "pop_pools.#", "0"),
resource.TestCheckResourceAttr(name, "country_pools.#", "0"),
resource.TestCheckResourceAttr(name, "region_pools.#", "1"),
),
},
},
})
}

func TestAccCloudflareLoadBalancer_GeoBalanced(t *testing.T) {
t.Parallel()
var loadBalancer cloudflare.LoadBalancer
Expand Down Expand Up @@ -808,6 +855,44 @@ resource "cloudflare_load_balancer" "%[3]s" {
}`, zoneID, zone, id)
}

func testAccCheckCloudflareLoadBalancerConfigGeoBalancedPoPCountry(zoneID, zone, id string) string {
return testAccCheckCloudflareLoadBalancerPoolConfigBasic(id, accountID) + fmt.Sprintf(`
resource "cloudflare_load_balancer" "%[3]s" {
zone_id = "%[1]s"
name = "tf-testacc-lb-%[3]s.%[2]s"
fallback_pool_id = "${cloudflare_load_balancer_pool.%[3]s.id}"
default_pool_ids = ["${cloudflare_load_balancer_pool.%[3]s.id}"]
description = "tf-acctest load balancer using pop/country geo-balancing"
proxied = true
steering_policy = "geo"
pop_pools {
pop = "LAX"
pool_ids = ["${cloudflare_load_balancer_pool.%[3]s.id}"]
}
country_pools {
country = "US"
pool_ids = ["${cloudflare_load_balancer_pool.%[3]s.id}"]
}
}`, zoneID, zone, id)
}

func testAccCheckCloudflareLoadBalancerConfigGeoBalancedPoPCountryToRegionUpdate(zoneID, zone, id string) string {
return testAccCheckCloudflareLoadBalancerPoolConfigBasic(id, accountID) + fmt.Sprintf(`
resource "cloudflare_load_balancer" "%[3]s" {
zone_id = "%[1]s"
name = "tf-testacc-lb-%[3]s.%[2]s"
fallback_pool_id = "${cloudflare_load_balancer_pool.%[3]s.id}"
default_pool_ids = ["${cloudflare_load_balancer_pool.%[3]s.id}"]
description = "tf-acctest load balancer using pop/country geo-balancing updated to region geo-balancing"
proxied = true
steering_policy = "geo"
region_pools {
region = "WNAM"
pool_ids = ["${cloudflare_load_balancer_pool.%[3]s.id}"]
}
}`, zoneID, zone, id)
}

func testAccCheckCloudflareLoadBalancerConfigProximityBalanced(zoneID, zone, id string) string {
return testAccCheckCloudflareLoadBalancerPoolConfigBasic(id, accountID) + fmt.Sprintf(`
resource "cloudflare_load_balancer" "%[3]s" {
Expand Down
3 changes: 0 additions & 3 deletions internal/sdkv2provider/schema_cloudflare_load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,23 +653,20 @@ func resourceCloudflareLoadBalancerSchema() map[string]*schema.Schema {
"pop_pools": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: loadBalancerPopPoolElem,
Description: "A set containing mappings of Cloudflare Point-of-Presence (PoP) identifiers to a list of pool IDs (ordered by their failover priority) for the PoP (datacenter). This feature is only available to enterprise customers.",
},

"country_pools": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: loadBalancerCountryPoolElem,
Description: "A set containing mappings of country codes to a list of pool IDs (ordered by their failover priority) for the given country.",
},

"region_pools": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: loadBalancerRegionPoolElem,
Description: "A set containing mappings of region codes to a list of pool IDs (ordered by their failover priority) for the given region.",
},
Expand Down