From 4e26b6c74d67336c42038b0a7bfe40dbf7c4da77 Mon Sep 17 00:00:00 2001 From: JJ Graham Date: Tue, 8 Aug 2023 18:55:42 -0500 Subject: [PATCH] Allow full deletion of pop_pools, country_pools, region_pools on load balancer updates --- .changelog/2673.txt | 3 + .../resource_cloudflare_load_balancer_test.go | 85 +++++++++++++++++++ .../schema_cloudflare_load_balancer.go | 3 - 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 .changelog/2673.txt diff --git a/.changelog/2673.txt b/.changelog/2673.txt new file mode 100644 index 0000000000..5d7382fa5f --- /dev/null +++ b/.changelog/2673.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/cloudflare_load_balancer: fix full deletion of pop_pools, region_pools, country_pools on update +``` diff --git a/internal/sdkv2provider/resource_cloudflare_load_balancer_test.go b/internal/sdkv2provider/resource_cloudflare_load_balancer_test.go index f043d7483d..f7483d9d94 100644 --- a/internal/sdkv2provider/resource_cloudflare_load_balancer_test.go +++ b/internal/sdkv2provider/resource_cloudflare_load_balancer_test.go @@ -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 @@ -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" { diff --git a/internal/sdkv2provider/schema_cloudflare_load_balancer.go b/internal/sdkv2provider/schema_cloudflare_load_balancer.go index aef5be6aaa..a1f8f3019b 100644 --- a/internal/sdkv2provider/schema_cloudflare_load_balancer.go +++ b/internal/sdkv2provider/schema_cloudflare_load_balancer.go @@ -653,7 +653,6 @@ 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.", }, @@ -661,7 +660,6 @@ func resourceCloudflareLoadBalancerSchema() map[string]*schema.Schema { "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.", }, @@ -669,7 +667,6 @@ func resourceCloudflareLoadBalancerSchema() map[string]*schema.Schema { "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.", },