Skip to content

Commit

Permalink
Add BGP Metrics fields for fabric cloud router routing protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
thogarty committed Oct 4, 2024
1 parent b165549 commit 2cc8ed9
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 8 deletions.
80 changes: 74 additions & 6 deletions equinix/resource_fabric_routing_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ func createBgpConnectionIpv4Sch() map[string]*schema.Schema {
Default: true,
Description: "Admin status for the BGP session",
},
"outbound_as_prepend_count": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "AS path prepend count",
},
"inbound_med": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Inbound Multi Exit Discriminator attribute",
},
"outbound_med": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Outbound Multi Exit Discriminator attribute",
},
}
}

Expand All @@ -82,6 +100,24 @@ func createBgpConnectionIpv6Sch() map[string]*schema.Schema {
Default: true,
Description: "Admin status for the BGP session",
},
"outbound_as_prepend_count": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "AS path prepend count",
},
"inbound_med": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Inbound Multi Exit Discriminator attribute",
},
"outbound_med": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Outbound Multi Exit Discriminator attribute",
},
}
}

Expand Down Expand Up @@ -245,6 +281,12 @@ func createFabricRoutingProtocolResourceSchema() map[string]*schema.Schema {
Computed: true,
Description: "BGP authorization key",
},
"as_override_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Enable AS number override",
},
"bfd": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -712,6 +754,16 @@ func routingProtocolBgpIpv4TerraformToGo(routingProtocolBgpIpv4Request []interfa
enabled := bgpIpv4Map["enabled"].(bool)
rpBgpIpv4.SetEnabled(enabled)

if outboundAsPrependCount := bgpIpv4Map["outbound_as_prepend_count"].(int); outboundAsPrependCount > 0 {
rpBgpIpv4.SetOutboundASPrependCount(int64(outboundAsPrependCount))
}
if inboundMed := bgpIpv4Map["inbound_med"].(int); inboundMed > 0 {
rpBgpIpv4.SetInboundMED(int64(inboundMed))
}
if outboundMed := bgpIpv4Map["outbound_med"].(int); outboundMed > 0 {
rpBgpIpv4.SetOutboundMED(int64(outboundMed))
}

return rpBgpIpv4
}

Expand All @@ -729,6 +781,16 @@ func routingProtocolBgpIpv6TerraformToGo(routingProtocolBgpIpv6Request []interfa
enabled := bgpIpv6Map["enabled"].(bool)
rpBgpIpv6.SetEnabled(enabled)

if outboundAsPrependCount := bgpIpv6Map["outbound_as_prepend_count"].(int); outboundAsPrependCount > 0 {
rpBgpIpv6.SetOutboundASPrependCount(int64(outboundAsPrependCount))
}
if inboundMed := bgpIpv6Map["inbound_med"].(int); inboundMed > 0 {
rpBgpIpv6.SetInboundMED(int64(inboundMed))
}
if outboundMed := bgpIpv6Map["outbound_med"].(int); outboundMed > 0 {
rpBgpIpv6.SetOutboundMED(int64(outboundMed))
}

return rpBgpIpv6
}

Expand Down Expand Up @@ -787,9 +849,12 @@ func routingProtocolBgpConnectionIpv4GoToTerraform(routingProtocolBgpIpv4 *fabri
}

