Skip to content

Commit

Permalink
feat: adding MD5 authentication key for Direct link Resources, DataSo…
Browse files Browse the repository at this point in the history
…urces and Documents
  • Loading branch information
ajay-malhotra1 authored and hkantare committed Jul 1, 2021
1 parent ea91d84 commit 2577b90
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ website/vendor
*.attach
*.xml
*.old
vendor/

# Test exclusions
!command/test-fixtures/**/*.tfstate
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/IBM/ibm-cos-sdk-go v1.7.0
github.com/IBM/ibm-cos-sdk-go-config v1.2.0
github.com/IBM/keyprotect-go-client v0.7.0
github.com/IBM/networking-go-sdk v0.17.0
github.com/IBM/networking-go-sdk v0.18.0
github.com/IBM/platform-services-go-sdk v0.18.16
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
github.com/IBM/schematics-go-sdk v0.0.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ github.com/IBM/keyprotect-go-client v0.7.0 h1:JstSHD14Lp6ihwQseyPuGcs1AjOBjAmcis
github.com/IBM/keyprotect-go-client v0.7.0/go.mod h1:SVr2ylV/fhSQPDiUjWirN9fsyWFCNNbt8GIT8hPJVjE=
github.com/IBM/networking-go-sdk v0.17.0 h1:AkP0aFX8ZfkHT7LDUOD1DtcImZWXqrlTr5eHlCgDcC4=
github.com/IBM/networking-go-sdk v0.17.0/go.mod h1:nViqUm1Bv+ke8dyOhjQ6e+2U1XeqZX2y4bQbR8Od3Hc=
github.com/IBM/networking-go-sdk v0.18.0 h1:mlALxXptnoDGviRW59ZQTyCr4PgTdQKp/5ksh2NM6Sk=
github.com/IBM/networking-go-sdk v0.18.0/go.mod h1:nViqUm1Bv+ke8dyOhjQ6e+2U1XeqZX2y4bQbR8Od3Hc=
github.com/IBM/platform-services-go-sdk v0.18.16 h1:blYycstPoNtPKtu1uZe240WvzcJENy/Lzx+HMUA8bOo=
github.com/IBM/platform-services-go-sdk v0.18.16/go.mod h1:awc7TZUeGMlToSeMSaWEz34Knf0lQnuGWumcI4pcuoM=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5 h1:NPUhkoOCRuv3OFWt19PmwjXGGTKlvmbuPg9fUrBUNe4=
Expand Down
9 changes: 9 additions & 0 deletions ibm/data_source_ibm_dl_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func dataSourceIBMDLGateway() *schema.Resource {
},
},

dlAuthenticationKey: {
Type: schema.TypeString,
Computed: true,
Description: "BGP MD5 authentication key",
},
dlBgpAsn: {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -456,6 +461,10 @@ func dataSourceIBMDLGatewayRead(d *schema.ResourceData, meta interface{}) error
d.Set(dlResourceGroup, *rg.ID)
}

if instance.AuthenticationKey != nil {
d.Set(dlAuthenticationKey, *instance.AuthenticationKey.Crn)
}

}
}

Expand Down
10 changes: 10 additions & 0 deletions ibm/data_source_ibm_dl_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func dataSourceIBMDLGateways() *schema.Resource {
Computed: true,
Description: "Id of the data source gateways",
},
dlAuthenticationKey: {
Type: schema.TypeString,
Computed: true,
Description: "BGP MD5 authentication key",
},
dlBgpAsn: {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -368,6 +373,11 @@ func dataSourceIBMDLGatewaysRead(d *schema.ResourceData, meta interface{}) error
gatewayChangeRequest := gatewayChangeRequestIntf.(*directlinkv1.GatewayChangeRequest)
gateway[dlChangeRequest] = *gatewayChangeRequest.Type
}

if instance.AuthenticationKey != nil {
gateway[dlAuthenticationKey] = *instance.AuthenticationKey.Crn
}

gateways = append(gateways, gateway)
}
d.SetId(dataSourceIBMDLGatewaysID(d))
Expand Down
29 changes: 29 additions & 0 deletions ibm/resource_ibm_dl_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
dlGatewayProvisioning = "configuring"
dlGatewayProvisioningDone = "provisioned"
dlGatewayProvisioningRejected = "create_rejected"
dlAuthenticationKey = "authentication_key"
)

