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

Direct Link: Dedicated VLAN Mapping #4900

Merged
merged 15 commits into from
Mar 13, 2024
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20211109141421-a4b61b05f7d1
github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta
github.com/IBM/keyprotect-go-client v0.12.2
github.com/IBM/networking-go-sdk v0.44.0
github.com/IBM/networking-go-sdk v0.45.0
github.com/IBM/platform-services-go-sdk v0.59.0
github.com/IBM/project-go-sdk v0.2.1
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
Expand Down Expand Up @@ -202,7 +202,7 @@ require (
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect; indirec
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.uber.org/ratelimit v0.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ github.com/IBM/keyprotect-go-client v0.12.2 h1:Cjxcqin9Pl0xz3MnxdiVd4v/eIa79xL3h
github.com/IBM/keyprotect-go-client v0.12.2/go.mod h1:yr8h2noNgU8vcbs+vhqoXp3Lmv73PI0zAc6VMgFvWwM=
github.com/IBM/mqcloud-go-sdk v0.0.4 h1:gqMpoU5a0qJ0GETG4PQrkgeEEoaQLvbxRJnEe6ytvC4=
github.com/IBM/mqcloud-go-sdk v0.0.4/go.mod h1:gQptHC6D+rxfg0muRFFGvTDmvl4YfiDE0uXkaRRewRk=
github.com/IBM/networking-go-sdk v0.44.0 h1:6acyMd6hwxcjK3bJ2suiUBTjzg8mRFAvYD76zbx0adk=
github.com/IBM/networking-go-sdk v0.44.0/go.mod h1:XtqYRInR5NHmFUXhOL6RovpDdv6PnJfZ1lPFvssA8MA=
github.com/IBM/networking-go-sdk v0.45.0 h1:tYgDhVDpgKvELNY7tcodbZ4ny9fatpEWM6PwtQcDe20=
github.com/IBM/networking-go-sdk v0.45.0/go.mod h1:NnJPA1e5GWr5opJe+5Hs6e1G6RcBIFz64TrkZsdnSp8=
github.com/IBM/platform-services-go-sdk v0.59.0 h1:FSRM3oKHxzShLCsIIb6Dl+JSaVOXpBWnfWFITJR6DDk=
github.com/IBM/platform-services-go-sdk v0.59.0/go.mod h1:+U6Kg7o5u/Bh4ZkLxjymSgfdpVsaWAtsMtzhwclUry0=
github.com/IBM/project-go-sdk v0.2.1 h1:Xo7ITrfyfVm0eCsaC2SADlhcEjqjx9rtU37fwnzGMCI=
Expand Down
1 change: 1 addition & 0 deletions ibm/service/directlink/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const (
dlType = "type"
dlUpdatedAt = "updated_at"
dlVlan = "vlan"
dlRemoveVlan = "remove_vlan"
dlWindowSize = "window_size"
customerAccountID = "customer_account_id"
dlRouteReports = "route_reports"
Expand Down
4 changes: 3 additions & 1 deletion ibm/service/directlink/data_source_ibm_dl_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ func dataSourceIBMDLGatewayRead(d *schema.ResourceData, meta interface{}) error
}
var found bool

for _, instance := range listGateways.Gateways {
for _, gwIntf := range listGateways.Gateways {

instance := gwIntf.(*directlinkv1.GatewayCollectionGatewaysItem)

if *instance.Name == dlGatewayName {
found = true
Expand Down
5 changes: 4 additions & 1 deletion ibm/service/directlink/data_source_ibm_dl_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,11 @@ func dataSourceIBMDLGatewaysRead(d *schema.ResourceData, meta interface{}) error
return err
}
gateways := make([]map[string]interface{}, 0)
for _, instance := range listGateways.Gateways {
for _, gwIntf := range listGateways.Gateways {

gateway := map[string]interface{}{}
instance := gwIntf.(*directlinkv1.GatewayCollectionGatewaysItem)

if instance.ID != nil {
gateway["id"] = *instance.ID
}
Expand Down
106 changes: 76 additions & 30 deletions ibm/service/directlink/resource_ibm_dl_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/IBM/go-sdk-core/v3/core"
"github.com/IBM/networking-go-sdk/directlinkv1"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -451,9 +452,19 @@ func ResourceIBMDLGateway() *schema.Resource {
Description: "Indicates whether gateway was created through a provider portal",
},
dlVlan: {
Type: schema.TypeInt,
Computed: true,
Description: "VLAN allocated for this gateway",
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "VLAN allocated for this gateway",
ConflictsWith: []string{"remove_vlan"},
ValidateFunc: validate.InvokeValidator("ibm_dl_gateway", dlVlan),
},
dlRemoveVlan: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove_vlan comes only during update scenario?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

Type: schema.TypeBool,
Optional: true,
Default: false,
ConflictsWith: []string{"vlan"},
Description: "Remove VLAN allocated for this dedicated gateway",
},
dlBgpIbmAsn: {
Type: schema.TypeInt,
Expand Down Expand Up @@ -640,6 +651,14 @@ func ResourceIBMDLGatewayValidator() *validate.ResourceValidator {
MinValue: "3",
MaxValue: "10"})

validateSchema = append(validateSchema,
validate.ValidateSchema{
Identifier: dlVlan,
ValidateFunctionIdentifier: validate.IntBetween,
Type: validate.TypeInt,
MinValue: "2",
MaxValue: "3967"})

ibmISDLGatewayResourceValidator := validate.ResourceValidator{ResourceName: "ibm_dl_gateway", Schema: validateSchema}
return &ibmISDLGatewayResourceValidator
}
Expand Down Expand Up @@ -859,6 +878,11 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error
if default_import_route_filter, ok := d.GetOk(dlDefault_import_route_filter); ok {
gatewayDedicatedTemplateModel.DefaultImportRouteFilter = NewStrPointer(default_import_route_filter.(string))
}

if vlan, ok := d.GetOk(dlVlan); ok {
mapped_vlan := int64(vlan.(int))
gatewayDedicatedTemplateModel.Vlan = &mapped_vlan
}
createGatewayOptionsModel.GatewayTemplate = gatewayDedicatedTemplateModel

} else if dtype == "connect" {
Expand Down Expand Up @@ -1070,14 +1094,16 @@ func resourceIBMdlGatewayRead(d *schema.ResourceData, meta interface{}) error {
}
log.Printf("[INFO] Calling getgateway api: %s", dtype)

instance, response, err := directLink.GetGateway(getOptions)
if err != nil {
instanceIntf, response, err := directLink.GetGateway(getOptions)
if (err != nil) || (instanceIntf == nil) {
if response != nil && response.StatusCode == 404 {
d.SetId("")
return nil
}
return fmt.Errorf("[ERROR] Error Getting Direct Link Gateway (%s Template): %s\n%s", dtype, err, response)
}

instance := instanceIntf.(*directlinkv1.GetGatewayResponse)
if instance.Name != nil {
d.Set(dlName, *instance.Name)
}
Expand Down Expand Up @@ -1134,7 +1160,10 @@ func resourceIBMdlGatewayRead(d *schema.ResourceData, meta interface{}) error {
}
if instance.Vlan != nil {
d.Set(dlVlan, *instance.Vlan)
} else {
d.Set(dlVlan, nil)
}

if instance.Global != nil {
d.Set(dlGlobal, *instance.Global)
}
Expand Down Expand Up @@ -1294,10 +1323,12 @@ func isDirectLinkRefreshFunc(client *directlinkv1.DirectLinkV1, id string) resou
getOptions := &directlinkv1.GetGatewayOptions{
ID: &id,
}
instance, response, err := client.GetGateway(getOptions)
if err != nil {
instanceIntf, response, err := client.GetGateway(getOptions)
if (err != nil) || (instanceIntf == nil) {
return nil, "", fmt.Errorf("[ERROR] Error Getting Direct Link: %s\n%s", err, response)
}

instance := instanceIntf.(*directlinkv1.GetGatewayResponse)
if *instance.OperationalStatus == "provisioned" || *instance.OperationalStatus == "failed" || *instance.OperationalStatus == "create_rejected" {
return instance, dlGatewayProvisioningDone, nil
}
Expand All @@ -1316,15 +1347,14 @@ func resourceIBMdlGatewayUpdate(d *schema.ResourceData, meta interface{}) error
getOptions := &directlinkv1.GetGatewayOptions{
ID: &ID,
}
instance, detail, err := directLink.GetGateway(getOptions)
instanceIntf, detail, err := directLink.GetGateway(getOptions)

if err != nil {
if (err != nil) || (instanceIntf == nil) {
log.Printf("Error fetching Direct Link Gateway :%s", detail)
return err
}

updateGatewayOptionsModel := &directlinkv1.UpdateGatewayOptions{}
updateGatewayOptionsModel.ID = &ID
instance := instanceIntf.(*directlinkv1.GetGatewayResponse)
gatewayPatchTemplateModel := map[string]interface{}{}
dtype := *instance.Type

if d.HasChange(dlTags) {
Expand All @@ -1338,23 +1368,23 @@ func resourceIBMdlGatewayUpdate(d *schema.ResourceData, meta interface{}) error

if d.HasChange(dlName) {
name := d.Get(dlName).(string)
updateGatewayOptionsModel.Name = &name
gatewayPatchTemplateModel["name"] = &name
}
if d.HasChange(dlSpeedMbps) {
speed := int64(d.Get(dlSpeedMbps).(int))
updateGatewayOptionsModel.SpeedMbps = &speed
gatewayPatchTemplateModel["speed_mbps"] = &speed
}
if d.HasChange(dlBgpAsn) {
bgpAsn := int64(d.Get(dlBgpAsn).(int))
updateGatewayOptionsModel.BgpAsn = &bgpAsn
gatewayPatchTemplateModel["bgp_asn"] = &bgpAsn
}
if d.HasChange(dlBgpCerCidr) {
bgpCerCidr := d.Get(dlBgpCerCidr).(string)
updateGatewayOptionsModel.BgpCerCidr = &bgpCerCidr
gatewayPatchTemplateModel["bgp_cer_cidr"] = &bgpCerCidr
}
if d.HasChange(dlBgpIbmCidr) {
bgpIbmCidr := d.Get(dlBgpIbmCidr).(string)
updateGatewayOptionsModel.BgpIbmCidr = &bgpIbmCidr
gatewayPatchTemplateModel["bgp_ibm_cidr"] = &bgpIbmCidr
}
if d.HasChange(dlAsPrepends) {
listGatewayAsPrependsOptions := directLink.NewListGatewayAsPrependsOptions(ID)
Expand Down Expand Up @@ -1522,29 +1552,29 @@ func resourceIBMdlGatewayUpdate(d *schema.ResourceData, meta interface{}) error
}
*/
if d.HasChange(dlDefault_export_route_filter) {
updateGatewayOptionsModel.DefaultExportRouteFilter = NewStrPointer(d.Get(dlDefault_export_route_filter).(string))
gatewayPatchTemplateModel["default_export_route_filter"] = NewStrPointer(d.Get(dlDefault_export_route_filter).(string))
}
if d.HasChange(dlDefault_import_route_filter) {
updateGatewayOptionsModel.DefaultImportRouteFilter = NewStrPointer(d.Get(dlDefault_import_route_filter).(string))
gatewayPatchTemplateModel["default_import_route_filter"] = NewStrPointer(d.Get(dlDefault_import_route_filter).(string))
}
if d.HasChange(dlGlobal) {
global := d.Get(dlGlobal).(bool)
updateGatewayOptionsModel.Global = &global
gatewayPatchTemplateModel["global"] = &global
}
if d.HasChange(dlMetered) {
metered := d.Get(dlMetered).(bool)
updateGatewayOptionsModel.Metered = &metered
gatewayPatchTemplateModel["metered"] = &metered
}
if d.HasChange(dlAuthenticationKey) {
authenticationKeyCrn := d.Get(dlAuthenticationKey).(string)
authenticationKeyPatchTemplate := new(directlinkv1.GatewayPatchTemplateAuthenticationKey)
authenticationKeyPatchTemplate.Crn = &authenticationKeyCrn
updateGatewayOptionsModel = updateGatewayOptionsModel.SetAuthenticationKey(authenticationKeyPatchTemplate)
gatewayPatchTemplateModel["authentication_key"] = authenticationKeyPatchTemplate
}

if mode, ok := d.GetOk(dlConnectionMode); ok && d.HasChange(dlConnectionMode) {
updatedConnectionMode := mode.(string)
updateGatewayOptionsModel.ConnectionMode = &updatedConnectionMode
gatewayPatchTemplateModel["connection_mode"] = &updatedConnectionMode
}

var updatedBfdConfig directlinkv1.GatewayBfdPatchTemplate
Expand All @@ -1559,7 +1589,7 @@ func resourceIBMdlGatewayUpdate(d *schema.ResourceData, meta interface{}) error
}

if !reflect.DeepEqual(updatedBfdConfig, directlinkv1.GatewayBfdPatchTemplate{}) {
updateGatewayOptionsModel.BfdConfig = &updatedBfdConfig
gatewayPatchTemplateModel["bfd_config"] = &updatedBfdConfig
}

if dtype == "dedicated" {
Expand Down Expand Up @@ -1596,14 +1626,28 @@ func resourceIBMdlGatewayUpdate(d *schema.ResourceData, meta interface{}) error
gatewayMacsecConfigTemplatePatchModel.WindowSize = &windowSizeint
}
}
updateGatewayOptionsModel.MacsecConfig = gatewayMacsecConfigTemplatePatchModel
gatewayPatchTemplateModel["macsec_config"] = gatewayMacsecConfigTemplatePatchModel
} else {
updateGatewayOptionsModel.MacsecConfig = nil
gatewayPatchTemplateModel["macsec_config"] = nil
}
if d.HasChange(dlVlan) {
if _, ok := d.GetOk(dlVlan); ok {
vlan := int64(d.Get(dlVlan).(int))
gatewayPatchTemplateModel["vlan"] = &vlan
}
}
if removeVlanOk, ok := d.GetOk(dlRemoveVlan); ok && !d.IsNewResource() {
removeVlan := removeVlanOk.(bool)
if removeVlan {
gatewayPatchTemplateModel["vlan"] = nil
}
}
}
name := d.Get(dlName).(string)
updateGatewayOptionsModel.Name = &name
_, response, err := directLink.UpdateGateway(updateGatewayOptionsModel)
gatewayPatchTemplateModel["name"] = &name

patchGatewayOptions := directLink.NewUpdateGatewayOptions(ID, gatewayPatchTemplateModel)
_, response, err := directLink.UpdateGateway(patchGatewayOptions)
if err != nil {
log.Printf("[DEBUG] Update Direct Link Gateway err %s\n%s", err, response)
return err
Expand Down Expand Up @@ -1645,13 +1689,15 @@ func resourceIBMdlGatewayExists(d *schema.ResourceData, meta interface{}) (bool,
getOptions := &directlinkv1.GetGatewayOptions{
ID: &ID,
}
_, response, err := directLink.GetGateway(getOptions)
if err != nil {
instanceIntf, response, err := directLink.GetGateway(getOptions)

if (err != nil) || (instanceIntf == nil) {
if response != nil && response.StatusCode == 404 {
d.SetId("")
return false, nil
}
return false, fmt.Errorf("[ERROR] Error Getting Direct Link Gateway : %s\n%s", err, response)
}
_ = instanceIntf.(*directlinkv1.GetGatewayResponse)
return true, nil
}
30 changes: 20 additions & 10 deletions ibm/service/directlink/resource_ibm_dl_gateway_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,14 +818,16 @@ func resourceIBMdlGatewayActionRead(d *schema.ResourceData, meta interface{}) er
getOptions := &directlinkv1.GetGatewayOptions{
ID: &ID,
}
instance, response, err := directLink.GetGateway(getOptions)
if err != nil {
instanceIntf, response, err := directLink.GetGateway(getOptions)

if (err != nil) || (instanceIntf == nil) {
if response != nil && response.StatusCode == 404 {
d.SetId("")
return nil
}
return fmt.Errorf("[ERROR] Error Getting Direct Link Gateway: %s\n%s", err, response)
}
instance := instanceIntf.(*directlinkv1.GetGatewayResponse)
if instance.Name != nil {
d.Set(dlName, *instance.Name)
}
Expand Down Expand Up @@ -993,10 +995,12 @@ func isDirectLinkRefreshFuncforAction(client *directlinkv1.DirectLinkV1, id stri
getOptions := &directlinkv1.GetGatewayOptions{
ID: &id,
}
instance, response, err := client.GetGateway(getOptions)
if err != nil {

instanceIntf, response, err := client.GetGateway(getOptions)
if (err != nil) || (instanceIntf == nil) {
return nil, "", fmt.Errorf("[ERROR] Error Getting Direct Link: %s\n%s", err, response)
}
instance := instanceIntf.(*directlinkv1.GetGatewayResponse)
if *instance.OperationalStatus == "provisioned" || *instance.OperationalStatus == "failed" || *instance.OperationalStatus == "create_rejected" {
return instance, dlGatewayProvisioningDone, nil
}
Expand All @@ -1021,10 +1025,12 @@ func isDirectLinkRefreshActionFunc(client *directlinkv1.DirectLinkV1, id string)
getOptions := &directlinkv1.GetGatewayOptions{
ID: &id,
}
instance, response, err := client.GetGateway(getOptions)
if err != nil {
instanceIntf, response, err := client.GetGateway(getOptions)

if (err != nil) || (instanceIntf == nil) {
return nil, "", fmt.Errorf("[ERROR] Error Getting Direct Link: %s\n%s", err, response)
}
instance := instanceIntf.(*directlinkv1.GetGatewayResponse)
if instance.ChangeRequest != nil {
gatewayChangeRequestIntf := instance.ChangeRequest
gatewayChangeRequest := gatewayChangeRequestIntf.(*directlinkv1.GatewayChangeRequest)
Expand Down Expand Up @@ -1053,10 +1059,12 @@ func isDirectLinkRefreshDeleteActionFunc(client *directlinkv1.DirectLinkV1, id s
getOptions := &directlinkv1.GetGatewayOptions{
ID: &id,
}
instance, response, err := client.GetGateway(getOptions)
if err != nil {
instanceIntf, response, err := client.GetGateway(getOptions)

if (err != nil) || (instanceIntf == nil) {
return nil, "", fmt.Errorf("[ERROR] Error Getting Direct Link: %s\n%s", err, response)
}
instance := instanceIntf.(*directlinkv1.GetGatewayResponse)
if instance.ChangeRequest != nil {
gatewayChangeRequestIntf := instance.ChangeRequest
gatewayChangeRequest := gatewayChangeRequestIntf.(*directlinkv1.GatewayChangeRequest)
Expand Down Expand Up @@ -1090,14 +1098,16 @@ func resourceIBMdlGatewayActionUpdate(d *schema.ResourceData, meta interface{})
if err != nil {
return err
}
instance, response, err := directLink.GetGateway(getOptions)
if err != nil {
instanceIntf, response, err := directLink.GetGateway(getOptions)

if (err != nil) || (instanceIntf == nil) {
if response != nil && response.StatusCode == 404 {
d.SetId("")
return nil
}
return fmt.Errorf("[ERROR] Error Getting Direct Link Gateway : %s\n%s", err, response)
}
instance := instanceIntf.(*directlinkv1.GetGatewayResponse)
if instance.ChangeRequest != nil {
gatewayChangeRequestIntf := instance.ChangeRequest
gatewayChangeRequest := gatewayChangeRequestIntf.(*directlinkv1.GatewayChangeRequest)
Expand Down
Loading
Loading