mappedBgpIpv4 := map[string]interface{}{
"customer_peer_ip": routingProtocolBgpIpv4.GetCustomerPeerIp(),
"equinix_peer_ip": routingProtocolBgpIpv4.GetEquinixPeerIp(),
"enabled": routingProtocolBgpIpv4.GetEnabled(),
"customer_peer_ip": routingProtocolBgpIpv4.GetCustomerPeerIp(),
"equinix_peer_ip": routingProtocolBgpIpv4.GetEquinixPeerIp(),
"enabled": routingProtocolBgpIpv4.GetEnabled(),
"outbound_as_prepend_count": int(routingProtocolBgpIpv4.GetOutboundASPrependCount()),
"inbound_med": int(routingProtocolBgpIpv4.GetInboundMED()),
"outbound_med": int(routingProtocolBgpIpv4.GetOutboundMED()),
}
rpBgpIpv4Set := schema.NewSet(
schema.HashResource(&schema.Resource{Schema: createBgpConnectionIpv4Sch()}),
Expand All @@ -804,9 +869,12 @@ func routingProtocolBgpConnectionIpv6GoToTerraform(routingProtocolBgpIpv6 *fabri
}

mappedBgpIpv6 := map[string]interface{}{
"customer_peer_ip": routingProtocolBgpIpv6.GetCustomerPeerIp(),
"equinix_peer_ip": routingProtocolBgpIpv6.GetEquinixPeerIp(),
"enabled": routingProtocolBgpIpv6.GetEnabled(),
"customer_peer_ip": routingProtocolBgpIpv6.GetCustomerPeerIp(),
"equinix_peer_ip": routingProtocolBgpIpv6.GetEquinixPeerIp(),
"enabled": routingProtocolBgpIpv6.GetEnabled(),
"outbound_as_prepend_count": int(routingProtocolBgpIpv6.GetOutboundASPrependCount()),
"inbound_med": int(routingProtocolBgpIpv6.GetInboundMED()),
"outbound_med": int(routingProtocolBgpIpv6.GetOutboundMED()),
}

rpBgpIpv6Set := schema.NewSet(
Expand Down
15 changes: 13 additions & 2 deletions equinix/resource_fabric_routing_protocol_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,15 @@ func TestAccFabricCreateRoutingProtocols_PFCR(t *testing.T) {
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "bgp_ipv4.0.customer_peer_ip", "190.1.1.2"),
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "bgp_ipv4.0.equinix_peer_ip", "190.1.1.1"),
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "bgp_ipv4.0.enabled", "true"),
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "bgp_ipv4.0.outbound_as_prepend_count", "1"),
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "bgp_ipv4.0.inbound_med", "4"),
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "bgp_ipv4.0.outbound_med", "7"),
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "bgp_ipv6.0.customer_peer_ip", "190::1:2"),
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "bgp_ipv6.0.equinix_peer_ip", "190::1:1"),
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "bgp_ipv6.0.enabled", "true"),
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "bgp_ipv6.0.outbound_as_prepend_count", "1"),
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "bgp_ipv6.0.inbound_med", "4"),
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "bgp_ipv6.0.outbound_med", "7"),
resource.TestCheckResourceAttr("equinix_fabric_routing_protocol.bgp", "customer_asn", "100"),

resource.TestCheckResourceAttrSet("data.equinix_fabric_routing_protocol.direct", "id"),
Expand All @@ -79,7 +85,6 @@ func TestAccFabricCreateRoutingProtocols_PFCR(t *testing.T) {
resource.TestCheckResourceAttr("data.equinix_fabric_routing_protocol.bgp", "bgp_ipv6.0.enabled", "true"),
resource.TestCheckResourceAttr("data.equinix_fabric_routing_protocol.bgp", "customer_asn", "100"),
),
ExpectNonEmptyPlan: true,
},
},
})
Expand Down Expand Up @@ -145,7 +150,7 @@ resource "equinix_fabric_connection" "this" {
}
link_protocol {
type= "DOT1Q"
vlan_tag= 2152
vlan_tag= 2008
}
location {
metro_code = "SV"
Expand Down Expand Up @@ -175,9 +180,15 @@ resource "equinix_fabric_routing_protocol" "bgp" {
name = "rp_bgp_PFCR"
bgp_ipv4{
customer_peer_ip = "190.1.1.2"
outbound_as_prepend_count = 1
inbound_med = 4
outbound_med = 7
}
bgp_ipv6{
customer_peer_ip = "190::1:2"
outbound_as_prepend_count = 1
inbound_med = 4
outbound_med = 7
}
customer_asn = "100"
}
Expand Down

0 comments on commit 2cc8ed9

Please sign in to comment.