Skip to content

Commit

Permalink
don't set connectivity for static types
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Feb 9, 2023
1 parent ff7b507 commit 1dca4b2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .changelog/2219.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ resource/cloudflare_spectrum_application: `edge_ips` now contains nested attribu
```

```release-note:breaking-change
resource/cloudflare_spectrum_application: `edge_ips.type` and `edge_ips.connectivity` are now required fields
resource/cloudflare_spectrum_application: `edge_ips.type` is now a required field
```
7 changes: 3 additions & 4 deletions docs/resources/spectrum_application.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ resource "cloudflare_spectrum_application" "example" {
]
edge_ips {
type = "static"
connectivity = "all"
ips = ["203.0.113.1", "203.0.113.2"]
type = "static"
ips = ["203.0.113.1", "203.0.113.2"]
}
}
```
Expand Down Expand Up @@ -77,11 +76,11 @@ Required:

Required:

- `connectivity` (String) The IP versions supported for inbound connections on Spectrum anycast IPs. Available values: `all`, `ipv4`, `ipv6`.
- `type` (String) The type of edge IP configuration specified. Available values: `dynamic`, `static`.

Optional:

- `connectivity` (String) The IP versions supported for inbound connections on Spectrum anycast IPs. Required when `type` is not `static`. Available values: `all`, `ipv4`, `ipv6`.
- `ips` (Set of String) The collection of customer owned IPs to broadcast via anycast for this hostname and application. Requires [Bring Your Own IP](https://developers.cloudflare.com/spectrum/getting-started/byoip/) provisioned.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ resource "cloudflare_spectrum_application" "example" {
]

edge_ips {
type = "static"
connectivity = "all"
ips = ["203.0.113.1", "203.0.113.2"]
type = "static"
ips = ["203.0.113.1", "203.0.113.2"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ func flattenEdgeIPs(edgeIPs *cloudflare.SpectrumApplicationEdgeIPs) []map[string

if edgeIPs.Connectivity != nil {
flattened["connectivity"] = edgeIPs.Connectivity.String()
} else {
flattened["connectivity"] = cloudflare.SpectrumConnectivityAll
}

ips := []string{}
Expand Down Expand Up @@ -284,8 +282,10 @@ func applicationFromResource(d *schema.ResourceData) cloudflare.SpectrumApplicat

application.EdgeIPs = &cloudflare.SpectrumApplicationEdgeIPs{}

c := edgeIPsConnectivityFromString(d.Get("edge_ips.0.connectivity").(string))
application.EdgeIPs.Connectivity = &c
if d.Get("edge_ips.0.connectivity").(string) != "" {
c := edgeIPsConnectivityFromString(d.Get("edge_ips.0.connectivity").(string))
application.EdgeIPs.Connectivity = &c
}

application.EdgeIPs.Type = edgeIPsTypeFromString(d.Get("edge_ips.0.type").(string))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,30 +237,6 @@ func TestAccCloudflareSpectrumApplication_EdgeIPConnectivity(t *testing.T) {
})
}

func TestAccCloudflareSpectrumApplication_EdgeIPsWithoutConnectivity(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) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccCheckCloudflareSpectrumApplicationConfigEdgeIPsWithoutConnectivity(zoneID, domain, rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflareSpectrumApplicationExists(name, &spectrumApp),
testAccCheckCloudflareSpectrumApplicationIDIsValid(name),
resource.TestCheckResourceAttr(name, "edge_ips.0.ips.#", "1"),
resource.TestCheckTypeSetElemAttr(name, "edge_ips.0.ips.*", "172.65.64.13"),
),
},
},
})
}

func TestAccCloudflareSpectrumApplication_EdgeIPsMultiple(t *testing.T) {
var spectrumApp cloudflare.SpectrumApplication
domain := os.Getenv("CLOUDFLARE_DOMAIN")
Expand Down Expand Up @@ -500,7 +476,6 @@ resource "cloudflare_spectrum_application" "%[3]s" {
origin_port = 22
edge_ips {
type = "static"
connectivity = "all"
ips = ["172.65.64.13"]
}
}`, zoneID, zoneName, ID)
Expand All @@ -521,7 +496,6 @@ resource "cloudflare_spectrum_application" "%[3]s" {
origin_port = 22
edge_ips {
type = "static"
connectivity = "all"
ips = [%[4]s]
}
}`, zoneID, zoneName, ID, IPs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ func resourceCloudflareSpectrumApplicationSchema() map[string]*schema.Schema {
},
"connectivity": {
Type: schema.TypeString,
Required: true,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"all", "ipv4", "ipv6"}, false),
Description: fmt.Sprintf("The IP versions supported for inbound connections on Spectrum anycast IPs. %s", renderAvailableDocumentationValuesStringSlice([]string{"all", "ipv4", "ipv6"})),
Description: fmt.Sprintf("The IP versions supported for inbound connections on Spectrum anycast IPs. Required when `type` is not `static`. %s", renderAvailableDocumentationValuesStringSlice([]string{"all", "ipv4", "ipv6"})),
},
"ips": {
Type: schema.TypeSet,
Expand Down

0 comments on commit 1dca4b2

Please sign in to comment.