diff --git a/.changelog/1515.txt b/.changelog/1515.txt new file mode 100644 index 0000000000..3a754a575d --- /dev/null +++ b/.changelog/1515.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..8eae7f5055 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.String()); err != nil { + log.Printf("[WARN] Error setting Edge IP connectivity on spectrum application %q: %s", d.Id(), err) + } } d.Set("tls", application.TLS) diff --git a/cloudflare/resource_cloudflare_spectrum_application_test.go b/cloudflare/resource_cloudflare_spectrum_application_test.go index 1e3b70fd28..b4c7a0c7d4 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,20 @@ 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_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),