-
Notifications
You must be signed in to change notification settings - Fork 666
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1d43615
feat: implement the changes to enable/update the BFD config for the D…
ajay-malhotra1 705cd0b
Merge remote-tracking branch 'upstream/master' into bfd
ajay-malhotra1 59c843f
Merge remote-tracking branch 'upstream/master' into bfd
ajay-malhotra1 7a1fb37
chore: updated the go sum file
ajay-malhotra1 e5d10ba
doc: updated the BFD status and BFD status updated at has been added …
ajay-malhotra1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"fmt" | ||
"log" | ||
"os" | ||
"reflect" | ||
"strings" | ||
"time" | ||
|
||
|
@@ -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 { | ||
|
@@ -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, | ||
Optional: true, | ||
Description: "Gateway BFD status", | ||
}, | ||
dlBfdStatusUpdatedAt: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can bfd_status_updated_at this be optional field There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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 | ||
|
@@ -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 { | ||
|
@@ -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" { | ||
|
@@ -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 { | ||
|
@@ -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) { | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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