Skip to content

Commit

Permalink
Merge pull request #631 from terraform-providers/SDK-88
Browse files Browse the repository at this point in the history
SDK-88: Add edge_ips, argo_smart_routing support for Spectrum
  • Loading branch information
jacobbednarz authored Mar 25, 2020
2 parents aae95b0 + 25d1433 commit 9ec5be3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
69 changes: 67 additions & 2 deletions cloudflare/resource_cloudflare_spectrum_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cloudflare
import (
"fmt"
"log"
"net"
"strings"

"github.com/cloudflare/cloudflare-go"
Expand Down Expand Up @@ -108,6 +109,26 @@ func resourceCloudflareSpectrumApplication() *schema.Resource {
"off", "v1", "v2", "simple",
}, false),
},

"edge_ips": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"edge_ip_connectivity": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"all", "ipv4", "ipv6",
}, false),
},

"argo_smart_routing": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand Down Expand Up @@ -186,11 +207,18 @@ func resourceCloudflareSpectrumApplicationRead(d *schema.ResourceData, meta inte
}
}

if application.EdgeIPs != nil {
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)
}
}

d.Set("origin_port", application.OriginPort)
d.Set("tls", application.TLS)
d.Set("traffic_type", application.TrafficType)
d.Set("ip_firewall", application.IPFirewall)
d.Set("proxy_protocol", application.ProxyProtocol)
d.Set("argo_smart_routing", application.ArgoSmartRouting)

return nil
}
Expand Down Expand Up @@ -224,6 +252,9 @@ func resourceCloudflareSpectrumApplicationImport(d *schema.ResourceData, meta in

d.Set("zone_id", zoneID)
d.SetId(applicationID)

resourceCloudflareSpectrumApplicationRead(d, meta)

return []*schema.ResourceData{d}, nil
}

Expand Down Expand Up @@ -263,6 +294,16 @@ func flattenOriginDNS(dns *cloudflare.SpectrumApplicationOriginDNS) []map[string
return []map[string]interface{}{flattened}
}

func flattenEdgeIPs(edgeIPs *cloudflare.SpectrumApplicationEdgeIPs) []string {
flattened := make([]string, 0)

for _, ip := range edgeIPs.IPs {
flattened = append(flattened, ip.String())
}

return flattened
}

func applicationFromResource(d *schema.ResourceData) cloudflare.SpectrumApplication {
application := cloudflare.SpectrumApplication{
ID: d.Id(),
Expand All @@ -286,8 +327,8 @@ func applicationFromResource(d *schema.ResourceData) cloudflare.SpectrumApplicat
application.TLS = tls.(string)
}

if traffic_type, ok := d.GetOk("traffic_type"); ok {
application.TrafficType = traffic_type.(string)
if trafficType, ok := d.GetOk("traffic_type"); ok {
application.TrafficType = trafficType.(string)
}

if ipFirewall, ok := d.GetOk("ip_firewall"); ok {
Expand All @@ -298,5 +339,29 @@ func applicationFromResource(d *schema.ResourceData) cloudflare.SpectrumApplicat
application.ProxyProtocol = cloudflare.ProxyProtocol(proxyProtocol.(string))
}

if argoSmartRouting, ok := d.GetOk("argo_smart_routing"); ok {
application.ArgoSmartRouting = argoSmartRouting.(bool)
}

connectivity := cloudflare.SpectrumApplicationConnectivity(cloudflare.SpectrumConnectivityAll)
application.EdgeIPs = &cloudflare.SpectrumApplicationEdgeIPs{
Type: cloudflare.SpectrumEdgeTypeDynamic,
Connectivity: &connectivity,
}

if edgeIPConnectivity, ok := d.GetOk("edge_ip_connectivity"); ok {
connectivity = cloudflare.SpectrumApplicationConnectivity(edgeIPConnectivity.(string))
}

if edgeIPs, ok := d.GetOk("edge_ips"); ok {
application.EdgeIPs = &cloudflare.SpectrumApplicationEdgeIPs{
Type: cloudflare.SpectrumEdgeTypeStatic,
}
// connectivity = cloudflare.SpectrumConnectivityStatic
for _, value := range edgeIPs.([]interface{}) {
application.EdgeIPs.IPs = append(application.EdgeIPs.IPs, net.ParseIP(value.(string)))
}
}

return application
}
5 changes: 4 additions & 1 deletion website/docs/r/spectrum_application.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ resource "cloudflare_spectrum_application" "ssh_proxy" {
* `tls` - (Optional) TLS configuration option for Cloudflare to connect to your origin. Valid values are: `off`, `flexible`, `full` and `strict`. Defaults to `off`.
* `ip_firewall` - (Optional) Enables the IP Firewall for this application. Defaults to `true`.
* `proxy_protocol` - (Optional) Enables a proxy protocol to the origin. Valid values are: `off`, `v1`, `v2`, and `simple`. Defaults to `off`.
* `traffic_type` - (Optional) Set's application type. Valid values are: `direct`, `http`, `https`. Defaults to `direct`.
* `traffic_type` - (Optional) Sets application type. Valid values are: `direct`, `http`, `https`. Defaults to `direct`.
* `argo_smart_routing` - (Optional). Enables Argo Smart Routing. Defaults to `false`.
* `edge_ip_connectivity` - (Optional). Choose which types of IP addresses will be provisioned for this subdomain. Valid values are: `all`, `ipv4`, `ipv6`. Defaults to `all`.
* `edge_ips` - (Optional). A list of edge IPs (IPv4 and/or IPv6) to configure Spectrum application to. Requires [Bring Your Own IP](https://developers.cloudflare.com/spectrum/getting-started/byoip/) provisioned.

**dns**

Expand Down

0 comments on commit 9ec5be3

Please sign in to comment.