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

Fix 'edge_ip_connectivity' state persistence #1515

Merged
merged 3 commits into from
Mar 21, 2022
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/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