Skip to content

Commit

Permalink
add include_sub_defaults to bgp session settings (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvm-pf authored Aug 1, 2024
1 parent 1813898 commit 47cbe21
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 89 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/packetfabric_cloud_router_bgp_session.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Read-Only:
- `bgp_settings_uuid` (String)
- `bgp_state` (String)
- `disabled` (Boolean)
- `include_sub_defaults` (Boolean)
- `l3_address` (String)
- `local_preference` (Number)
- `med` (Number)
Expand Down
1 change: 1 addition & 0 deletions docs/resources/packetfabric_cloud_router_bgp_session.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ resource "packetfabric_cloud_router_bgp_session" "cr_bgp1" {

Available range is 2 through 16.
- `disabled` (Boolean) Whether this BGP session is disabled. Defaults: false
- `include_sub_defaults` (Boolean) Set this to true to Enable Quick Internet to announce more specific default-route to customer. Defaults: falseDefaults: false
- `l3_address` (String) The L3 address of this instance. Not used for Azure connections. Required for all other CSP.
- `local_preference` (Number) The local preference for this instance. When the same route is received in multiple locations, those with a higher local preference value are preferred by the cloud router. It is used when type = in.

Expand Down
154 changes: 79 additions & 75 deletions internal/packetfabric/bgp_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ const bgpSessionSettingsByUUIDURI = "/v2/services/cloud-routers/%s/connections/%
// This struct represents a Bgp Session for an existing Cloud Router connection
// https://docs.packetfabric.com/api/v2/redoc/#operation/cloud_routers_bgp_create
type BgpSession struct {
AddressFamily string `json:"address_family"`
AsPrepend int `json:"as_prepend,omitempty"`
BfdInterval int `json:"bfd_interval,omitempty"`
BfdMultiplier int `json:"bfd_multiplier,omitempty"`
Disabled bool `json:"disabled,omitempty"`
L3Address string `json:"l3_address,omitempty"`
LocalPreference int `json:"local_preference,omitempty"`
Md5 string `json:"md5,omitempty"`
Med int `json:"med,omitempty"`
MultihopTTL int `json:"multihop_ttl,omitempty"`
Nat *BgpNat `json:"nat,omitempty"`
Orlonger bool `json:"orlonger,omitempty"`
Prefixes []BgpPrefix `json:"prefixes,omitempty"`
PrimarySubnet string `json:"primary_subnet,omitempty"`
RemoteAddress string `json:"remote_address,omitempty"`
RemoteAsn int `json:"remote_asn"`
SecondarySubnet string `json:"secondary_subnet,omitempty"`
AddressFamily string `json:"address_family"`
AsPrepend int `json:"as_prepend,omitempty"`
BfdInterval int `json:"bfd_interval,omitempty"`
BfdMultiplier int `json:"bfd_multiplier,omitempty"`
IncludeSubDefaults bool `json:"include_sub_defaults,omitempty"`
Disabled bool `json:"disabled,omitempty"`
L3Address string `json:"l3_address,omitempty"`
LocalPreference int `json:"local_preference,omitempty"`
Md5 string `json:"md5,omitempty"`
Med int `json:"med,omitempty"`
MultihopTTL int `json:"multihop_ttl,omitempty"`
Nat *BgpNat `json:"nat,omitempty"`
Orlonger bool `json:"orlonger,omitempty"`
Prefixes []BgpPrefix `json:"prefixes,omitempty"`
PrimarySubnet string `json:"primary_subnet,omitempty"`
RemoteAddress string `json:"remote_address,omitempty"`
RemoteAsn int `json:"remote_asn"`
SecondarySubnet string `json:"secondary_subnet,omitempty"`
}

type BgpSessionUpdate struct {
Expand Down Expand Up @@ -73,71 +74,74 @@ type BgpPrefix struct {
}

type BgpSessionCreateResp struct {
BgpSettingsUUID string `json:"bgp_settings_uuid"`
AddressFamily string `json:"address_family"`
RemoteAddress string `json:"remote_address"`
RemoteAsn int `json:"remote_asn"`
MultihopTTL int `json:"multihop_ttl"`
LocalPreference int `json:"local_preference"`
AsPrepend int `json:"as_prepend"`
L3Address string `json:"l3_address"`
Med int `json:"med"`
Md5 string `json:"md5"`
Orlonger bool `json:"orlonger"`
BfdInterval int `json:"bfd_interval"`
BfdMultiplier int `json:"bfd_multiplier"`
Disabled bool `json:"disabled"`
Nat *BgpNat `json:"nat"`
Prefixes []BgpPrefix `json:"prefixes"`
BgpState string `json:"bgp_state"`
TimeCreated string `json:"time_created"`
TimeUpdated string `json:"time_updated"`
BgpSettingsUUID string `json:"bgp_settings_uuid"`
AddressFamily string `json:"address_family"`
RemoteAddress string `json:"remote_address"`
RemoteAsn int `json:"remote_asn"`
MultihopTTL int `json:"multihop_ttl"`
LocalPreference int `json:"local_preference"`
AsPrepend int `json:"as_prepend"`
L3Address string `json:"l3_address"`
Med int `json:"med"`
Md5 string `json:"md5"`
Orlonger bool `json:"orlonger"`
BfdInterval int `json:"bfd_interval"`
BfdMultiplier int `json:"bfd_multiplier"`
IncludeSubDefaults bool `json:"include_sub_defaults,omitempty"`
Disabled bool `json:"disabled"`
Nat *BgpNat `json:"nat"`
Prefixes []BgpPrefix `json:"prefixes"`
BgpState string `json:"bgp_state"`
TimeCreated string `json:"time_created"`
TimeUpdated string `json:"time_updated"`
}

type BgpSessionBySettingsUUID struct {
BgpSettingsUUID string `json:"bgp_settings_uuid"`
AddressFamily string `json:"address_family"`
RemoteAddress string `json:"remote_address,omitempty"`
RemoteAsn int `json:"remote_asn"`
MultihopTTL int `json:"multihop_ttl,omitempty"`
LocalPreference int `json:"local_preference,omitempty"`
Md5 string `json:"md5,omitempty"`
Med int `json:"med,omitempty"`
L3Address string `json:"l3_address,omitempty"`
PrimarySubnet string `json:"primary_subnet,omitempty"`
SecondarySubnet string `json:"secondary_subnet,omitempty"`
AsPrepend int `json:"as_prepend,omitempty"`
Orlonger bool `json:"orlonger"`
BfdInterval int `json:"bfd_interval,omitempty"`
BfdMultiplier int `json:"bfd_multiplier,omitempty"`
Disabled bool `json:"disabled"`
BgpState string `json:"bgp_state"`
Prefixes []BgpPrefix `json:"prefixes"`
Subnet string `json:"subnet,omitempty"`
PublicIP string `json:"public_ip,omitempty"`
Nat *BgpNat `json:"nat,omitempty"`
BgpSettingsUUID string `json:"bgp_settings_uuid"`
AddressFamily string `json:"address_family"`
RemoteAddress string `json:"remote_address,omitempty"`
RemoteAsn int `json:"remote_asn"`
MultihopTTL int `json:"multihop_ttl,omitempty"`
LocalPreference int `json:"local_preference,omitempty"`
Md5 string `json:"md5,omitempty"`
Med int `json:"med,omitempty"`
L3Address string `json:"l3_address,omitempty"`
PrimarySubnet string `json:"primary_subnet,omitempty"`
SecondarySubnet string `json:"secondary_subnet,omitempty"`
AsPrepend int `json:"as_prepend,omitempty"`
Orlonger bool `json:"orlonger"`
BfdInterval int `json:"bfd_interval,omitempty"`
BfdMultiplier int `json:"bfd_multiplier,omitempty"`
IncludeSubDefaults bool `json:"include_sub_defaults,omitempty"`
Disabled bool `json:"disabled"`
BgpState string `json:"bgp_state"`
Prefixes []BgpPrefix `json:"prefixes"`
Subnet string `json:"subnet,omitempty"`
PublicIP string `json:"public_ip,omitempty"`
Nat *BgpNat `json:"nat,omitempty"`
}

// This struct represents a Bgp Session create response
type BgpSessionAssociatedResp struct {
BgpSettingsUUID string `json:"bgp_settings_uuid"`
AddressFamily string `json:"address_family"`
RemoteAddress string `json:"remote_address"`
RemoteAsn int `json:"remote_asn"`
MultihopTTL int `json:"multihop_ttl"`
LocalPreference int `json:"local_preference"`
AsPrepend int `json:"as_prepend"`
Med int `json:"med"`
L3Address string `json:"l3_address"`
Orlonger bool `json:"orlonger"`
BfdInterval int `json:"bfd_interval"`
BfdMultiplier int `json:"bfd_multiplier"`
Disabled bool `json:"disabled"`
BgpState string `json:"bgp_state"`
TimeCreated string `json:"time_created"`
TimeUpdated string `json:"time_updated"`
Prefixes []BgpPrefix `json:"prefixes"`
Nat *BgpNat `json:"nat,omitempty"`
BgpSettingsUUID string `json:"bgp_settings_uuid"`
AddressFamily string `json:"address_family"`
RemoteAddress string `json:"remote_address"`
RemoteAsn int `json:"remote_asn"`
MultihopTTL int `json:"multihop_ttl"`
LocalPreference int `json:"local_preference"`
AsPrepend int `json:"as_prepend"`
Med int `json:"med"`
L3Address string `json:"l3_address"`
Orlonger bool `json:"orlonger"`
BfdInterval int `json:"bfd_interval"`
BfdMultiplier int `json:"bfd_multiplier"`
IncludeSubDefaults bool `json:"include_sub_defaults,omitempty"`
Disabled bool `json:"disabled"`
BgpState string `json:"bgp_state"`
TimeCreated string `json:"time_created"`
TimeUpdated string `json:"time_updated"`
Prefixes []BgpPrefix `json:"prefixes"`
Nat *BgpNat `json:"nat,omitempty"`
}

type BgpDeleteMessage struct {
Expand Down
29 changes: 15 additions & 14 deletions internal/packetfabric/bgp_session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ var _updatedTime = "2019-08-24T14:15:22Z"

func init() {
_bgpSessionSettings = append(_bgpSessionSettings, BgpSessionAssociatedResp{
BgpSettingsUUID: _bgpSettingsUUID,
AddressFamily: "v4",
RemoteAddress: "10.0.0.1",
RemoteAsn: 4556,
MultihopTTL: 1,
LocalPreference: 1,
AsPrepend: 1,
Med: 1,
Orlonger: true,
BfdInterval: 300,
BfdMultiplier: 3,
Disabled: false,
TimeCreated: _createdTime,
TimeUpdated: _updatedTime,
BgpSettingsUUID: _bgpSettingsUUID,
AddressFamily: "v4",
RemoteAddress: "10.0.0.1",
RemoteAsn: 4556,
MultihopTTL: 1,
LocalPreference: 1,
AsPrepend: 1,
Med: 1,
Orlonger: true,
BfdInterval: 300,
BfdMultiplier: 3,
IncludeSubDefaults: false,
Disabled: false,
TimeCreated: _createdTime,
TimeUpdated: _updatedTime,
Prefixes: []BgpPrefix{
{
Prefix: _bgpPrefixOut,
Expand Down
1 change: 1 addition & 0 deletions internal/packetfabric/cloud_service_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ type BgpSettings struct {
AsPrepend int `json:"as_prepend,omitempty"`
BfdInterval int `json:"bfd_interval,omitempty"`
BfdMultiplier int `json:"bfd_multiplier,omitempty"`
IncludeSubDefaults bool `json:"include_sub_defaults,omitempty"`
CustomerAsn int `json:"customer_asn,omitempty"`
CustomerRouterIp string `json:"customer_router_ip,omitempty"`
Disabled bool `json:"disabled,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/datasource_bgp_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func dataSourceBgpSession() *schema.Resource {
Computed: true,
Description: "The number of BFD Control packets not received by a neighbor that causes the session to be declared down.\n\t\tAvailable range is 2 through 16.",
},
"include_sub_defaults": {
Type: schema.TypeBool,
Computed: true,
Description: "Set this to true to Enable Quick Internet to announce more specific default-route to customer. Defaults: false",
},
"disabled": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -266,6 +271,7 @@ func flattenBgpSessions(sessions *[]packetfabric.BgpSessionAssociatedResp) []int
flatten["orlonger"] = session.Orlonger
flatten["bfd_interval"] = session.BfdInterval
flatten["bfd_multiplier"] = session.BfdMultiplier
flatten["include_sub_defaults"] = session.IncludeSubDefaults
flatten["disabled"] = session.Disabled
flatten["bgp_state"] = session.BgpState
flatten["time_created"] = session.TimeCreated
Expand Down
1 change: 1 addition & 0 deletions internal/provider/datasource_bgp_session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestAccDataSourceBgpSessionComputedRequiredFields(t *testing.T) {
resource.TestCheckResourceAttrSet(datasourceBgpSessionResult.ResourceName, "bgp_sessions.0.med"),
resource.TestCheckResourceAttrSet(datasourceBgpSessionResult.ResourceName, "bgp_sessions.0.bfd_interval"),
resource.TestCheckResourceAttrSet(datasourceBgpSessionResult.ResourceName, "bgp_sessions.0.bfd_multiplier"),
resource.TestCheckResourceAttrSet(datasourceBgpSessionResult.ResourceName, "bgp_sessions.0.include_sub_defaults"),
resource.TestCheckResourceAttrSet(datasourceBgpSessionResult.ResourceName, "bgp_sessions.0.disabled"),
resource.TestCheckResourceAttrSet(datasourceBgpSessionResult.ResourceName, "bgp_sessions.0.time_created"),
resource.TestCheckResourceAttrSet(datasourceBgpSessionResult.ResourceName, "bgp_sessions.0.prefixes.0.bgp_prefix_uuid"),
Expand Down
13 changes: 13 additions & 0 deletions internal/provider/resource_bgp_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ func resourceBgpSession() *schema.Resource {
ValidateFunc: validation.IntBetween(2, 16),
Description: "If you are using BFD, this is the number of consecutive packets that can be lost before BFD considers a peer down and shuts down BGP.\n\n\tAvailable range is 2 through 16. ",
},
"include_sub_defaults": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Set this to true to Enable Quick Internet to announce more specific default-route to customer. Defaults: false",
},
"disabled": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -348,6 +354,7 @@ func resourceBgpSessionRead(ctx context.Context, d *schema.ResourceData, m inter
_ = d.Set("local_preference", bgp.LocalPreference)
_ = d.Set("bfd_interval", bgp.BfdInterval)
_ = d.Set("bfd_multiplier", bgp.BfdMultiplier)
_ = d.Set("include_sub_defaults", bgp.IncludeSubDefaults)

if bgp.Nat != nil {
nat := flattenNatConfiguration(bgp.Nat)
Expand Down Expand Up @@ -451,6 +458,9 @@ func extractBgpSessionCreate(d *schema.ResourceData) packetfabric.BgpSession {
if bfdMultiplier, ok := d.GetOk("bfd_multiplier"); ok {
bgpSession.BfdMultiplier = bfdMultiplier.(int)
}
if includeSubDefaults, ok := d.GetOk("include_sub_defaults"); ok {
bgpSession.IncludeSubDefaults = includeSubDefaults.(bool)
}
if md5, ok := d.GetOk("md5"); ok {
bgpSession.Md5 = md5.(string)
}
Expand Down Expand Up @@ -520,6 +530,9 @@ func extractBgpSessionUpdate(d *schema.ResourceData, c *packetfabric.PFClient, c
if bfdMultiplier, ok := d.GetOk("bfd_multiplier"); ok {
bgpSession.BfdMultiplier = bfdMultiplier.(int)
}
if includeSubDefaults, ok := d.GetOk("include_sub_defaults"); ok {
bgpSession.IncludeSubDefaults = includeSubDefaults.(bool)
}
if md5, ok := d.GetOk("md5"); ok {
bgpSession.Md5 = md5.(string)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/resource_cloud_router_connection_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ func extractBgpSessionFromCloudSettings(d *schema.ResourceData, bgpSettings map[
if bfdMultiplier, ok := bgpSettings["bfd_multiplier"]; ok && bfdMultiplier.(int) != 0 {
bgpSession.BfdMultiplier = bfdMultiplier.(int)
}
if includeSubDefaults, ok := d.GetOk("include_sub_defaults"); ok {
bgpSession.IncludeSubDefaults = includeSubDefaults.(bool)
}
if md5, ok := bgpSettings["md5"]; ok && md5.(string) != "" {
bgpSession.Md5 = md5.(string)
} else {
Expand Down Expand Up @@ -378,6 +381,9 @@ func extractRouterConnBgpSettings(bgpSettingsMap map[string]interface{}) *packet
if bfdMultiplier, ok := bgpSettingsMap["bfd_multiplier"]; ok {
bgpSettings.BfdMultiplier = bfdMultiplier.(int)
}
if includeSubDefaults, ok := bgpSettingsMap["include_sub_defaults"]; ok {
bgpSettings.IncludeSubDefaults = includeSubDefaults.(bool)
}
if nat, ok := bgpSettingsMap["nat"]; ok {
for _, nat := range nat.(*schema.Set).List() {
bgpSettings.Nat = extractConnBgpSessionNat(nat.(map[string]interface{}))
Expand Down

0 comments on commit 47cbe21

Please sign in to comment.