Skip to content

Commit

Permalink
Merge pull request #1515 from kireledan/kireledan/1500-spectrum-fix
Browse files Browse the repository at this point in the history
Fix 'edge_ip_connectivity' state persistence
  • Loading branch information
jacobbednarz authored Mar 21, 2022
2 parents 9246df1 + 0a7cf6a commit 45e1431
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/1515.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_spectrum_application: Fix 'edge_ip_connectivity' state persistence
```
3 changes: 3 additions & 0 deletions cloudflare/resource_cloudflare_spectrum_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions cloudflare/resource_cloudflare_spectrum_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions cloudflare/schema_cloudflare_spectrum_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 45e1431

Please sign in to comment.