From 23739cdc54c871701c64f2b7dbb3678b48434a52 Mon Sep 17 00:00:00 2001 From: Erik Nadel Date: Wed, 16 Mar 2022 20:59:31 -0500 Subject: [PATCH 1/3] Fix 'edge_ip_connectivity' state persistence --- .changelog/1500.txt | 3 +++ cloudflare/resource_cloudflare_spectrum_application.go | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 .changelog/1500.txt diff --git a/.changelog/1500.txt b/.changelog/1500.txt new file mode 100644 index 0000000000..3a754a575d --- /dev/null +++ b/.changelog/1500.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/cloudflare_spectrum_application: Fix 'edge_ip_connectivity' state persistence +``` diff --git a/cloudflare/resource_cloudflare_spectrum_application.go b/cloudflare/resource_cloudflare_spectrum_application.go index ff7de06ab1..3ab19c00b5 100644 --- a/cloudflare/resource_cloudflare_spectrum_application.go +++ b/cloudflare/resource_cloudflare_spectrum_application.go @@ -113,6 +113,9 @@ func resourceCloudflareSpectrumApplicationRead(d *schema.ResourceData, meta inte if err := d.Set("edge_ips", flattenEdgeIPs(application.EdgeIPs)); err != nil { log.Printf("[WARN] Error setting Edge IPs on spectrum application %q: %s", d.Id(), err) } + if err := d.Set("edge_ip_connectivity", application.EdgeIPs.Connectivity); err != nil { + log.Printf("[WARN] Error setting Edge IP connectivity on spectrum application %q: %s", d.Id(), err) + } } d.Set("tls", application.TLS) From 483c8bf7f4f8e118401789b543f5f16eb9dd1389 Mon Sep 17 00:00:00 2001 From: Erik Nadel Date: Mon, 21 Mar 2022 13:09:34 -0500 Subject: [PATCH 2/3] Fix changelog text and add edge_ip_connectivity test --- .changelog/{1500.txt => 1515.txt} | 0 ...ce_cloudflare_spectrum_application_test.go | 41 +++++++++++++++++++ 2 files changed, 41 insertions(+) rename .changelog/{1500.txt => 1515.txt} (100%) diff --git a/.changelog/1500.txt b/.changelog/1515.txt similarity index 100% rename from .changelog/1500.txt rename to .changelog/1515.txt diff --git a/cloudflare/resource_cloudflare_spectrum_application_test.go b/cloudflare/resource_cloudflare_spectrum_application_test.go index 1e3b70fd28..8ac1ca7b5e 100644 --- a/cloudflare/resource_cloudflare_spectrum_application_test.go +++ b/cloudflare/resource_cloudflare_spectrum_application_test.go @@ -240,6 +240,29 @@ func testAccCheckCloudflareSpectrumApplicationDestroy(s *terraform.State) error return nil } +func TestAccCloudflareSpectrumApplication_EdgeIPConnectivity(t *testing.T) { + var spectrumApp cloudflare.SpectrumApplication + domain := os.Getenv("CLOUDFLARE_DOMAIN") + zoneID := os.Getenv("CLOUDFLARE_ZONE_ID") + rnd := generateRandomResourceName() + name := "cloudflare_spectrum_application." + rnd + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckCloudflareSpectrumApplicationConfigEdgeIPConnectivity(zoneID, domain, rnd), + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudflareSpectrumApplicationExists(name, &spectrumApp), + testAccCheckCloudflareSpectrumApplicationIDIsValid(name), + resource.TestCheckResourceAttr(name, "edge_ip_connectivity", "ipv4"), + ), + }, + }, + }) +} + func testAccCheckCloudflareSpectrumApplicationExists(n string, spectrumApp *cloudflare.SpectrumApplication) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -369,3 +392,21 @@ resource "cloudflare_spectrum_application" "%[3]s" { origin_port = 22 }`, zoneID, zoneName, ID) } + +func testAccCheckCloudflareSpectrumApplicationConfigEdgeIPConnectivity(zoneID, zoneName, ID string) string { + return fmt.Sprintf(` +resource "cloudflare_spectrum_application" "%[3]s" { + zone_id = "%[1]s" + protocol = "tcp/22" + + dns { + type = "CNAME" + name = "%[3]s.%[2]s" + } + + origin_dns { + name = "%[3]s.origin.%[2]s" + } + edge_ip_connectivity = "ipv4" +}`, zoneID, zoneName, ID) +} From 0a7cf6aa4874b12d88c7fda190c83e7381635d31 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Tue, 22 Mar 2022 09:38:58 +1100 Subject: [PATCH 3/3] fix test and schema --- cloudflare/resource_cloudflare_spectrum_application.go | 2 +- cloudflare/resource_cloudflare_spectrum_application_test.go | 5 ++--- cloudflare/schema_cloudflare_spectrum_application.go | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cloudflare/resource_cloudflare_spectrum_application.go b/cloudflare/resource_cloudflare_spectrum_application.go index 3ab19c00b5..8eae7f5055 100644 --- a/cloudflare/resource_cloudflare_spectrum_application.go +++ b/cloudflare/resource_cloudflare_spectrum_application.go @@ -113,7 +113,7 @@ func resourceCloudflareSpectrumApplicationRead(d *schema.ResourceData, meta inte if err := d.Set("edge_ips", flattenEdgeIPs(application.EdgeIPs)); err != nil { log.Printf("[WARN] Error setting Edge IPs on spectrum application %q: %s", d.Id(), err) } - if err := d.Set("edge_ip_connectivity", application.EdgeIPs.Connectivity); err != nil { + if err := d.Set("edge_ip_connectivity", application.EdgeIPs.Connectivity.String()); err != nil { log.Printf("[WARN] Error setting Edge IP connectivity on spectrum application %q: %s", d.Id(), err) } } diff --git a/cloudflare/resource_cloudflare_spectrum_application_test.go b/cloudflare/resource_cloudflare_spectrum_application_test.go index 8ac1ca7b5e..b4c7a0c7d4 100644 --- a/cloudflare/resource_cloudflare_spectrum_application_test.go +++ b/cloudflare/resource_cloudflare_spectrum_application_test.go @@ -404,9 +404,8 @@ resource "cloudflare_spectrum_application" "%[3]s" { name = "%[3]s.%[2]s" } - origin_dns { - name = "%[3]s.origin.%[2]s" - } + origin_direct = ["tcp://1.2.3.4:23"] + origin_port = 22 edge_ip_connectivity = "ipv4" }`, zoneID, zoneName, ID) } diff --git a/cloudflare/schema_cloudflare_spectrum_application.go b/cloudflare/schema_cloudflare_spectrum_application.go index d16f9fa763..a77e16e468 100644 --- a/cloudflare/schema_cloudflare_spectrum_application.go +++ b/cloudflare/schema_cloudflare_spectrum_application.go @@ -125,6 +125,7 @@ func resourceCloudflareSpectrumApplicationSchema() map[string]*schema.Schema { "edge_ip_connectivity": { Type: schema.TypeString, Optional: true, + Computed: true, ValidateFunc: validation.StringInSlice([]string{ "all", "ipv4", "ipv6", }, false),