Skip to content

Commit

Permalink
feat: implement resource and data sources to create and fetch direct …
Browse files Browse the repository at this point in the history
…link route reports (#4065)

* feat: implement resource and data sources for direct link route report

* chore: update the example for route report resource

* chore: removed logs which are not needed

* addressed review comments

* addressed review comments

* addressed review comments

* return nil in case the returned response code is 404 for dl route report resource

* added the documentation for AS Prepends for directlink resource and datasource

* added the documentation for AS Prepends for directlink resource and datasource

* added the documentation for AS Prepends for directlink resource and datasource

* added the documentation for AS Prepends for directlink resource and datasource

* added the documentation for AS Prepends for directlink resource and datasource
  • Loading branch information
ajay-malhotra1 authored Oct 14, 2022
1 parent ac46532 commit 3253ad1
Show file tree
Hide file tree
Showing 21 changed files with 1,757 additions and 71 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20211109141421-a4b61b05f7d1
github.com/IBM/ibm-hpcs-uko-sdk v0.0.4
github.com/IBM/keyprotect-go-client v0.7.0
github.com/IBM/networking-go-sdk v0.33.0
github.com/IBM/networking-go-sdk v0.34.0
github.com/IBM/platform-services-go-sdk v0.28.5
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
github.com/IBM/scc-go-sdk/v3 v3.1.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ github.com/IBM/ibm-hpcs-uko-sdk v0.0.4 h1:B3FEq830k/B7HjQqvQubxmz8PxOUvKYD2ZypDq
github.com/IBM/ibm-hpcs-uko-sdk v0.0.4/go.mod h1:MLVNHMYoKsvovJZ4v1gQCpIYtRDHTtoIHK6XztDZGsU=
github.com/IBM/keyprotect-go-client v0.7.0 h1:JstSHD14Lp6ihwQseyPuGcs1AjOBjAmcisP0dTBA6A0=
github.com/IBM/keyprotect-go-client v0.7.0/go.mod h1:SVr2ylV/fhSQPDiUjWirN9fsyWFCNNbt8GIT8hPJVjE=
github.com/IBM/networking-go-sdk v0.33.0 h1:+e4Q/io0y/I+LHKSa95gUM+CJfya6gHOelSWi+hkvBA=
github.com/IBM/networking-go-sdk v0.33.0/go.mod h1:7b/E21A6BmfycDuNmHjA+EhFm9iM8Wm4ULF9g93J+KE=
github.com/IBM/networking-go-sdk v0.34.0 h1:E8H+v8ipie3vk9w+jvNm8TBeVNrUhqUAKWQOYw9POEc=
github.com/IBM/networking-go-sdk v0.34.0/go.mod h1:tDJtlySQC/txyejU9KeQ27Amc6xKH0MwHFE/B2+Sn5w=
github.com/IBM/platform-services-go-sdk v0.28.5 h1:wVwapdVU3+J/JtS0P6WYi21gqsm1pX/MH4UX69c3+5E=
github.com/IBM/platform-services-go-sdk v0.28.5/go.mod h1:jy0Ahvj5Gkkua3Gd7t22bo0GfmHRQaPZcaqwfVgEY7k=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5 h1:NPUhkoOCRuv3OFWt19PmwjXGGTKlvmbuPg9fUrBUNe4=
Expand Down
3 changes: 3 additions & 0 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ func Provider() *schema.Provider {
"ibm_dl_routers": directlink.DataSourceIBMDLRouters(),
"ibm_dl_provider_ports": directlink.DataSourceIBMDirectLinkProviderPorts(),
"ibm_dl_provider_gateways": directlink.DataSourceIBMDirectLinkProviderGateways(),
"ibm_dl_route_reports": directlink.DataSourceIBMDLRouteReports(),
"ibm_dl_route_report": directlink.DataSourceIBMDLRouteReport(),

// //Added for Transit Gateway
"ibm_tg_gateway": transitgateway.DataSourceIBMTransitGateway(),
Expand Down Expand Up @@ -1023,6 +1025,7 @@ func Provider() *schema.Provider {
"ibm_dl_gateway": directlink.ResourceIBMDLGateway(),
"ibm_dl_virtual_connection": directlink.ResourceIBMDLGatewayVC(),
"ibm_dl_provider_gateway": directlink.ResourceIBMDLProviderGateway(),
"ibm_dl_route_report": directlink.ResourceIBMDLGatewayRouteReport(),
// //Added for Transit Gateway
"ibm_tg_gateway": transitgateway.ResourceIBMTransitGateway(),
"ibm_tg_connection": transitgateway.ResourceIBMTransitGatewayConnection(),
Expand Down
94 changes: 94 additions & 0 deletions ibm/service/directlink/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright IBM Corp. 2022 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package directlink

const (
dlGatewaysVirtualConnections = "gateway_vcs"
dlVCNetworkAccount = "network_account"
dlVCNetworkId = "network_id"
dlVCName = "name"
dlVCType = "type"
dlVCCreatedAt = "created_at"
dlVCStatus = "status"
dlGatewayId = "gateway"
ID = "id"
dlVirtualConnectionId = "virtual_connection_id"
dlVirtualConnectionName = "virtual_connection_name"
dlVirtualConnectionType = "virtual_connection_type"
dlActive = "active"
dlAsPrepends = "as_prepends"
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"
dlLength = "length"
dlLoaRejectReason = "loa_reject_reason"
dlLocationDisplayName = "location_display_name"
dlLocationName = "location_name"
dlLinkStatus = "link_status"
dlMacSecConfig = "macsec_config"
dlMetered = "metered"
dlName = "name"
dlOperationalStatus = "operational_status"
dlPolicy = "policy"
dlPort = "port"
dlPrimaryCak = "primary_cak"
dlProviderAPIManaged = "provider_api_managed"
dlGatewayProvisioningDone = "provisioned"
dlResourceGroup = "resource_group"
dlSakExpiryTime = "sak_expiry_time"
dlSpeedMbps = "speed_mbps"
dlMacSecConfigStatus = "status"
dlTags = "tags"
dlType = "type"
dlUpdatedAt = "updated_at"
dlVlan = "vlan"
dlWindowSize = "window_size"
customerAccountID = "customer_account_id"
dlRouteReports = "route_reports"
dlPrefix = "prefix"
dlRouteReportNextHop = "next_hop"
dlGatewayRoutes = "gateway_routes"
dlOnPremRoutes = "on_prem_routes"
dlOverlappingRoutes = "overlapping_routes"
dlRoutes = "routes"
dlRouteReportStatus = "status"
dlVirtualConnectionRoutes = "virtual_connection_routes"
dlId = "id"
dlRouteReportPending = "pending"
dlRouteReportComplete = "complete"
dlRouteReportId = "route_report_id"
dlResourceId = "id"
)

func NewInt64Pointer(v int64) *int64 {
return &v
}

func NewStrPointer(v string) *string {
return &v
}
58 changes: 58 additions & 0 deletions ibm/service/directlink/data_source_ibm_dl_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,45 @@ func DataSourceIBMDLGateway() *schema.Resource {
},
},

dlAsPrepends: {
Type: schema.TypeList,
Computed: true,
Description: "List of AS Prepend configuration information",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
dlCreatedAt: {
Type: schema.TypeString,
Computed: true,
Description: "The date and time AS Prepend was created",
},
ID: {
Type: schema.TypeString,
Computed: true,
Description: "The date and time AS Prepend was created",
},
dlLength: {
Type: schema.TypeInt,
Computed: true,
Description: "Number of times the ASN to appended to the AS Path",
},
dlPolicy: {
Type: schema.TypeString,
Computed: true,
Description: "Route type this AS Prepend applies to",
},
dlPrefix: {
Type: schema.TypeString,
Computed: true,
Description: "Comma separated list of prefixes this AS Prepend applies to. Maximum of 10 prefixes. If not specified, this AS Prepend applies to all prefixes.",
},
dlUpdatedAt: {
Type: schema.TypeString,
Computed: true,
Description: "The date and time AS Prepend was updated",
},
},
},
},
dlAuthenticationKey: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -446,6 +485,25 @@ func dataSourceIBMDLGatewayRead(d *schema.ResourceData, meta interface{}) error
d.Set(dlBfdStatusUpdatedAt, instance.BfdConfig.BfdStatusUpdatedAt.String())
}
}