func resourceIBMDLGateway() *schema.Resource {
Expand All @@ -84,6 +85,12 @@ func resourceIBMDLGateway() *schema.Resource {
),

Schema: map[string]*schema.Schema{
dlAuthenticationKey: {
Type: schema.TypeString,
Optional: true,
ForceNew: false,
Description: "BGP MD5 authentication key",
},
dlBgpAsn: {
Type: schema.TypeInt,
Required: true,
Expand Down Expand Up @@ -503,6 +510,12 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error
}
gatewayDedicatedTemplateModel.MacsecConfig = gatewayMacsecConfigTemplateModel
}

if authKeyCrn, ok := d.GetOk(dlAuthenticationKey); ok {
authKeyCrnStr := authKeyCrn.(string)
gatewayDedicatedTemplateModel.AuthenticationKey = &directlinkv1.GatewayTemplateAuthenticationKey{Crn: &authKeyCrnStr}
}

createGatewayOptionsModel.GatewayTemplate = gatewayDedicatedTemplateModel

} else if dtype == "connect" {
Expand Down Expand Up @@ -533,6 +546,12 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error
gatewayConnectTemplateModel.ResourceGroup = &directlinkv1.ResourceGroupIdentity{ID: &resourceGroup}

}

if authKeyCrn, ok := d.GetOk(dlAuthenticationKey); ok {
authKeyCrnStr := authKeyCrn.(string)
gatewayConnectTemplateModel.AuthenticationKey = &directlinkv1.GatewayTemplateAuthenticationKey{Crn: &authKeyCrnStr}
}

createGatewayOptionsModel.GatewayTemplate = gatewayConnectTemplateModel

} else {
Expand Down Expand Up @@ -666,6 +685,9 @@ func resourceIBMdlGatewayRead(d *schema.ResourceData, meta interface{}) error {
if instance.CreatedAt != nil {
d.Set(dlCreatedAt, instance.CreatedAt.String())
}
if instance.AuthenticationKey != nil {
d.Set(dlAuthenticationKey, *instance.AuthenticationKey.Crn)
}
if dtype == "dedicated" {
if instance.MacsecConfig != nil {
macsecList := make([]map[string]interface{}, 0)
Expand Down Expand Up @@ -835,6 +857,13 @@ func resourceIBMdlGatewayUpdate(d *schema.ResourceData, meta interface{}) error
metered := d.Get(dlMetered).(bool)
updateGatewayOptionsModel.Metered = &metered
}
if d.HasChange(dlAuthenticationKey) {
authenticationKeyCrn := d.Get(dlAuthenticationKey).(string)
authenticationKeyPatchTemplate := new(directlinkv1.GatewayPatchTemplateAuthenticationKey)
authenticationKeyPatchTemplate.Crn = &authenticationKeyCrn
updateGatewayOptionsModel = updateGatewayOptionsModel.SetAuthenticationKey(authenticationKeyPatchTemplate)
}

if dtype == "dedicated" {
if d.HasChange(dlMacSecConfig) && !d.IsNewResource() {
// Construct an instance of the GatewayMacsecConfigTemplate model
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/dl_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Review the argument reference that you can specify for your resource.
## Attribute reference
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.
- `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
1 change: 1 addition & 0 deletions website/docs/d/dl_gateways.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ You can access the following attribute references after your data source is crea
- `gateways` - (String) List of all the Direct Link Gateways in the IBM Cloud infrastructure.

Nested scheme for `gateways`:
- `authentication_key` - (String) BGP MD5 authentication key.
- `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
1 change: 1 addition & 0 deletions website/docs/r/dl_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ resource "ibm_dl_gateway" "test_dl_connect" {
## Argument reference
Review the argument reference that you can specify for your resource.

- `authentication_key` - (Optional, String) BGP MD5 authentication key.
- `bgp_asn`- (Required, Forces new resource, Integer) The BGP ASN of the gateway to be created. For example, `64999`.
- `bgp_base_cidr` - (Optional, String) (Deprecated) The BGP base CIDR of the gateway to be created. See `bgp_ibm_cidr` and `bgp_cer_cidr` for details on how to create a gateway by using automatic or explicit IP assignment. Any `bgp_base_cidr` value set will be ignored.
- `bgp_cer_cidr` - (Optional, Forces new resource, String) The BGP customer edge router CIDR. Specify a value within `bgp_base_cidr`. For auto IP assignment, omit `bgp_cer_cidr` and `bgp_ibm_cidr`. IBM will automatically select values for `bgp_cer_cidr` and `bgp_ibm_cidr`.
Expand Down

0 comments on commit 2577b90

Please sign in to comment.