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

Adding new resources to support BGP Route Filters in direct link gateway #4294

Merged
merged 12 commits into from
Apr 10, 2023
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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.9.0
github.com/IBM/networking-go-sdk v0.36.0
github.com/IBM/networking-go-sdk v0.40.0
github.com/IBM/platform-services-go-sdk v0.34.0
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
github.com/IBM/scc-go-sdk/v3 v3.1.6
Expand Down
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ github.com/IBM/go-sdk-core/v5 v5.5.1/go.mod h1:Sn+z+qTDREQvCr+UFa22TqqfXNxx3o723
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/go.mod h1:tt/B9rxLkRtglE7pvqLuYikgCXaZFL3btdruJaoUeek=
github.com/IBM/go-sdk-core/v5 v5.7.0/go.mod h1:+YbdhrjCHC84ls4MeBp+Hj4NZCni+tDAc0XQUqRO9Jc=
github.com/IBM/go-sdk-core/v5 v5.8.0/go.mod h1:+YbdhrjCHC84ls4MeBp+Hj4NZCni+tDAc0XQUqRO9Jc=
github.com/IBM/go-sdk-core/v5 v5.9.2/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE=
github.com/IBM/go-sdk-core/v5 v5.9.5/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE=
github.com/IBM/go-sdk-core/v5 v5.10.2/go.mod h1:WZPFasUzsKab/2mzt29xPcfruSk5js2ywAPwW4VJjdI=
Expand All @@ -88,8 +87,8 @@ github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta h1:P1fdIfKsD9xvJQ5MHIEztPS9yfNf9x+V
github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta/go.mod h1:MLVNHMYoKsvovJZ4v1gQCpIYtRDHTtoIHK6XztDZGsU=
github.com/IBM/keyprotect-go-client v0.9.0 h1:UwbyEHcaGlmLNK7PW0qo9VlxneN+0/2zoGBubHzbtro=
github.com/IBM/keyprotect-go-client v0.9.0/go.mod h1:yr8h2noNgU8vcbs+vhqoXp3Lmv73PI0zAc6VMgFvWwM=
github.com/IBM/networking-go-sdk v0.36.0 h1:ADntTsRM8DMZOxS9TYGTAL6i0zw9V2L7OeLFd9Czntk=
github.com/IBM/networking-go-sdk v0.36.0/go.mod h1:tDJtlySQC/txyejU9KeQ27Amc6xKH0MwHFE/B2+Sn5w=
github.com/IBM/networking-go-sdk v0.40.0 h1:NdHTG0YXtN2D/B62BRgy6iJRFLdiJtSFCdTzAZB5m5k=
github.com/IBM/networking-go-sdk v0.40.0/go.mod h1:lTUZwtUkMANMnrLHFIgRhHrkBfwASY/Iho1fabaPHxo=
github.com/IBM/platform-services-go-sdk v0.34.0 h1:ozGdyWdBByNS8sw07FP4qx2r1qUc59D0BoN3rMTgtIk=
github.com/IBM/platform-services-go-sdk v0.34.0/go.mod h1:oFW/DQyAXGBcGytB+DtKjE3yNdEGM2bmw5SDOjrRwTw=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5 h1:NPUhkoOCRuv3OFWt19PmwjXGGTKlvmbuPg9fUrBUNe4=
Expand Down Expand Up @@ -685,7 +684,7 @@ github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9
github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
github.com/onsi/gomega v1.21.1/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc=
github.com/onsi/gomega v1.27.1 h1:rfztXRbg6nv/5f+Raen9RcGoSecHIFgBBLQK3Wdj754=
github.com/onsi/gomega v1.27.2 h1:SKU0CXeKE/WVgIV1T61kSa3+IRE8Ekrv9rdXDwwTqnY=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
Expand Down
27 changes: 16 additions & 11 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,17 +611,21 @@ func Provider() *schema.Provider {

// // Added for Direct Link

"ibm_dl_gateways": directlink.DataSourceIBMDLGateways(),
"ibm_dl_offering_speeds": directlink.DataSourceIBMDLOfferingSpeeds(),
"ibm_dl_port": directlink.DataSourceIBMDirectLinkPort(),
"ibm_dl_ports": directlink.DataSourceIBMDirectLinkPorts(),
"ibm_dl_gateway": directlink.DataSourceIBMDLGateway(),
"ibm_dl_locations": directlink.DataSourceIBMDLLocations(),
"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(),
"ibm_dl_gateways": directlink.DataSourceIBMDLGateways(),
"ibm_dl_offering_speeds": directlink.DataSourceIBMDLOfferingSpeeds(),
"ibm_dl_port": directlink.DataSourceIBMDirectLinkPort(),
"ibm_dl_ports": directlink.DataSourceIBMDirectLinkPorts(),
"ibm_dl_gateway": directlink.DataSourceIBMDLGateway(),
"ibm_dl_locations": directlink.DataSourceIBMDLLocations(),
"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(),
"ibm_dl_export_route_filters": directlink.DataSourceIBMDLExportRouteFilters(),
"ibm_dl_export_route_filter": directlink.DataSourceIBMDLExportRouteFilter(),
"ibm_dl_import_route_filters": directlink.DataSourceIBMDLImportRouteFilters(),
"ibm_dl_import_route_filter": directlink.DataSourceIBMDLImportRouteFilter(),

// //Added for Transit Gateway
"ibm_tg_gateway": transitgateway.DataSourceIBMTransitGateway(),
Expand Down Expand Up @@ -1100,6 +1104,7 @@ func Provider() *schema.Provider {
"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
21 changes: 17 additions & 4 deletions ibm/service/cis/resource_ibm_cis_domain_settings.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Copyright IBM Corp. 2017, 2023 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package cis

import (
"log"

"github.com/IBM/go-sdk-core/v5/core"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const (
Expand Down Expand Up @@ -51,6 +52,7 @@ const (
cisDomainSettingsSecurityHeaderMaxAge = "max_age"
cisDomainSettingsSecurityHeaderIncludeSubdomains = "include_subdomains"
cisDomainSettingsSecurityHeaderNoSniff = "nosniff"
cisDomainSettingsSecurityHeaderPreload = "preload"
cisDomainSettingsMobileRedirect = "mobile_redirect"
sushmitha1506 marked this conversation as resolved.
Show resolved Hide resolved
cisDomainSettingsMobileRedirectStatus = "status"
cisDomainSettingsMobileRedirectMobileSubdomain = "mobile_subdomain"
Expand Down Expand Up @@ -412,6 +414,12 @@ func ResourceIBMCISSettings() *schema.Resource {
Description: "security header no sniff",
Required: true,
},
cisDomainSettingsSecurityHeaderPreload: {
Type: schema.TypeBool,
Description: "security header preload",
Optional: true,
Default: false,
},
},
},
},
Expand Down Expand Up @@ -1030,10 +1038,12 @@ func resourceCISSettingsUpdate(d *schema.ResourceData, meta interface{}) error {
dataMap := v.([]interface{})[0].(map[string]interface{})
enabled := dataMap[cisDomainSettingsSecurityHeaderEnabled].(bool)
nosniff := dataMap[cisDomainSettingsSecurityHeaderNoSniff].(bool)
preload := dataMap[cisDomainSettingsSecurityHeaderPreload].(bool)

includeSubdomain := dataMap[cisDomainSettingsSecurityHeaderIncludeSubdomains].(bool)
maxAge := int64(dataMap[cisDomainSettingsSecurityHeaderMaxAge].(int))
securityVal, err := cisClient.NewSecurityHeaderSettingValueStrictTransportSecurity(
enabled, maxAge, includeSubdomain, nosniff)
enabled, maxAge, includeSubdomain, preload, nosniff)
if err != nil {
log.Println("Invalid security header setting values")
return err
Expand Down Expand Up @@ -1380,6 +1390,9 @@ func resourceCISSettingsRead(d *schema.ResourceData, meta interface{}) error {
if securityHeader.Nosniff != nil {
value[cisDomainSettingsSecurityHeaderNoSniff] = *securityHeader.Nosniff
}
if securityHeader.Preload != nil {
value[cisDomainSettingsSecurityHeaderPreload] = *securityHeader.Preload
}
if securityHeader.IncludeSubdomains != nil {
value[cisDomainSettingsSecurityHeaderIncludeSubdomains] = *securityHeader.IncludeSubdomains
}
Expand Down
5 changes: 3 additions & 2 deletions ibm/service/cis/resource_ibm_cis_domain_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"fmt"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
)

func TestAccIBMCisSettings_Basic(t *testing.T) {
Expand Down Expand Up @@ -153,6 +153,7 @@ func testAccCheckCisSettingsConfigBasic4(id string, CisDomainStatic string) stri
include_subdomains = true
max_age = 100
nosniff = false
preload = false
}
mobile_redirect {
status = "off"
Expand Down
12 changes: 12 additions & 0 deletions ibm/service/directlink/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
dlBgpIbmAsn = "bgp_ibm_asn"
dlBgpIbmCidr = "bgp_ibm_cidr"
dlBgpStatus = "bgp_status"
dlBgpStatusUpdatedAt = "bgp_status_updated_at"
dlCarrierName = "carrier_name"
dlChangeRequest = "change_request"
dlCipherSuite = "cipher_suite"
Expand All @@ -50,6 +51,7 @@ const (
dlLocationDisplayName = "location_display_name"
dlLocationName = "location_name"
dlLinkStatus = "link_status"
dlLinkStatusUpdatedAt = "link_status_updated_at"
dlMacSecConfig = "macsec_config"
dlMetered = "metered"
dlName = "name"
Expand Down Expand Up @@ -83,6 +85,16 @@ const (
dlRouteReportComplete = "complete"
dlRouteReportId = "route_report_id"
dlResourceId = "id"
dlExportRouteFilters = "export_route_filters"
dlImportRouteFilters = "import_route_filters"
dlAction = "action"
dlBefore = "before"
dlGe = "ge"
dlLe = "le"
dlExportRouteFilterId = "ex_filter_id"
dlImportRouteFilterId = "im_filter_id"
dlDefault_export_route_filter = "default_export_route_filter"
dlDefault_import_route_filter = "default_import_route_filter"
)

func NewInt64Pointer(v int64) *int64 {
Expand Down
107 changes: 107 additions & 0 deletions ibm/service/directlink/data_source_ibm_dl_export_route_filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright IBM Corp. 2022 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package directlink

import (
"fmt"
"log"

"github.com/IBM/networking-go-sdk/directlinkv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceIBMDLExportRouteFilter() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMDLExportRouteFilterRead,
Schema: map[string]*schema.Schema{
dlGatewayId: {
Type: schema.TypeString,
Required: true,
Description: "The Direct Link gateway identifier",
},
dlExportRouteFilterId: {
sushmitha1506 marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Required: true,
Description: "Export route Filter identifier",
},
dlAction: {
Type: schema.TypeString,
Computed: true,
Description: "Determines whether the routes that match the prefix-set will be permit or deny",
},
dlBefore: {
Type: schema.TypeString,
Computed: true,
Description: "Identifier of the next route filter to be considered",
},
dlCreatedAt: {
Type: schema.TypeString,
Computed: true,
Description: "The date and time of the export route filter was created",
},
dlGe: {
Type: schema.TypeInt,
Computed: true,
Description: "The minimum matching length of the prefix-set",
},
dlLe: {
Type: schema.TypeInt,
Computed: true,
Description: "The maximum matching length of the prefix-set",
},
dlPrefix: {
Type: schema.TypeString,
Computed: true,
Description: "IP prefix representing an address and mask length of the prefix-set",
},
dlUpdatedAt: {
Type: schema.TypeString,
Computed: true,
Description: "The date and time of the export route filter was last updated",
},
},
}
}

func dataSourceIBMDLExportRouteFilterRead(d *schema.ResourceData, meta interface{}) error {
directLink, err := directlinkClient(meta)
if err != nil {
return err
}
gatewayId := d.Get(dlGatewayId).(string)
exportRouteFilterId := d.Get(dlExportRouteFilterId).(string)
getGatewayExportRouteFilterOptionsModel := &directlinkv1.GetGatewayExportRouteFilterOptions{GatewayID: &gatewayId, ID: &exportRouteFilterId}
exportRouteFilter, response, err := directLink.GetGatewayExportRouteFilter(getGatewayExportRouteFilterOptionsModel)
if err != nil {
log.Println("[ERROR] Error while listing the DL Export Route Filter", response, err)
return err
}
if exportRouteFilter == nil {
return fmt.Errorf("error while reading the Export Route filter for gateway: %s and Export route FilterId: %s with response code: %d", gatewayId, exportRouteFilterId, response.StatusCode)
} else if exportRouteFilter.ID != nil {
d.SetId(*exportRouteFilter.ID)
}
if exportRouteFilter.Action != nil {
d.Set(dlAction, *exportRouteFilter.Action)
}
if exportRouteFilter.Before != nil {
d.Set(dlBefore, *exportRouteFilter.Before)
}
if exportRouteFilter.CreatedAt != nil {
d.Set(dlCreatedAt, exportRouteFilter.CreatedAt.String())
}
if exportRouteFilter.Prefix != nil {
d.Set(dlPrefix, *exportRouteFilter.Prefix)
}
if exportRouteFilter.UpdatedAt != nil {
d.Set(dlUpdatedAt, exportRouteFilter.UpdatedAt.String())
}
if exportRouteFilter.Ge != nil {
d.Set(dlGe, *exportRouteFilter.Ge)
}
if exportRouteFilter.Le != nil {
d.Set(dlLe, *exportRouteFilter.Le)
}
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright IBM Corp. 2023 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package directlink_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
)

func TestAccIBMDLExportRouteFilterDataSource_basic(t *testing.T) {
node := "data.ibm_dl_export_route_filter.test_dl_export_route_filter"
gatewayname := fmt.Sprintf("gateway-name1-%d", acctest.RandIntRange(10, 100))

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMDLExportRouteFilterDataSourceConfig(gatewayname),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(node, "action"),
),
},
},
})
}

func testAccCheckIBMDLExportRouteFilterDataSourceConfig(gatewayname string) string {
return fmt.Sprintf(`
data "ibm_dl_ports" "ds_dlports" {
}
resource ibm_dl_gateway test_dl_gateway {
bgp_asn = 64999
global = true
metered = false
name = "%s"
speed_mbps = 1000
type = "connect"
port = data.ibm_dl_ports.ds_dlports.ports[0].port_id
export_route_filters {
action = "deny"
prefix = "10.10.9.0/24"
ge =25
le = 27
}
}
data "ibm_dl_export_route_filters" "test_dl_export_route_filters" {
gateway = ibm_dl_gateway.test_dl_gateway.id
}
data "ibm_dl_export_route_filter" "test_dl_export_route_filter" {
gateway = ibm_dl_gateway.test_dl_gateway.id
id = data.ibm_dl_export_route_filters.test_dl_export_route_filters.export_route_filters[0].export_route_filter_id
}
`, gatewayname)
}
Loading