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

feat: implement the changes to enable/update the BFD config for the DirectLink gateways #3194

Merged
merged 5 commits into from
Oct 27, 2021
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: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ github.com/IBM/go-sdk-core/v5 v5.0.3/go.mod h1:vyNdbFujJtdTj9HbihtvKwwS3k/GKSKpO
github.com/IBM/go-sdk-core/v5 v5.1.0/go.mod h1:vyNdbFujJtdTj9HbihtvKwwS3k/GKSKpOx9ZIQ6MWDY=
github.com/IBM/go-sdk-core/v5 v5.4.5/go.mod h1:Sn+z+qTDREQvCr+UFa22TqqfXNxx3o723y8GsfLV8e0=
github.com/IBM/go-sdk-core/v5 v5.5.1/go.mod h1:Sn+z+qTDREQvCr+UFa22TqqfXNxx3o723y8GsfLV8e0=
github.com/IBM/go-sdk-core/v5 v5.6.3 h1:xj44tzfBnjGJXKthMeaIn9wcYH+z4dXTuhntsBp+NdQ=
github.com/IBM/go-sdk-core/v5 v5.6.3/go.mod h1:tt/B9rxLkRtglE7pvqLuYikgCXaZFL3btdruJaoUeek=
github.com/IBM/go-sdk-core/v5 v5.6.5 h1:zXlt5x/udqZTD617SKUQzPDON4x5y0+22vNxsdCGYpg=
github.com/IBM/go-sdk-core/v5 v5.6.5/go.mod h1:tt/B9rxLkRtglE7pvqLuYikgCXaZFL3btdruJaoUeek=
Expand All @@ -95,8 +94,6 @@ github.com/IBM/schematics-go-sdk v0.0.2 h1:IFdM73VL3xwf/KaTh1IY99hkiTfFRYg5F1JNj
github.com/IBM/schematics-go-sdk v0.0.2/go.mod h1:ymN1+3uEaWNT0RthwHzExxMiN0AnTh6W3piSY8canjs=
github.com/IBM/secrets-manager-go-sdk v0.1.19 h1:0GPs5EoTaWNsjo4QPj64GNxlWfN8VHJy4RDFLqddSe8=
github.com/IBM/secrets-manager-go-sdk v0.1.19/go.mod h1:eO3dBhzPrHkkt+yPex/jB2xD6qHZxBko+Aw+0tfqHeA=
github.com/IBM/vpc-go-sdk v0.10.0 h1:QAUN6hziV9+dbtsHrk8KuSr/kIW8qGBNlCsZ/ghgBZ4=
github.com/IBM/vpc-go-sdk v0.10.0/go.mod h1:Y1oXX7o+UJIKzMnTt1t74e2weUzVqb2XZ1/INV/D/fs=
github.com/IBM/vpc-go-sdk v0.12.0 h1:tOuEveEJOEjNhLcRxTOG/w5mf0e59fqJVwSysq2oSx8=
github.com/IBM/vpc-go-sdk v0.12.0/go.mod h1:B3Pgkwb0tQqTeIojR1MFLp96qW7cKnWyJ74jbAJgdbk=
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:vuquMR410psHNax14XKNWa0Ae/kYgWJcXi0IFuX60N0=
Expand Down
39 changes: 39 additions & 0 deletions ibm/data_source_ibm_dl_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ func dataSourceIBMDLGateway() *schema.Resource {
Computed: true,
Description: "BGP MD5 authentication key",
},
dlBfdInterval: {
Type: schema.TypeInt,
Computed: true,
Description: "BFD Interval",
},
dlBfdMultiplier: {
Type: schema.TypeInt,
Computed: true,
Description: "BFD Multiplier",
},
dlBfdStatus: {
Type: schema.TypeString,
Computed: true,
Description: "BFD Status",
},
dlBfdStatusUpdatedAt: {
Type: schema.TypeString,
Computed: true,
Description: "BFD Status",
},
dlBgpAsn: {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -405,6 +425,25 @@ func dataSourceIBMDLGatewayRead(d *schema.ResourceData, meta interface{}) error
if instance.CreatedAt != nil {
d.Set(dlCreatedAt, instance.CreatedAt.String())
}

//Show the BFD Config parameters if set
if instance.BfdConfig != nil {
if instance.BfdConfig.Interval != nil {
d.Set(dlBfdInterval, *instance.BfdConfig.Interval)
}

if instance.BfdConfig.Multiplier != nil {
d.Set(dlBfdMultiplier, *instance.BfdConfig.Multiplier)
}

if instance.BfdConfig.BfdStatus != nil {
d.Set(dlBfdStatus, *instance.BfdConfig.BfdStatus)
}

if instance.BfdConfig.BfdStatusUpdatedAt != nil {
d.Set(dlBfdStatusUpdatedAt, instance.BfdConfig.BfdStatusUpdatedAt.String())
}
}
dtype := *instance.Type
if dtype == "dedicated" {
if instance.MacsecConfig != nil {
Expand Down
40 changes: 40 additions & 0 deletions ibm/data_source_ibm_dl_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ func dataSourceIBMDLGateways() *schema.Resource {
Computed: true,
Description: "BGP MD5 authentication key",
},
dlBfdInterval: {
Type: schema.TypeInt,
Computed: true,
Description: "BFD Interval",
},
dlBfdMultiplier: {
Type: schema.TypeInt,
Computed: true,
Description: "BFD Multiplier",
},
dlBfdStatus: {
Type: schema.TypeString,
Computed: true,
Description: "BFD Status",
},
dlBfdStatusUpdatedAt: {
Type: schema.TypeString,
Computed: true,
Description: "BFD Status",
},
dlBgpAsn: {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -322,6 +342,26 @@ func dataSourceIBMDLGatewaysRead(d *schema.ResourceData, meta interface{}) error
rg := instance.ResourceGroup
gateway[dlResourceGroup] = *rg.ID
}

//Show the BFD Config parameters if set
if instance.BfdConfig != nil {
if instance.BfdConfig.Interval != nil {
gateway[dlBfdInterval] = *instance.BfdConfig.Interval
}

if instance.BfdConfig.Multiplier != nil {
gateway[dlBfdMultiplier] = *instance.BfdConfig.Multiplier
}

if instance.BfdConfig.BfdStatus != nil {
gateway[dlBfdStatus] = *instance.BfdConfig.BfdStatus
}

if instance.BfdConfig.BfdStatusUpdatedAt != nil {
gateway[dlBfdStatusUpdatedAt] = instance.BfdConfig.BfdStatusUpdatedAt.String()
}
}

dtype := *instance.Type
if dtype == "dedicated" {
if instance.MacsecConfig != nil {
Expand Down
169 changes: 138 additions & 31 deletions ibm/resource_ibm_dl_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"log"
"os"
"reflect"
"strings"
"time"

Expand All @@ -18,50 +19,54 @@ import (
)

const (
dlLoaRejectReason = "loa_reject_reason"
dlCustomerName = "customer_name"
dlCarrierName = "carrier_name"
dlResourceGroup = "resource_group"
dlActive = "active"
dlAuthenticationKey = "authentication_key"
dlBfdInterval = "bfd_interval"
dlBfdMultiplier = "bfd_multiplier"
dlBfdStatus = "bfd_status"
dlBfdStatusUpdatedAt = "bfd_status_updated_at"
dlBgpAsn = "bgp_asn"
dlBgpBaseCidr = "bgp_base_cidr"
dlBgpCerCidr = "bgp_cer_cidr"
dlBgpIbmAsn = "bgp_ibm_asn"
dlBgpIbmCidr = "bgp_ibm_cidr"
dlBgpStatus = "bgp_status"
dlCarrierName = "carrier_name"
dlChangeRequest = "change_request"
dlCipherSuite = "cipher_suite"
dlCompletionNoticeRejectReason = "completion_notice_reject_reason"
dlConfidentialityOffset = "confidentiality_offset"
dlGatewayProvisioning = "configuring"
dlConnectionMode = "connection_mode"
dlCreatedAt = "created_at"
dlGatewayProvisioningRejected = "create_rejected"
dlCrossConnectRouter = "cross_connect_router"
dlCrn = "crn"
dlCryptographicAlgorithm = "cryptographic_algorithm"
dlCustomerName = "customer_name"
dlFallbackCak = "fallback_cak"
dlGlobal = "global"
dlKeyServerPriority = "key_server_priority"
dlLoaRejectReason = "loa_reject_reason"
dlLocationDisplayName = "location_display_name"
dlLocationName = "location_name"
dlName = "name"
dlSpeedMbps = "speed_mbps"
dlOperationalStatus = "operational_status"
dlBgpStatus = "bgp_status"
dlLinkStatus = "link_status"
dlType = "type"
dlCrn = "crn"
dlCreatedAt = "created_at"
dlMacSecConfig = "macsec_config"
dlMetered = "metered"
dlLocationDisplayName = "location_display_name"
dlBgpIbmAsn = "bgp_ibm_asn"
dlCompletionNoticeRejectReason = "completion_notice_reject_reason"
dlName = "name"
dlOperationalStatus = "operational_status"
dlPort = "port"
dlProviderAPIManaged = "provider_api_managed"
dlVlan = "vlan"
dlTags = "tags"
dlActive = "active"
dlFallbackCak = "fallback_cak"
dlPrimaryCak = "primary_cak"
dlProviderAPIManaged = "provider_api_managed"
dlGatewayProvisioningDone = "provisioned"
dlResourceGroup = "resource_group"
dlSakExpiryTime = "sak_expiry_time"
dlWindowSize = "window_size"
dlMacSecConfig = "macsec_config"
dlCipherSuite = "cipher_suite"
dlConfidentialityOffset = "confidentiality_offset"
dlCryptographicAlgorithm = "cryptographic_algorithm"
dlKeyServerPriority = "key_server_priority"
dlSpeedMbps = "speed_mbps"
dlMacSecConfigStatus = "status"
dlChangeRequest = "change_request"
dlGatewayProvisioning = "configuring"
dlGatewayProvisioningDone = "provisioned"
dlGatewayProvisioningRejected = "create_rejected"
dlAuthenticationKey = "authentication_key"
dlConnectionMode = "connection_mode"
dlTags = "tags"
dlType = "type"
dlVlan = "vlan"
dlWindowSize = "window_size"
)

func resourceIBMDLGateway() *schema.Resource {
Expand Down Expand Up @@ -92,6 +97,32 @@ func resourceIBMDLGateway() *schema.Resource {
ForceNew: false,
Description: "BGP MD5 authentication key",
},
dlBfdInterval: {
Type: schema.TypeInt,
Optional: true,
ForceNew: false,
Description: "BFD Interval",
ValidateFunc: InvokeValidator("ibm_dl_gateway", dlBfdInterval),
},
dlBfdMultiplier: {
Type: schema.TypeInt,
Optional: true,
ForceNew: false,
Description: "BFD Multiplier",
ValidateFunc: InvokeValidator("ibm_dl_gateway", dlBfdMultiplier),
},
dlBfdStatus: {
Type: schema.TypeString,
Computed: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status can be a optional field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BFD status has been created as an optional field for ibm_dl_gateway resource at L117

Optional: true,
Description: "Gateway BFD status",
},
dlBfdStatusUpdatedAt: {
Type: schema.TypeString,
Computed: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can bfd_status_updated_at this be optional field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BFD status updated at has been created as an optional field for ibm_dl_gateway resource at L123

Optional: true,
Description: "Date and time BFD status was updated",
},
dlBgpAsn: {
Type: schema.TypeInt,
Required: true,
Expand Down Expand Up @@ -420,6 +451,22 @@ func resourceIBMDLGatewayValidator() *ResourceValidator {
Type: TypeString,
Required: true,
AllowedValues: dlConnectionModeAllowedValues})
validateSchema = append(validateSchema,
ValidateSchema{
Identifier: dlBfdInterval,
ValidateFunctionIdentifier: IntBetween,
Type: TypeInt,
Required: true,
MinValue: "300",
MaxValue: "255000"})
validateSchema = append(validateSchema,
ValidateSchema{
Identifier: dlBfdMultiplier,
ValidateFunctionIdentifier: IntBetween,
Type: TypeInt,
Required: true,
MinValue: "1",
MaxValue: "255"})

ibmISDLGatewayResourceValidator := ResourceValidator{ResourceName: "ibm_dl_gateway", Schema: validateSchema}
return &ibmISDLGatewayResourceValidator
Expand All @@ -443,6 +490,24 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error
bgpAsn := int64(d.Get(dlBgpAsn).(int))
metered := d.Get(dlMetered).(bool)

var bfdConfig directlinkv1.GatewayBfdConfigTemplate
isBfdInterval := false

if bfdInterval, ok := d.GetOk(dlBfdInterval); ok {
isBfdInterval = true
interval := int64(bfdInterval.(int))
bfdConfig.Interval = &interval
}

if bfdMultiplier, ok := d.GetOk(dlBfdMultiplier); ok {
multiplier := int64(bfdMultiplier.(int))
bfdConfig.Multiplier = &multiplier
} else if isBfdInterval {
// Set the default value for multiplier if interval is set
multiplier := int64(3)
bfdConfig.Multiplier = &multiplier
}

if dtype == "dedicated" {
var crossConnectRouter, carrierName, locationName, customerName string
if _, ok := d.GetOk(dlCarrierName); ok {
Expand Down Expand Up @@ -534,6 +599,10 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error
gatewayDedicatedTemplateModel.ConnectionMode = &connectionModeStr
}

if !reflect.DeepEqual(bfdConfig, directlinkv1.GatewayBfdConfigTemplate{}) {
gatewayDedicatedTemplateModel.BfdConfig = &bfdConfig
}

createGatewayOptionsModel.GatewayTemplate = gatewayDedicatedTemplateModel

} else if dtype == "connect" {
Expand Down Expand Up @@ -575,6 +644,10 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error
gatewayConnectTemplateModel.ConnectionMode = &connectionModeStr
}

if !reflect.DeepEqual(bfdConfig, directlinkv1.GatewayBfdConfigTemplate{}) {
gatewayConnectTemplateModel.BfdConfig = &bfdConfig
}

createGatewayOptionsModel.GatewayTemplate = gatewayConnectTemplateModel

} else {
Expand Down Expand Up @@ -789,6 +862,25 @@ func resourceIBMdlGatewayRead(d *schema.ResourceData, meta interface{}) error {
d.Set(ResourceGroupName, *rg.ID)
}

//Show the BFD Config parameters if set
if instance.BfdConfig != nil {
if instance.BfdConfig.Interval != nil {
d.Set(dlBfdInterval, *instance.BfdConfig.Interval)
}

if instance.BfdConfig.Multiplier != nil {
d.Set(dlBfdMultiplier, *instance.BfdConfig.Multiplier)
}

if instance.BfdConfig.BfdStatus != nil {
d.Set(dlBfdStatus, *instance.BfdConfig.BfdStatus)
}

if instance.BfdConfig.BfdStatusUpdatedAt != nil {
d.Set(dlBfdStatusUpdatedAt, instance.BfdConfig.BfdStatusUpdatedAt.String())
}
}

return nil
}
func isWaitForDirectLinkAvailable(client *directlinkv1.DirectLinkV1, id string, timeout time.Duration) (interface{}, error) {
Expand Down Expand Up @@ -907,6 +999,21 @@ func resourceIBMdlGatewayUpdate(d *schema.ResourceData, meta interface{}) error
updateGatewayOptionsModel.ConnectionMode = &updatedConnectionMode
}

var updatedBfdConfig directlinkv1.GatewayBfdPatchTemplate
if bfdInterval, ok := d.GetOk(dlBfdInterval); ok && d.HasChange(dlBfdInterval) {
updatedBfdInterval := bfdInterval.(int64)
updatedBfdConfig.Interval = &updatedBfdInterval
}

if bfdMultiplier, ok := d.GetOk(dlBfdMultiplier); ok && d.HasChange(dlBfdMultiplier) {
updatedbfdMultiplier := bfdMultiplier.(int64)
updatedBfdConfig.Multiplier = &updatedbfdMultiplier
}

if !reflect.DeepEqual(updatedBfdConfig, directlinkv1.GatewayBfdPatchTemplate{}) {
updateGatewayOptionsModel.BfdConfig = &updatedBfdConfig
}

if dtype == "dedicated" {
if d.HasChange(dlMacSecConfig) && !d.IsNewResource() {
// Construct an instance of the GatewayMacsecConfigTemplate model
Expand Down
4 changes: 4 additions & 0 deletions website/docs/d/dl_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Review the argument reference that you can specify for your resource.
In addition to the argument reference list, you can access the following attribute references after your data source is created.

- `authentication_key` - (String) BGP MD5 authentication key.
- `bfd_interval` - (String) Minimum interval in milliseconds at which the local routing device transmits hello packets and then expects to receive a reply from a neighbor with which it has established a BFD session.
- `bfd_multiplier` - (String) The number of hello packets not received by a neighbor that causes the originating interface to be declared down.
- `bfd_status` - (String) Gateway BFD status.
- `bfd_status_updated_at` - (String) Date and time bfd status was updated.
- `bgp_asn` - (String) Customer BGP ASN.
- `bgp_base_cidr` - (String) The BGP base CIDR.
- `bgp_cer_cidr` - (String) The BGP customer edge router CIDR.
Expand Down
4 changes: 4 additions & 0 deletions website/docs/d/dl_gateways.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ You can access the following attribute references after your data source is crea

Nested scheme for `gateways`:
- `authentication_key` - (String) BGP MD5 authentication key.
- `bfd_interval` - (String) Minimum interval in milliseconds at which the local routing device transmits hello packets and then expects to receive a reply from a neighbor with which it has established a BFD session.
- `bfd_multiplier` - (String) The number of hello packets not received by a neighbor that causes the originating interface to be declared down.
- `bfd_status` - (String) Gateway BFD status.
- `bfd_status_updated_at` - (String) Date and time bfd status was updated.
- `bgp_asn` - (String) Customer BGP ASN.
- `bgp_base_cidr` - (String) The BGP base CIDR.
- `bgp_cer_cidr` - (String) The BGP customer edge router CIDR.
Expand Down
Loading