asPrependList := make([]map[string]interface{}, 0)
if len(instance.AsPrepends) > 0 {
for _, asPrepend := range instance.AsPrepends {
asPrependItem := map[string]interface{}{}
asPrependItem[dlResourceId] = asPrepend.ID
asPrependItem[dlLength] = asPrepend.Length
asPrependItem[dlPrefix] = asPrepend.Prefix
asPrependItem[dlPolicy] = asPrepend.Policy
asPrependItem[dlCreatedAt] = asPrepend.CreatedAt.String()
asPrependItem[dlUpdatedAt] = asPrepend.UpdatedAt.String()

asPrependList = append(asPrependList, asPrependItem)
}

}

d.Set(dlAsPrepends, asPrependList)

dtype := *instance.Type
if dtype == "dedicated" {
if instance.MacsecConfig != nil {
Expand Down
56 changes: 56 additions & 0 deletions ibm/service/directlink/data_source_ibm_dl_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,45 @@ func DataSourceIBMDLGateways() *schema.Resource {
Computed: true,
Description: "Id of the data source gateways",
},
dlAsPrepends: {
Type: schema.TypeList,
Computed: true,
Description: "List of AS Prepend configuration information",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
dlCreatedAt: {
Type: schema.TypeString,
Computed: true,
Description: "The date and time AS Prepend was created",
},
ID: {
Type: schema.TypeString,
Computed: true,
Description: "The date and time AS Prepend was created",
},
dlLength: {
Type: schema.TypeInt,
Computed: true,
Description: "Number of times the ASN to appended to the AS Path",
},
dlPolicy: {
Type: schema.TypeString,
Computed: true,
Description: "Route type this AS Prepend applies to",
},
dlPrefix: {
Type: schema.TypeString,
Computed: true,
Description: "Comma separated list of prefixes this AS Prepend applies to. Maximum of 10 prefixes. If not specified, this AS Prepend applies to all prefixes.",
},
dlUpdatedAt: {
Type: schema.TypeString,
Computed: true,
Description: "The date and time AS Prepend was updated",
},
},
},
},
dlAuthenticationKey: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -362,6 +401,23 @@ func dataSourceIBMDLGatewaysRead(d *schema.ResourceData, meta interface{}) error
}
}

asPrependList := make([]map[string]interface{}, 0)
if len(instance.AsPrepends) > 0 {
for _, asPrepend := range instance.AsPrepends {
asPrependItem := map[string]interface{}{}
asPrependItem[dlResourceId] = asPrepend.ID
asPrependItem[dlLength] = asPrepend.Length
asPrependItem[dlPrefix] = asPrepend.Prefix
asPrependItem[dlPolicy] = asPrepend.Policy
asPrependItem[dlCreatedAt] = asPrepend.CreatedAt.String()
asPrependItem[dlUpdatedAt] = asPrepend.UpdatedAt.String()

asPrependList = append(asPrependList, asPrependItem)
}

}
gateway[dlAsPrepends] = asPrependList

dtype := *instance.Type
if dtype == "dedicated" {
if instance.MacsecConfig != nil {
Expand Down
Loading

0 comments on commit 3253ad1

Please sign in to comment.