diff --git a/go.mod b/go.mod index b35261b017..cf38c31d8d 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index d3cd8861ca..f5e0b380ac 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/ibm/provider/provider.go b/ibm/provider/provider.go index f189341b2c..4467fb8788 100644 --- a/ibm/provider/provider.go +++ b/ibm/provider/provider.go @@ -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(), @@ -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(), diff --git a/ibm/service/cis/resource_ibm_cis_domain_settings.go b/ibm/service/cis/resource_ibm_cis_domain_settings.go index a21bfc2866..5a83a01ae0 100644 --- a/ibm/service/cis/resource_ibm_cis_domain_settings.go +++ b/ibm/service/cis/resource_ibm_cis_domain_settings.go @@ -1,4 +1,4 @@ -// 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 @@ -6,11 +6,12 @@ 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 ( @@ -51,6 +52,7 @@ const ( cisDomainSettingsSecurityHeaderMaxAge = "max_age" cisDomainSettingsSecurityHeaderIncludeSubdomains = "include_subdomains" cisDomainSettingsSecurityHeaderNoSniff = "nosniff" + cisDomainSettingsSecurityHeaderPreload = "preload" cisDomainSettingsMobileRedirect = "mobile_redirect" cisDomainSettingsMobileRedirectStatus = "status" cisDomainSettingsMobileRedirectMobileSubdomain = "mobile_subdomain" @@ -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, + }, }, }, }, @@ -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 @@ -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 } diff --git a/ibm/service/cis/resource_ibm_cis_domain_settings_test.go b/ibm/service/cis/resource_ibm_cis_domain_settings_test.go index 14b230ecbc..5859d59be9 100644 --- a/ibm/service/cis/resource_ibm_cis_domain_settings_test.go +++ b/ibm/service/cis/resource_ibm_cis_domain_settings_test.go @@ -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) { @@ -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" diff --git a/ibm/service/directlink/constants.go b/ibm/service/directlink/constants.go index 426707560b..dbf97b918a 100644 --- a/ibm/service/directlink/constants.go +++ b/ibm/service/directlink/constants.go @@ -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" @@ -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" @@ -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 { diff --git a/ibm/service/directlink/data_source_ibm_dl_export_route_filter.go b/ibm/service/directlink/data_source_ibm_dl_export_route_filter.go new file mode 100644 index 0000000000..d6fa35a6c0 --- /dev/null +++ b/ibm/service/directlink/data_source_ibm_dl_export_route_filter.go @@ -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: { + 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 +} diff --git a/ibm/service/directlink/data_source_ibm_dl_export_route_filter_test.go b/ibm/service/directlink/data_source_ibm_dl_export_route_filter_test.go new file mode 100644 index 0000000000..d567294728 --- /dev/null +++ b/ibm/service/directlink/data_source_ibm_dl_export_route_filter_test.go @@ -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) +} diff --git a/ibm/service/directlink/data_source_ibm_dl_export_route_filters.go b/ibm/service/directlink/data_source_ibm_dl_export_route_filters.go new file mode 100644 index 0000000000..480f4865e4 --- /dev/null +++ b/ibm/service/directlink/data_source_ibm_dl_export_route_filters.go @@ -0,0 +1,127 @@ +// Copyright IBM Corp. 2023 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package directlink + +import ( + "log" + "time" + + "github.com/IBM/networking-go-sdk/directlinkv1" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func DataSourceIBMDLExportRouteFilters() *schema.Resource { + return &schema.Resource{ + Read: dataSourceIBMDLExportRouteFiltersRead, + Schema: map[string]*schema.Schema{ + dlGatewayId: { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The Direct Link gateway identifier", + }, + dlExportRouteFilters: { + Type: schema.TypeList, + Description: "Collection of export route filters", + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + dlExportRouteFilterId: { + Type: schema.TypeString, + Computed: true, + Description: "The 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 dataSourceIBMDLExportRouteFiltersRead(d *schema.ResourceData, meta interface{}) error { + directLink, err := directlinkClient(meta) + if err != nil { + return err + } + + gatewayId := d.Get(dlGatewayId).(string) + listGatewayExportRouteFiltersOptionsModel := &directlinkv1.ListGatewayExportRouteFiltersOptions{GatewayID: &gatewayId} + exportRouteFilterList, response, err := directLink.ListGatewayExportRouteFilters(listGatewayExportRouteFiltersOptionsModel) + if err != nil { + log.Println("[ERROR] Error listing Direct Link Export Route Filters", response, err) + return err + } + exportRouteFilters := make([]map[string]interface{}, 0) + for _, instance := range exportRouteFilterList.ExportRouteFilters { + routeFilter := map[string]interface{}{} + if instance.ID != nil { + routeFilter[dlExportRouteFilterId] = *instance.ID + } + if instance.Action != nil { + routeFilter[dlAction] = *instance.Action + } + if instance.Before != nil { + routeFilter[dlBefore] = *instance.Before + } + if instance.CreatedAt != nil { + routeFilter[dlCreatedAt] = instance.CreatedAt.String() + } + if instance.Prefix != nil { + routeFilter[dlPrefix] = *instance.Prefix + } + if instance.UpdatedAt != nil { + routeFilter[dlUpdatedAt] = instance.UpdatedAt.String() + } + if instance.Ge != nil { + routeFilter[dlGe] = *instance.Ge + } + if instance.Le != nil { + routeFilter[dlLe] = *instance.Le + } + exportRouteFilters = append(exportRouteFilters, routeFilter) + } + d.Set(dlExportRouteFilters, exportRouteFilters) + d.SetId(dataSourceIBMDirectLinkGatewayExportRouteFiltersID(d)) + return nil +} + +// dataSourceIBMDirectLinkGatewayRouteReportsID returns a reasonable ID for a directlink gateways list. +func dataSourceIBMDirectLinkGatewayExportRouteFiltersID(d *schema.ResourceData) string { + return time.Now().UTC().String() +} diff --git a/ibm/service/directlink/data_source_ibm_dl_export_route_filters_test.go b/ibm/service/directlink/data_source_ibm_dl_export_route_filters_test.go new file mode 100644 index 0000000000..fbe5b192b5 --- /dev/null +++ b/ibm/service/directlink/data_source_ibm_dl_export_route_filters_test.go @@ -0,0 +1,57 @@ +// 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 TestAccIBMDLExportRouteFiltersDataSource_basic(t *testing.T) { + node := "data.ibm_dl_export_route_filters.test_dl_export_route_filters" + gatewayname := fmt.Sprintf("gateway-name2-%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMDLExportRouteFiltersDataSourceConfig(gatewayname), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(node, "export_route_filters.#"), + ), + }, + }, + }) +} + +func testAccCheckIBMDLExportRouteFiltersDataSourceConfig(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 + } + `, gatewayname) +} diff --git a/ibm/service/directlink/data_source_ibm_dl_gateway.go b/ibm/service/directlink/data_source_ibm_dl_gateway.go index 18999c4411..515047aa51 100644 --- a/ibm/service/directlink/data_source_ibm_dl_gateway.go +++ b/ibm/service/directlink/data_source_ibm_dl_gateway.go @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2017, 2021 All Rights Reserved. +// Copyright IBM Corp. 2017, 2021, 2023 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 package directlink @@ -7,10 +7,11 @@ import ( "fmt" "log" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" "github.com/IBM/networking-go-sdk/directlinkv1" "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/validate" ) const ( @@ -120,6 +121,16 @@ func DataSourceIBMDLGateway() *schema.Resource { }, }, }, + dlDefault_export_route_filter: { + Type: schema.TypeString, + Computed: true, + Description: "The default directional route filter action that applies to routes that do not match any directional route filters", + }, + dlDefault_import_route_filter: { + Type: schema.TypeString, + Computed: true, + Description: "The default directional route filter action that applies to routes that do not match any directional route filters", + }, dlAuthenticationKey: { Type: schema.TypeString, Computed: true, @@ -175,6 +186,12 @@ func DataSourceIBMDLGateway() *schema.Resource { Computed: true, Description: "Gateway BGP status", }, + dlBgpStatusUpdatedAt: { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: "Date and time BGP status was updated", + }, dlMacSecConfig: { Type: schema.TypeList, Computed: true, @@ -284,6 +301,12 @@ func DataSourceIBMDLGateway() *schema.Resource { Computed: true, Description: "Gateway link status", }, + dlLinkStatusUpdatedAt: { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: "Date and time Link status was updated", + }, dlLocationDisplayName: { Type: schema.TypeString, Computed: true, @@ -451,6 +474,9 @@ func dataSourceIBMDLGatewayRead(d *schema.ResourceData, meta interface{}) error if instance.BgpStatus != nil { d.Set(dlBgpStatus, *instance.BgpStatus) } + if instance.BgpStatusUpdatedAt != nil { + d.Set(dlBgpStatusUpdatedAt, instance.BgpStatusUpdatedAt.String()) + } if instance.LocationName != nil { d.Set(dlLocationName, *instance.LocationName) } @@ -469,9 +495,18 @@ func dataSourceIBMDLGatewayRead(d *schema.ResourceData, meta interface{}) error if instance.LinkStatus != nil { d.Set(dlLinkStatus, *instance.LinkStatus) } + if instance.LinkStatusUpdatedAt != nil { + d.Set(dlLinkStatusUpdatedAt, instance.LinkStatusUpdatedAt.String()) + } if instance.CreatedAt != nil { d.Set(dlCreatedAt, instance.CreatedAt.String()) } + if instance.DefaultExportRouteFilter != nil { + d.Set(dlDefault_export_route_filter, *instance.DefaultExportRouteFilter) + } + if instance.DefaultImportRouteFilter != nil { + d.Set(dlDefault_import_route_filter, *instance.DefaultImportRouteFilter) + } //Show the BFD Config parameters if set if instance.BfdConfig != nil { diff --git a/ibm/service/directlink/data_source_ibm_dl_gateways.go b/ibm/service/directlink/data_source_ibm_dl_gateways.go index 96cd920009..a8c7b2a757 100644 --- a/ibm/service/directlink/data_source_ibm_dl_gateways.go +++ b/ibm/service/directlink/data_source_ibm_dl_gateways.go @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2017, 2021 All Rights Reserved. +// Copyright IBM Corp. 2017, 2021, 2023 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 package directlink @@ -77,6 +77,16 @@ func DataSourceIBMDLGateways() *schema.Resource { }, }, }, + dlDefault_export_route_filter: { + Type: schema.TypeString, + Computed: true, + Description: "The default directional route filter action that applies to routes that do not match any directional route filters", + }, + dlDefault_import_route_filter: { + Type: schema.TypeString, + Computed: true, + Description: "The default directional route filter action that applies to routes that do not match any directional route filters", + }, dlAuthenticationKey: { Type: schema.TypeString, Computed: true, @@ -132,6 +142,12 @@ func DataSourceIBMDLGateways() *schema.Resource { Computed: true, Description: "Gateway BGP status", }, + dlBgpStatusUpdatedAt: { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: "Date and time BGP status was updated", + }, dlCompletionNoticeRejectReason: { Type: schema.TypeString, Computed: true, @@ -167,6 +183,12 @@ func DataSourceIBMDLGateways() *schema.Resource { Computed: true, Description: "Gateway link status", }, + dlLinkStatusUpdatedAt: { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: "Date and time Link status was updated", + }, dlLocationDisplayName: { Type: schema.TypeString, Computed: true, @@ -363,6 +385,9 @@ func dataSourceIBMDLGatewaysRead(d *schema.ResourceData, meta interface{}) error if instance.BgpStatus != nil { gateway[dlBgpStatus] = *instance.BgpStatus } + if instance.BgpStatusUpdatedAt != nil { + gateway[dlBgpStatusUpdatedAt] = instance.BgpStatusUpdatedAt.String() + } if instance.LocationName != nil { gateway[dlLocationName] = *instance.LocationName } @@ -381,6 +406,9 @@ func dataSourceIBMDLGatewaysRead(d *schema.ResourceData, meta interface{}) error if instance.LinkStatus != nil { gateway[dlLinkStatus] = *instance.LinkStatus } + if instance.LinkStatusUpdatedAt != nil { + gateway[dlLinkStatusUpdatedAt] = instance.LinkStatusUpdatedAt.String() + } if instance.CreatedAt != nil { gateway[dlCreatedAt] = instance.CreatedAt.String() } @@ -388,6 +416,12 @@ func dataSourceIBMDLGatewaysRead(d *schema.ResourceData, meta interface{}) error rg := instance.ResourceGroup gateway[dlResourceGroup] = *rg.ID } + if instance.DefaultExportRouteFilter != nil { + gateway[dlDefault_export_route_filter] = *instance.DefaultExportRouteFilter + } + if instance.DefaultImportRouteFilter != nil { + gateway[dlDefault_import_route_filter] = *instance.DefaultImportRouteFilter + } //Show the BFD Config parameters if set if instance.BfdConfig != nil { diff --git a/ibm/service/directlink/data_source_ibm_dl_import_route_filter.go b/ibm/service/directlink/data_source_ibm_dl_import_route_filter.go new file mode 100644 index 0000000000..bdca147e67 --- /dev/null +++ b/ibm/service/directlink/data_source_ibm_dl_import_route_filter.go @@ -0,0 +1,109 @@ +// Copyright IBM Corp. 2023 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 DataSourceIBMDLImportRouteFilter() *schema.Resource { + return &schema.Resource{ + Read: dataSourceIBMDLImportRouteFilterRead, + Schema: map[string]*schema.Schema{ + dlGatewayId: { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The Direct Link gateway identifier", + }, + dlImportRouteFilterId: { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Import 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 import 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 import route filter was last updated", + }, + }, + } +} + +func dataSourceIBMDLImportRouteFilterRead(d *schema.ResourceData, meta interface{}) error { + directLink, err := directlinkClient(meta) + if err != nil { + return err + } + gatewayId := d.Get(dlGatewayId).(string) + importRouteFilterId := d.Get(dlImportRouteFilterId).(string) + getGatewayImportRouteFilterOptionsModel := &directlinkv1.GetGatewayImportRouteFilterOptions{GatewayID: &gatewayId, ID: &importRouteFilterId} + importRouteFilter, response, err := directLink.GetGatewayImportRouteFilter(getGatewayImportRouteFilterOptionsModel) + if err != nil { + log.Println("[ERROR] Error while listing Direct Link Import Route Filter", response, err) + return err + } + if importRouteFilter == nil { + return fmt.Errorf("error fetching the Import route Filter for gateway: %s and Import Route FilterId: %s with response code: %d", gatewayId, importRouteFilterId, response.StatusCode) + } else if importRouteFilter.ID != nil { + d.SetId(*importRouteFilter.ID) + } + if importRouteFilter.Action != nil { + d.Set(dlAction, *importRouteFilter.Action) + } + if importRouteFilter.Before != nil { + d.Set(dlBefore, *importRouteFilter.Before) + } + if importRouteFilter.CreatedAt != nil { + d.Set(dlCreatedAt, importRouteFilter.CreatedAt.String()) + } + if importRouteFilter.Prefix != nil { + d.Set(dlPrefix, *importRouteFilter.Prefix) + } + if importRouteFilter.UpdatedAt != nil { + d.Set(dlUpdatedAt, importRouteFilter.UpdatedAt.String()) + } + if importRouteFilter.Ge != nil { + d.Set(dlGe, *importRouteFilter.Ge) + } + if importRouteFilter.Le != nil { + d.Set(dlLe, *importRouteFilter.Le) + } + return nil +} diff --git a/ibm/service/directlink/data_source_ibm_dl_import_route_filter_test.go b/ibm/service/directlink/data_source_ibm_dl_import_route_filter_test.go new file mode 100644 index 0000000000..490b4eb7de --- /dev/null +++ b/ibm/service/directlink/data_source_ibm_dl_import_route_filter_test.go @@ -0,0 +1,62 @@ +// 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 TestAccIBMDLImportRouteFilterDataSource_basic(t *testing.T) { + node := "data.ibm_dl_import_route_filter.test_dl_import_route_filter" + gatewayname := fmt.Sprintf("import-route-filter-gateway-name-%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMDLImportRouteFilterDataSourceConfig(gatewayname), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(node, "action"), + ), + }, + }, + }) +} + +func testAccCheckIBMDLImportRouteFilterDataSourceConfig(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 + import_route_filters { + action = "deny" + prefix = "10.10.9.0/24" + ge =25 + le = 26 + } + } + data "ibm_dl_import_route_filters" "test_dl_import_route_filters" { + gateway = ibm_dl_gateway.test_dl_gateway.id + } + data "ibm_dl_import_route_filter" "test_dl_import_route_filter" { + gateway = ibm_dl_gateway.test_dl_gateway.id + id = data.ibm_dl_import_route_filters.test_dl_import_route_filters.import_route_filters[0].import_route_filter_id + } + `, gatewayname) +} diff --git a/ibm/service/directlink/data_source_ibm_dl_import_route_filters.go b/ibm/service/directlink/data_source_ibm_dl_import_route_filters.go new file mode 100644 index 0000000000..9a1d2676bc --- /dev/null +++ b/ibm/service/directlink/data_source_ibm_dl_import_route_filters.go @@ -0,0 +1,127 @@ +// Copyright IBM Corp. 2023 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package directlink + +import ( + "log" + "time" + + "github.com/IBM/networking-go-sdk/directlinkv1" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func DataSourceIBMDLImportRouteFilters() *schema.Resource { + return &schema.Resource{ + Read: dataSourceIBMDLImportRouteFiltersRead, + Schema: map[string]*schema.Schema{ + dlGatewayId: { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The Direct Link gateway identifier", + }, + dlImportRouteFilters: { + Type: schema.TypeList, + Description: "Collection of import route filters", + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + dlImportRouteFilterId: { + Type: schema.TypeString, + Computed: true, + Description: "The Import 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 import 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 import route filter was last updated", + }, + }, + }, + }, + }, + } +} + +func dataSourceIBMDLImportRouteFiltersRead(d *schema.ResourceData, meta interface{}) error { + directLink, err := directlinkClient(meta) + if err != nil { + return err + } + + gatewayId := d.Get(dlGatewayId).(string) + listGatewayImportRouteFiltersOptionsModel := &directlinkv1.ListGatewayImportRouteFiltersOptions{GatewayID: &gatewayId} + importRouteFilterList, response, err := directLink.ListGatewayImportRouteFilters(listGatewayImportRouteFiltersOptionsModel) + if err != nil { + log.Println("[ERROR] Error while listing Direct Link Import Route Filters", response, err) + return err + } + importRouteFilters := make([]map[string]interface{}, 0) + for _, instance := range importRouteFilterList.ImportRouteFilters { + routeFilter := map[string]interface{}{} + if instance.ID != nil { + routeFilter[dlImportRouteFilterId] = *instance.ID + } + if instance.Action != nil { + routeFilter[dlAction] = *instance.Action + } + if instance.Before != nil { + routeFilter[dlBefore] = *instance.Before + } + if instance.CreatedAt != nil { + routeFilter[dlCreatedAt] = instance.CreatedAt.String() + } + if instance.Prefix != nil { + routeFilter[dlPrefix] = *instance.Prefix + } + if instance.UpdatedAt != nil { + routeFilter[dlUpdatedAt] = instance.UpdatedAt.String() + } + if instance.Ge != nil { + routeFilter[dlGe] = *instance.Ge + } + if instance.Le != nil { + routeFilter[dlLe] = *instance.Le + } + importRouteFilters = append(importRouteFilters, routeFilter) + } + d.Set(dlImportRouteFilters, importRouteFilters) + d.SetId(dataSourceIBMDirectLinkGatewayImportRouteFiltersID(d)) + return nil +} + +// dataSourceIBMDirectLinkGatewayImportRouteFiltersID returns a reasonable ID for a directlink gateways list. +func dataSourceIBMDirectLinkGatewayImportRouteFiltersID(d *schema.ResourceData) string { + return time.Now().UTC().String() +} diff --git a/ibm/service/directlink/data_source_ibm_dl_import_route_filters_test.go b/ibm/service/directlink/data_source_ibm_dl_import_route_filters_test.go new file mode 100644 index 0000000000..d2e46378bc --- /dev/null +++ b/ibm/service/directlink/data_source_ibm_dl_import_route_filters_test.go @@ -0,0 +1,58 @@ +// 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 TestAccIBMDLImportRouteFiltersDataSource_basic(t *testing.T) { + node := "data.ibm_dl_import_route_filters.test_dl_import_route_filters" + gatewayname := fmt.Sprintf("import-gateway-name-%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMDLImportRouteFiltersDataSourceConfig(gatewayname), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(node, "import_route_filters.#"), + ), + }, + }, + }) +} + +func testAccCheckIBMDLImportRouteFiltersDataSourceConfig(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 + import_route_filters { + action = "deny" + prefix = "10.10.9.0/24" + ge =25 + le = 27 + } + } + data "ibm_dl_import_route_filters" "test_dl_import_route_filters" { + gateway = ibm_dl_gateway.test_dl_gateway.id + } + `, gatewayname) +} diff --git a/ibm/service/directlink/resource_ibm_dl_gateway.go b/ibm/service/directlink/resource_ibm_dl_gateway.go index cfe309ff3f..72dd8fe0d3 100644 --- a/ibm/service/directlink/resource_ibm_dl_gateway.go +++ b/ibm/service/directlink/resource_ibm_dl_gateway.go @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2017, 2021 All Rights Reserved. +// Copyright IBM Corp. 2017, 2021, 2023 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 package directlink @@ -12,14 +12,15 @@ import ( "strings" "time" - "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/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" + + "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" ) func ResourceIBMDLGateway() *schema.Resource { @@ -42,7 +43,6 @@ func ResourceIBMDLGateway() *schema.Resource { return flex.ResourceTagsCustomizeDiff(diff) }, ), - Schema: map[string]*schema.Schema{ dlAuthenticationKey: { Type: schema.TypeString, @@ -50,6 +50,124 @@ func ResourceIBMDLGateway() *schema.Resource { ForceNew: false, Description: "BGP MD5 authentication key", }, + dlExportRouteFilters: { + Type: schema.TypeList, + Optional: true, + ForceNew: false, + Description: "List Export Route Filters for a Direct Link gateway", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + dlExportRouteFilterId: { + Type: schema.TypeString, + Computed: true, + Description: "Export route Filter identifier", + }, + dlAction: { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.InvokeValidator("ibm_dl_gateway", dlAction), + Description: "Determines whether the routes that match the prefix-set will be permit or deny", + }, + dlBefore: { + Type: schema.TypeString, + Optional: true, + 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, + Optional: true, + Description: "The minimum matching length of the prefix-set", + }, + dlLe: { + Type: schema.TypeInt, + Optional: true, + Description: "The maximum matching length of the prefix-set", + }, + dlPrefix: { + Type: schema.TypeString, + Required: 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", + }, + }, + }, + }, + dlImportRouteFilters: { + Type: schema.TypeList, + Optional: true, + ForceNew: false, + Description: "List Import Route Filters for a Direct Link gateway", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + dlImportRouteFilterId: { + Type: schema.TypeString, + Computed: true, + Description: "Import route Filter identifier", + }, + dlAction: { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.InvokeValidator("ibm_dl_gateway", dlAction), + Description: "Determines whether the routes that match the prefix-set will be permit or deny", + }, + dlBefore: { + Type: schema.TypeString, + Optional: true, + 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, + Optional: true, + Description: "The minimum matching length of the prefix-set", + }, + dlLe: { + Type: schema.TypeInt, + Optional: true, + Description: "The maximum matching length of the prefix-set", + }, + dlPrefix: { + Type: schema.TypeString, + Required: 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", + }, + }, + }, + }, + dlDefault_export_route_filter: { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validate.InvokeValidator("ibm_dl_gateway", dlDefault_export_route_filter), + Description: "The default directional route filter action that applies to routes that do not match any directional route filters", + }, + dlDefault_import_route_filter: { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validate.InvokeValidator("ibm_dl_gateway", dlDefault_import_route_filter), + Description: "The default directional route filter action that applies to routes that do not match any directional route filters", + }, dlAsPrepends: { Type: schema.TypeList, Optional: true, @@ -192,21 +310,18 @@ func ResourceIBMDLGateway() *schema.Resource { ForceNew: false, Description: "The unique user-defined name for this gateway", ValidateFunc: validate.InvokeValidator("ibm_dl_gateway", dlName), - // ValidateFunc: validateRegexpLen(1, 63, "^([a-zA-Z]|[a-zA-Z][-_a-zA-Z0-9]*[a-zA-Z0-9])$"), }, dlCarrierName: { Type: schema.TypeString, Optional: true, ForceNew: true, Description: "Carrier name", - // ValidateFunc: validateRegexpLen(1, 128, "^[a-z][A-Z][0-9][ -_]$"), }, dlCustomerName: { Type: schema.TypeString, Optional: true, ForceNew: true, Description: "Customer name", - // ValidateFunc: validateRegexpLen(1, 128, "^[a-z][A-Z][0-9][ -_]$"), }, dlSpeedMbps: { Type: schema.TypeInt, @@ -220,7 +335,6 @@ func ResourceIBMDLGateway() *schema.Resource { ForceNew: true, Description: "Gateway type", ValidateFunc: validate.InvokeValidator("ibm_dl_gateway", dlType), - // ValidateFunc: validate.ValidateAllowedStringValues([]string{"dedicated", "connect"}), }, dlMacSecConfig: { Type: schema.TypeList, @@ -346,12 +460,16 @@ func ResourceIBMDLGateway() *schema.Resource { Computed: true, Description: "IBM BGP ASN", }, - dlBgpStatus: { Type: schema.TypeString, Computed: true, Description: "Gateway BGP status", }, + dlBgpStatusUpdatedAt: { + Type: schema.TypeString, + Computed: true, + Description: "Date and time BGP status was updated", + }, dlChangeRequest: { Type: schema.TypeString, Computed: true, @@ -377,6 +495,11 @@ func ResourceIBMDLGateway() *schema.Resource { Computed: true, Description: "Gateway link status", }, + dlLinkStatusUpdatedAt: { + Type: schema.TypeString, + Computed: true, + Description: "Date and time Link status was updated", + }, dlLocationDisplayName: { Type: schema.TypeString, Computed: true, @@ -429,7 +552,29 @@ func ResourceIBMDLGatewayValidator() *validate.ResourceValidator { dlTypeAllowedValues := "dedicated, connect" dlConnectionModeAllowedValues := "direct, transit" dlPolicyAllowedValues := "export, import" + dlActionValues := "permit, deny" + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: dlAction, + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + AllowedValues: dlActionValues}) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: dlDefault_export_route_filter, + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + AllowedValues: dlActionValues}) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: dlDefault_import_route_filter, + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + AllowedValues: dlActionValues}) validateSchema = append(validateSchema, validate.ValidateSchema{ Identifier: dlType, @@ -563,11 +708,55 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error } } + exportRouteFiltersCreateList := make([]directlinkv1.GatewayTemplateRouteFilter, 0) + if exportRouteFiltersInputList, ok := d.GetOk(dlExportRouteFilters); ok { + exportRouteFilters := exportRouteFiltersInputList.([]interface{}) + + for _, exportRouteFilter := range exportRouteFilters { + filtersData := exportRouteFilter.(map[string]interface{}) + + // Construct an Export Route Filters List + exportRouteFilterTemplateModel := new(directlinkv1.GatewayTemplateRouteFilter) + exportRouteFilterTemplateModel.Action = NewStrPointer(filtersData[dlAction].(string)) + exportRouteFilterTemplateModel.Prefix = NewStrPointer(filtersData[dlPrefix].(string)) + exportRouteFilterTemplateModel.Ge = nil + exportRouteFilterTemplateModel.Le = nil + if _, ok := filtersData[dlGe]; ok { + exportRouteFilterTemplateModel.Ge = NewInt64Pointer(int64(filtersData[dlGe].(int))) + } + if _, ok := filtersData[dlLe]; ok { + exportRouteFilterTemplateModel.Le = NewInt64Pointer(int64(filtersData[dlLe].(int))) + } + exportRouteFiltersCreateList = append(exportRouteFiltersCreateList, *exportRouteFilterTemplateModel) + } + } + + importRouteFiltersCreateList := make([]directlinkv1.GatewayTemplateRouteFilter, 0) + if importRouteFiltersInputList, ok := d.GetOk(dlImportRouteFilters); ok { + importRouteFilters := importRouteFiltersInputList.([]interface{}) + + for _, importRouteFilter := range importRouteFilters { + filtersData := importRouteFilter.(map[string]interface{}) + + // Construct an Import Route Filters List + importRouteFilterTemplateModel := new(directlinkv1.GatewayTemplateRouteFilter) + importRouteFilterTemplateModel.Action = NewStrPointer(filtersData[dlAction].(string)) + importRouteFilterTemplateModel.Prefix = NewStrPointer(filtersData[dlPrefix].(string)) + importRouteFilterTemplateModel.Ge = nil + importRouteFilterTemplateModel.Le = nil + if _, ok := filtersData[dlGe]; ok { + importRouteFilterTemplateModel.Ge = NewInt64Pointer(int64(filtersData[dlGe].(int))) + } + if _, ok := filtersData[dlLe]; ok { + importRouteFilterTemplateModel.Le = NewInt64Pointer(int64(filtersData[dlLe].(int))) + } + importRouteFiltersCreateList = append(importRouteFiltersCreateList, *importRouteFilterTemplateModel) + } + } if dtype == "dedicated" { var crossConnectRouter, carrierName, locationName, customerName string if _, ok := d.GetOk(dlCarrierName); ok { carrierName = d.Get(dlCarrierName).(string) - // gatewayTemplateModel.CarrierName = &carrierName } else { err = fmt.Errorf("[ERROR] Error creating gateway, %s is a required field", dlCarrierName) log.Printf("%s is a required field", dlCarrierName) @@ -575,7 +764,6 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error } if _, ok := d.GetOk(dlCrossConnectRouter); ok { crossConnectRouter = d.Get(dlCrossConnectRouter).(string) - // gatewayTemplateModel.CrossConnectRouter = &crossConnectRouter } else { err = fmt.Errorf("[ERROR] Error creating gateway, %s is a required field", dlCrossConnectRouter) log.Printf("%s is a required field", dlCrossConnectRouter) @@ -583,7 +771,6 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error } if _, ok := d.GetOk(dlLocationName); ok { locationName = d.Get(dlLocationName).(string) - //gatewayTemplateModel.LocationName = &locationName } else { err = fmt.Errorf("[ERROR] Error creating gateway, %s is a required field", dlLocationName) log.Printf("%s is a required field", dlLocationName) @@ -591,7 +778,6 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error } if _, ok := d.GetOk(dlCustomerName); ok { customerName = d.Get(dlCustomerName).(string) - //gatewayTemplateModel.CustomerName = &customerName } else { err = fmt.Errorf("[ERROR] Error creating gateway, %s is a required field", dlCustomerName) log.Printf("%s is a required field", dlCustomerName) @@ -661,7 +847,18 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error if len(asPrependsCreateItems) > 0 { gatewayDedicatedTemplateModel.AsPrepends = asPrependsCreateItems } - + if len(exportRouteFiltersCreateList) > 0 { + gatewayDedicatedTemplateModel.ExportRouteFilters = exportRouteFiltersCreateList + } + if len(importRouteFiltersCreateList) > 0 { + gatewayDedicatedTemplateModel.ImportRouteFilters = importRouteFiltersCreateList + } + if default_export_route_filter, ok := d.GetOk(dlDefault_export_route_filter); ok { + gatewayDedicatedTemplateModel.DefaultExportRouteFilter = NewStrPointer(default_export_route_filter.(string)) + } + if default_import_route_filter, ok := d.GetOk(dlDefault_import_route_filter); ok { + gatewayDedicatedTemplateModel.DefaultImportRouteFilter = NewStrPointer(default_import_route_filter.(string)) + } createGatewayOptionsModel.GatewayTemplate = gatewayDedicatedTemplateModel } else if dtype == "connect" { @@ -710,7 +907,18 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error if len(asPrependsCreateItems) > 0 { gatewayConnectTemplateModel.AsPrepends = asPrependsCreateItems } - + if len(exportRouteFiltersCreateList) > 0 { + gatewayConnectTemplateModel.ExportRouteFilters = exportRouteFiltersCreateList + } + if len(importRouteFiltersCreateList) > 0 { + gatewayConnectTemplateModel.ImportRouteFilters = importRouteFiltersCreateList + } + if default_export_route_filter, ok := d.GetOk(dlDefault_export_route_filter); ok { + gatewayConnectTemplateModel.DefaultExportRouteFilter = NewStrPointer(default_export_route_filter.(string)) + } + if default_import_route_filter, ok := d.GetOk(dlDefault_import_route_filter); ok { + gatewayConnectTemplateModel.DefaultImportRouteFilter = NewStrPointer(default_import_route_filter.(string)) + } createGatewayOptionsModel.GatewayTemplate = gatewayConnectTemplateModel } else { @@ -754,6 +962,98 @@ func resourceIBMdlGatewayCreate(d *schema.ResourceData, meta interface{}) error return resourceIBMdlGatewayRead(d, meta) } +func resourceIBMdlGatewayExportRouteFiltersRead(d *schema.ResourceData, meta interface{}) error { + directLink, err := directlinkClient(meta) + if err != nil { + return err + } + + gatewayId := d.Id() + listGatewayExportRouteFiltersOptionsModel := &directlinkv1.ListGatewayExportRouteFiltersOptions{GatewayID: &gatewayId} + exportRouteFilterList, response, err := directLink.ListGatewayExportRouteFilters(listGatewayExportRouteFiltersOptionsModel) + if err != nil { + log.Println("[WARN] Error listing Direct Link Export Route Filters", response, err) + return err + } + exportRouteFilters := make([]map[string]interface{}, 0) + for _, instance := range exportRouteFilterList.ExportRouteFilters { + routeFilter := map[string]interface{}{} + if instance.ID != nil { + routeFilter[dlExportRouteFilterId] = *instance.ID + } + if instance.Action != nil { + routeFilter[dlAction] = *instance.Action + } + if instance.Before != nil { + routeFilter[dlBefore] = *instance.Before + } + if instance.CreatedAt != nil { + routeFilter[dlCreatedAt] = instance.CreatedAt.String() + } + if instance.Prefix != nil { + routeFilter[dlPrefix] = *instance.Prefix + } + if instance.UpdatedAt != nil { + routeFilter[dlUpdatedAt] = instance.UpdatedAt.String() + } + if instance.Ge != nil { + routeFilter[dlGe] = *instance.Ge + } + if instance.Le != nil { + routeFilter[dlLe] = *instance.Le + } + exportRouteFilters = append(exportRouteFilters, routeFilter) + } + d.Set(dlExportRouteFilters, exportRouteFilters) + return nil +} + +func resourceIBMdlGatewayImportRouteFiltersRead(d *schema.ResourceData, meta interface{}) error { + directLink, err := directlinkClient(meta) + if err != nil { + return err + } + + gatewayId := d.Id() + listGatewayImportRouteFiltersOptionsModel := &directlinkv1.ListGatewayImportRouteFiltersOptions{GatewayID: &gatewayId} + importRouteFilterList, response, err := directLink.ListGatewayImportRouteFilters(listGatewayImportRouteFiltersOptionsModel) + if err != nil { + log.Println("[WARN] Error while listing Direct Link Import Route Filters", response, err) + return err + } + importRouteFilters := make([]map[string]interface{}, 0) + for _, instance := range importRouteFilterList.ImportRouteFilters { + routeFilter := map[string]interface{}{} + if instance.ID != nil { + routeFilter[dlImportRouteFilterId] = *instance.ID + } + if instance.Action != nil { + routeFilter[dlAction] = *instance.Action + } + if instance.Before != nil { + routeFilter[dlBefore] = *instance.Before + } + if instance.CreatedAt != nil { + routeFilter[dlCreatedAt] = instance.CreatedAt.String() + } + if instance.Prefix != nil { + routeFilter[dlPrefix] = *instance.Prefix + } + if instance.UpdatedAt != nil { + routeFilter[dlUpdatedAt] = instance.UpdatedAt.String() + } + if instance.Ge != nil { + routeFilter[dlGe] = *instance.Ge + } + if instance.Le != nil { + routeFilter[dlLe] = *instance.Le + } + importRouteFilters = append(importRouteFilters, routeFilter) + } + d.Set(dlImportRouteFilters, importRouteFilters) + return nil +} + func resourceIBMdlGatewayRead(d *schema.ResourceData, meta interface{}) error { dtype := d.Get(dlType).(string) log.Printf("[INFO] Inside resourceIBMdlGatewayRead: %s", dtype) @@ -820,6 +1120,9 @@ func resourceIBMdlGatewayRead(d *schema.ResourceData, meta interface{}) error { if instance.BgpStatus != nil { d.Set(dlBgpStatus, *instance.BgpStatus) } + if instance.BgpStatusUpdatedAt != nil { + d.Set(dlBgpStatusUpdatedAt, instance.BgpStatusUpdatedAt.String()) + } if instance.CompletionNoticeRejectReason != nil { d.Set(dlCompletionNoticeRejectReason, *instance.CompletionNoticeRejectReason) } @@ -841,6 +1144,9 @@ func resourceIBMdlGatewayRead(d *schema.ResourceData, meta interface{}) error { if instance.LinkStatus != nil { d.Set(dlLinkStatus, *instance.LinkStatus) } + if instance.LinkStatusUpdatedAt != nil { + d.Set(dlLinkStatusUpdatedAt, instance.LinkStatusUpdatedAt.String()) + } if instance.CreatedAt != nil { d.Set(dlCreatedAt, instance.CreatedAt.String()) } @@ -850,7 +1156,12 @@ func resourceIBMdlGatewayRead(d *schema.ResourceData, meta interface{}) error { if instance.ConnectionMode != nil { d.Set(dlConnectionMode, *instance.ConnectionMode) } - + if instance.DefaultExportRouteFilter != nil { + d.Set(dlDefault_export_route_filter, *instance.DefaultExportRouteFilter) + } + if instance.DefaultImportRouteFilter != nil { + d.Set(dlDefault_import_route_filter, *instance.DefaultImportRouteFilter) + } asPrependList := make([]map[string]interface{}, 0) if len(instance.AsPrepends) > 0 { for _, asPrepend := range instance.AsPrepends { @@ -962,7 +1273,8 @@ func resourceIBMdlGatewayRead(d *schema.ResourceData, meta interface{}) error { d.Set(dlBfdStatusUpdatedAt, instance.BfdConfig.BfdStatusUpdatedAt.String()) } } - + resourceIBMdlGatewayExportRouteFiltersRead(d, meta) + resourceIBMdlGatewayImportRouteFiltersRead(d, meta) return nil } func isWaitForDirectLinkAvailable(client *directlinkv1.DirectLinkV1, id string, timeout time.Duration) (interface{}, error) { @@ -1091,6 +1403,107 @@ func resourceIBMdlGatewayUpdate(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("[ERROR] Error while replacing AS Prepends to a gateway id %s %s\n%s", ID, operationErr, responseRep) } } + if d.HasChange(dlExportRouteFilters) { + + listGatewayExportRouteFiltersOptionsModel := &directlinkv1.ListGatewayExportRouteFiltersOptions{GatewayID: &ID} + _, response, operationErr := directLink.ListGatewayExportRouteFilters(listGatewayExportRouteFiltersOptionsModel) + if operationErr != nil { + log.Printf("[DEBUG] Error listing the Direct Link Export Route Filters %s\n%s", operationErr, response) + return fmt.Errorf("[ERROR] Error listing Direct Link Gateway Export Route Filters %s\n%s", operationErr, response) + } + etag := response.GetHeaders().Get("etag") + exportRouteFiltersReplaceList := make([]directlinkv1.GatewayTemplateRouteFilter, 0) + if exportRouteFiltersInputList, ok := d.GetOk(dlExportRouteFilters); ok { + exportRouteFilters := exportRouteFiltersInputList.([]interface{}) + + for _, exportRouteFilter := range exportRouteFilters { + filtersData := exportRouteFilter.(map[string]interface{}) + + // Construct an instance of the Export Route Fileter Template model + exportRouteFilterTemplateModel := new(directlinkv1.GatewayTemplateRouteFilter) + exportRouteFilterTemplateModel.Action = NewStrPointer(filtersData[dlAction].(string)) + exportRouteFilterTemplateModel.Prefix = NewStrPointer(filtersData[dlPrefix].(string)) + exportRouteFilterTemplateModel.Ge = nil + exportRouteFilterTemplateModel.Le = nil + if _, ok := filtersData[dlGe]; ok { + exportRouteFilterTemplateModel.Ge = NewInt64Pointer(int64(filtersData[dlGe].(int))) + } + if _, ok := filtersData[dlLe]; ok { + exportRouteFilterTemplateModel.Le = NewInt64Pointer(int64(filtersData[dlLe].(int))) + } + exportRouteFiltersReplaceList = append(exportRouteFiltersReplaceList, *exportRouteFilterTemplateModel) + } + } + replaceGatewayExportRouteFiltersOptionsModel := new(directlinkv1.ReplaceGatewayExportRouteFiltersOptions) + replaceGatewayExportRouteFiltersOptionsModel.GatewayID = core.StringPtr(ID) + replaceGatewayExportRouteFiltersOptionsModel.ExportRouteFilters = exportRouteFiltersReplaceList + replaceGatewayExportRouteFiltersOptionsModel.IfMatch = core.StringPtr(etag) + replaceGatewayExportRouteFiltersOptionsModel.Headers = map[string]string{"If-Match": etag} + + /* after updating the Asprepends , waiting for + gateway to move to provisioned state + */ + _, err = isWaitForDirectLinkAvailable(directLink, ID, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return err + } + _, response, err := directLink.ReplaceGatewayExportRouteFilters(replaceGatewayExportRouteFiltersOptionsModel) + if err != nil { + log.Printf("[DEBUG] Error while replacing Export Route Fileter to a gateway id %s %s\n%s", ID, err, response) + return fmt.Errorf("[ERROR] Error while replacing Export Route Fileter to a gateway id %s %s\n%s", ID, err, response) + } + } + + if d.HasChange(dlImportRouteFilters) { + listGatewayImportRouteFiltersOptionsModel := &directlinkv1.ListGatewayImportRouteFiltersOptions{GatewayID: &ID} + _, response, operationErr := directLink.ListGatewayImportRouteFilters(listGatewayImportRouteFiltersOptionsModel) + if operationErr != nil { + log.Printf("[DEBUG] Error listing the Direct Link Import Route Filters %s\n%s", operationErr, response) + return fmt.Errorf("[ERROR] Error listing Direct Link Gateway Import Route Filters %s\n%s", operationErr, response) + } + etag := response.GetHeaders().Get("etag") + importRouteFiltersReplaceList := make([]directlinkv1.GatewayTemplateRouteFilter, 0) + if importRouteFiltersInputList, ok := d.GetOk(dlImportRouteFilters); ok { + importRouteFilters := importRouteFiltersInputList.([]interface{}) + + for _, importRouteFilter := range importRouteFilters { + filtersData := importRouteFilter.(map[string]interface{}) + + // Construct an instance of the Export Route Fileter Template model + importRouteFilterTemplateModel := new(directlinkv1.GatewayTemplateRouteFilter) + importRouteFilterTemplateModel.Action = NewStrPointer(filtersData[dlAction].(string)) + importRouteFilterTemplateModel.Prefix = NewStrPointer(filtersData[dlPrefix].(string)) + importRouteFilterTemplateModel.Ge = nil + importRouteFilterTemplateModel.Le = nil + if _, ok := filtersData[dlGe]; ok { + importRouteFilterTemplateModel.Ge = NewInt64Pointer(int64(filtersData[dlGe].(int))) + } + if _, ok := filtersData[dlLe]; ok { + importRouteFilterTemplateModel.Le = NewInt64Pointer(int64(filtersData[dlLe].(int))) + } + importRouteFiltersReplaceList = append(importRouteFiltersReplaceList, *importRouteFilterTemplateModel) + } + } + replaceGatewayImportRouteFiltersOptionsModel := new(directlinkv1.ReplaceGatewayImportRouteFiltersOptions) + replaceGatewayImportRouteFiltersOptionsModel.GatewayID = core.StringPtr(ID) + replaceGatewayImportRouteFiltersOptionsModel.ImportRouteFilters = importRouteFiltersReplaceList + replaceGatewayImportRouteFiltersOptionsModel.IfMatch = core.StringPtr(etag) + replaceGatewayImportRouteFiltersOptionsModel.Headers = map[string]string{"If-Match": etag} + + /* after updating the export route filter , waiting for + gatewat to move to provisioned state + */ + _, err = isWaitForDirectLinkAvailable(directLink, ID, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return err + } + _, response, err := directLink.ReplaceGatewayImportRouteFilters(replaceGatewayImportRouteFiltersOptionsModel) + if err != nil { + log.Printf("[DEBUG] Error while replacing Import Route Fileter to a gateway id %s %s\n%s", ID, err, response) + return fmt.Errorf("[ERROR] Error while replacing Import Route Fileter to a gateway id %s %s\n%s", ID, err, response) + } + + } /* NOTE: Operational Status cannot be maintained in terraform. The status keeps changing automatically in server side. Hence, cannot be maintained in terraform. @@ -1108,6 +1521,12 @@ 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)) + } + if d.HasChange(dlDefault_import_route_filter) { + updateGatewayOptionsModel.DefaultImportRouteFilter = NewStrPointer(d.Get(dlDefault_import_route_filter).(string)) + } if d.HasChange(dlGlobal) { global := d.Get(dlGlobal).(bool) updateGatewayOptionsModel.Global = &global diff --git a/ibm/service/directlink/resource_ibm_dl_gateway_test.go b/ibm/service/directlink/resource_ibm_dl_gateway_test.go index 472bfd60a0..a80d07e75e 100644 --- a/ibm/service/directlink/resource_ibm_dl_gateway_test.go +++ b/ibm/service/directlink/resource_ibm_dl_gateway_test.go @@ -9,13 +9,13 @@ import ( "log" "testing" - acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" - "github.com/IBM/networking-go-sdk/directlinkv1" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" ) func TestAccIBMDLGateway_basic(t *testing.T) { @@ -54,6 +54,10 @@ func TestAccIBMDLGateway_basic(t *testing.T) { func TestAccIBMDLGatewayConnect_basic(t *testing.T) { var instance string connectgatewayname := fmt.Sprintf("gateway-connect-%d", acctest.RandIntRange(10, 100)) + exprefix := "10.0.0.0/16" + exupdatedPrefix := "10.0.0.0/17" + imprefix := "10.0.0.0/16" + imupdatedPrefix := "10.0.0.0/17" resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -63,11 +67,22 @@ func TestAccIBMDLGatewayConnect_basic(t *testing.T) { { //dl connect test case - Config: testAccCheckIBMDLConnectGatewayConfig(connectgatewayname), + Config: testAccCheckIBMDLConnectGatewayConfig(connectgatewayname, exprefix, imprefix), Check: resource.ComposeTestCheckFunc( testAccCheckIBMDLGatewayExists("ibm_dl_gateway.test_dl_connect", instance), resource.TestCheckResourceAttr("ibm_dl_gateway.test_dl_connect", "name", connectgatewayname), - // resource.TestCheckResourceAttrSet("ibm_dl_gateway.test_dl_connect", "as_prepends.#"), + resource.TestCheckResourceAttr("data.ibm_dl_export_route_filter.test_dl_export_route_filter", "prefix", exprefix), + resource.TestCheckResourceAttr("data.ibm_dl_import_route_filter.test_dl_import_route_filter", "prefix", imprefix), + //resource.TestCheckResourceAttrSet("ibm_dl_gateway.test_dl_connect", "as_prepends.#"), + ), + }, + { + //Update test case + Config: testAccCheckIBMDLConnectGatewayConfig(connectgatewayname, exupdatedPrefix, imupdatedPrefix), + Check: resource.ComposeTestCheckFunc( + testAccCheckIBMDLGatewayExists("ibm_dl_gateway.test_dl_connect", instance), + resource.TestCheckResourceAttr("data.ibm_dl_export_route_filter.test_dl_export_route_filter", "prefix", exupdatedPrefix), + resource.TestCheckResourceAttr("data.ibm_dl_import_route_filter.test_dl_import_route_filter", "prefix", imupdatedPrefix), ), }, }, @@ -96,9 +111,9 @@ func testAccCheckIBMDLGatewayConfig(gatewayname, custname, carriername string) s `, gatewayname, custname, carriername) } -func testAccCheckIBMDLConnectGatewayConfig(gatewayname string) string { +func testAccCheckIBMDLConnectGatewayConfig(gatewayname string, exprefix string, imprefix string) string { return fmt.Sprintf(` - data "ibm_dl_ports" "test_ds_dl_ports" { + data "ibm_dl_ports" "ds_dlports" { } resource "ibm_dl_gateway" "test_dl_connect" { bgp_asn = 64999 @@ -107,10 +122,37 @@ func testAccCheckIBMDLConnectGatewayConfig(gatewayname string) string { name = "%s" speed_mbps = 1000 type = "connect" - port = data.ibm_dl_ports.test_ds_dl_ports.ports[0].port_id + port = data.ibm_dl_ports.ds_dlports.ports[0].port_id + export_route_filters { + action = "deny" + prefix = "%s" + ge =17 + le = 28 + } + import_route_filters { + action = "deny" + prefix = "%s" + ge =17 + le = 28 + } } - `, gatewayname) + data "ibm_dl_export_route_filters" "test_dl_export_route_filters" { + gateway = ibm_dl_gateway.test_dl_connect.id + } + data "ibm_dl_export_route_filter" "test_dl_export_route_filter" { + gateway = ibm_dl_gateway.test_dl_connect.id + id = data.ibm_dl_export_route_filters.test_dl_export_route_filters.export_route_filters[0].export_route_filter_id + } + data "ibm_dl_import_route_filters" "test_dl_import_route_filters" { + gateway = ibm_dl_gateway.test_dl_connect.id + } + data "ibm_dl_import_route_filter" "test_dl_import_route_filter" { + gateway = ibm_dl_gateway.test_dl_connect.id + id = data.ibm_dl_import_route_filters.test_dl_import_route_filters.import_route_filters[0].import_route_filter_id + } + `, gatewayname, exprefix, imprefix) } + func directlinkClient(meta interface{}) (*directlinkv1.DirectLinkV1, error) { sess, err := meta.(conns.ClientSession).DirectlinkV1API() return sess, err diff --git a/website/docs/d/dl_export_route_filter.html.markdown b/website/docs/d/dl_export_route_filter.html.markdown new file mode 100644 index 0000000000..ab3a6b01b3 --- /dev/null +++ b/website/docs/d/dl_export_route_filter.html.markdown @@ -0,0 +1,42 @@ + +subcategory: "Direct Link Gateway" +layout: "ibm" +page_title: "IBM : # dl_export_route_filter" +description: |- + Manages IBM Cloud Infrastructure Direct Link Gateway. +--- + +# dl_export_route_filter + +Import the details of an existing IBM Cloud Infrastructure Direct Link Gateway and its virtual connections. For more information, about IBM Cloud Direct Link, see [getting started with IBM Cloud Direct Link](https://cloud.ibm.com/docs/dl?topic=dl-get-started-with-ibm-cloud-dl). + + +## Example usage + +--- +```terraform +data "dl_export_route_filter" "test_dl_export_route_filter" { + gateway = ibm_dl_gateway.test_dl_gateway.id + ex_filter_id = ibm_dl_gateway.test_dl_gateway.export_route_filters[0].ex_filter_id +} +``` +--- +## Argument reference +Review the argument reference that you can specify for your resource. + +- `gateway`- (Required, String) Direct Link Gateway ID. +- `ex_filter_id` - (Required, String) Export Route Filter ID + + +## Attribute reference +In addition to the argument reference list, you can access the following attribute references after your data source is created. + +- `created_at` - (String) The date and time resource is created. +- `id` - (String) The unique identifier of Export Route Filter. +- `action` - (String) Whether to permit or deny the prefix filter. +- `before` - (String) Identifier of prefix filter that handles the ordering and follow semantics. When a filter reference another filter in it's before field, then the filter making the reference is applied before the referenced filter. For example: if filter A references filter B in its before field, A is applied before B. +- `ge` - (Int) The minimum matching length of the prefix-set. +- `le` - (Int) The maximum matching length of the prefix-set. +- `prefix` - (String) IP prefix representing an address and mask length of the prefix-set. +- `updated_at` - (String) The date and time resource is last updated. + diff --git a/website/docs/d/dl_export_route_filters.html.markdown b/website/docs/d/dl_export_route_filters.html.markdown new file mode 100644 index 0000000000..3d71f1900e --- /dev/null +++ b/website/docs/d/dl_export_route_filters.html.markdown @@ -0,0 +1,43 @@ + +subcategory: "Direct Link Gateway" +layout: "ibm" +page_title: "IBM : dl_export_route_filters" +description: |- + Manages IBM Cloud Infrastructure Direct Link Gateway. +--- + +# dl_export_route_filters + +Import the details of an existing IBM Cloud Infrastructure Direct Link Gateway and its virtual connections. For more information, about IBM Cloud Direct Link, see [getting started with IBM Cloud Direct Link](https://cloud.ibm.com/docs/dl?topic=dl-get-started-with-ibm-cloud-dl). + + +## Example usage + +--- +```terraform +data "dl_export_route_filters" "test_dl_export_route_filters" { + gateway = ibm_dl_gateway.test_dl_gateway.id +} +``` +--- +## Argument reference +Review the argument reference that you can specify for your resource. + +- `gateway`- (Required, String) Direct Link Gateway ID. + + +## Attribute reference +In addition to the argument reference list, you can access the following attribute references after your data source is created. + +- `export_route_filters` - List of all export route filters for a given direct link gateway. + + Nested scheme for `export_route_filters`: + - `created_at` - (String) The date and time resource is created. + - `ex_filter_id` - (String) The unique identifier of Export Route Filter. + - `action` - (String) Whether to permit or deny the prefix filter. + - `before` - (String) Identifier of prefix filter that handles the ordering and follow semantics. When a filter reference another filter in it's before field, then the filter making the reference is applied before the referenced filter. For example: if filter A references filter B in its before field, A is applied before B. + - `ge` - (Int) The minimum matching length of the prefix-set. + - `le` - (Int) The maximum matching length of the prefix-set. + - `prefix` - (String) IP prefix representing an address and mask length of the prefix-set. + - `updated_at` - (String) The date and time resource is last updated. + diff --git a/website/docs/d/dl_gateway.html.markdown b/website/docs/d/dl_gateway.html.markdown index 37af74a901..e166704787 100644 --- a/website/docs/d/dl_gateway.html.markdown +++ b/website/docs/d/dl_gateway.html.markdown @@ -1,4 +1,4 @@ ---- + subcategory: "Direct Link Gateway" layout: "ibm" page_title: "IBM : dl_gateway" @@ -13,13 +13,13 @@ Import the details of an existing IBM Cloud Infrastructure Direct Link Gateway a ## Example usage +--- ```terraform data "ibm_dl_gateway" "test_dl_gateway_vc" { name = "mygateway" } ``` - - +--- ## Argument reference Review the argument reference that you can specify for your resource. @@ -30,7 +30,6 @@ Review the argument reference that you can specify for your resource. In addition to the argument reference list, you can access the following attribute references after your data source is created. - `as_prepends` - (List) List of AS Prepend configuration information - Nested scheme for `as_prepend`: - `created_at`- (String) The date and time AS Prepend was created. - `id` - (String) The unique identifier for this AS Prepend. @@ -39,7 +38,6 @@ In addition to the argument reference list, you can access the following attribu - `prefix` - (Deprecated, String) Comma separated list of prefixes this AS Prepend applies to. Maximum of 10 prefixes. If not specified, this AS Prepend applies to all prefixes. - `specific_prefixes` - (Array of Strings) Array of prefixes this AS Prepend applies to. - `updated_at`- (String) The date and time AS Prepend was updated - - `authentication_key` - (String) BGP MD5 authentication key. - `bfd_interval` - (String) Minimum interval in milliseconds at which the local routing device transmits hello packets and then expects to receive a reply from a neighbor with which it has established a BFD session. - `bfd_multiplier` - (String) The number of hello packets not received by a neighbor that causes the originating interface to be declared down. @@ -51,6 +49,9 @@ In addition to the argument reference list, you can access the following attribu - `bgp_ibm_asn` - (String) The IBM BGP ASN. - `bgp_ibm_cidr` - (String) The IBM BGP CIDR. - `bgp_status` - (String) The gateway BGP status. +- `bgp_status_updated_at` - (String) Date and time bgp status was updated. +- `default_export_route_filter` - (String) The default directional route filter action that applies to routes that do not match any directional route filters. +- `default_import_route_filter` - (String) The default directional route filter action that applies to routes that do not match any directional route filters. - `created_at` - (String) The date and time resource is created. - `crn` - (String) The CRN of the gateway. - `completion_notice_reject_reason` - (String) The reason for completion notice rejection. Only included on a dedicated gateways type with a rejected completion notice. @@ -61,6 +62,7 @@ In addition to the argument reference list, you can access the following attribu - `location_display_name` - (String) Long name of the gateway location. - `location_name` - (String) The location name of the gateway. - `link_status` - (String) The gateway link status. Only included on a dedicated gateways type. +- `link_status_updated_at` - (String) Date and time link status was updated. - `metered` - (String) Metered billing option. If set **true** gateway usage is billed per GB. Otherwise, flat rate is charged for the gateway. - `operational_status` - (String) The gateway operational statu. - `port` - (Integer) The port identifier. diff --git a/website/docs/d/dl_gateways.html.markdown b/website/docs/d/dl_gateways.html.markdown index aec9d6fc21..333b617468 100644 --- a/website/docs/d/dl_gateways.html.markdown +++ b/website/docs/d/dl_gateways.html.markdown @@ -1,4 +1,4 @@ ---- + subcategory: "Direct Link Gateway" layout: "ibm" page_title: "IBM : dl_gateways" @@ -13,12 +13,13 @@ Import the details of an existing IBM Cloud Infrastructure Direct Link Gateways. ## Example usage +--- ```terraform data "ibm_dl_gateways" "ds_dlgateways" { } ``` - +--- ## Argument reference There is no argument reference that you need to specify for the data source. @@ -30,16 +31,14 @@ You can access the following attribute references after your data source is crea Nested scheme for `gateways`: - `as_prepends` - (List) List of AS Prepend configuration information - Nested scheme for `as_prepend`: - - `created_at`- (String) The date and time AS Prepend was created. - - `id` - (String) The unique identifier for this AS Prepend. - - `length` - (Integer) Number of times the ASN to appended to the AS Path. - - `policy` - (String) Route type this AS Prepend applies to. Possible values are `import` and `export`. - - `prefix` - (Deprecated, String) Comma separated list of prefixes this AS Prepend applies to. Maximum of 10 prefixes. If not specified, this AS Prepend applies to all prefixes. - - `specific_prefixes` - (Array of Strings) Array of prefixes this AS Prepend applies to. - - `updated_at`- (String) The date and time AS Prepend was updated - + - `created_at`- (String) The date and time AS Prepend was created. + - `id` - (String) The unique identifier for this AS Prepend. + - `length` - (Integer) Number of times the ASN to appended to the AS Path. + - `policy` - (String) Route type this AS Prepend applies to. Possible values are `import` and `export`. + - `prefix` - (Deprecated, String) Comma separated list of prefixes this AS Prepend applies to. Maximum of 10 prefixes. If not specified, this AS Prepend applies to all prefixes. + - `specific_prefixes` - (Array of Strings) Array of prefixes this AS Prepend applies to. + - `updated_at`- (String) The date and time AS Prepend was updated - `authentication_key` - (String) BGP MD5 authentication key. - `bfd_interval` - (String) Minimum interval in milliseconds at which the local routing device transmits hello packets and then expects to receive a reply from a neighbor with which it has established a BFD session. - `bfd_multiplier` - (String) The number of hello packets not received by a neighbor that causes the originating interface to be declared down. @@ -51,10 +50,14 @@ You can access the following attribute references after your data source is crea - `bgp_ibm_asn` - (String) The IBM BGP ASN. - `bgp_ibm_cidr` - (String) The IBM BGP CIDR. - `bgp_status` - (String) The gateway BGP status. + - `bgp_status_updated_at` - (String) Date and time bgp status was updated. + - `default_export_route_filter` - (String) The default directional route filter action that applies to routes that do not match any directional route filters. + - `default_import_route_filter` - (String) The default directional route filter action that applies to routes that do not match any directional route filters. - `completion_notice_reject_reason` - (String) The reason for completion notice rejection. Only included on a dedicated gateways type with a rejected completion notice. - `connection_mode` - (String) Type of network connection that you want to bind to your direct link. - `cross_connect_router` - (String) The cross connect router. Only included on a dedicated gateways type.. - `link_status` - (String) The gateway link status. Only included on a dedicated gateways type. + - `link_status_updated_at` - (String) Date and time link status was updated. - `created_at` - (String) The date and time resource is created. - `crn` - (String) The CRN of the gateway. - `global` - (Bool) Gateway with global routing as **true** can connect networks outside your associated region. diff --git a/website/docs/d/dl_import_route_filter.html.markdown b/website/docs/d/dl_import_route_filter.html.markdown new file mode 100644 index 0000000000..39355ba454 --- /dev/null +++ b/website/docs/d/dl_import_route_filter.html.markdown @@ -0,0 +1,42 @@ + +subcategory: "Direct Link Gateway" +layout: "ibm" +page_title: "IBM : # dl_import_route_filter" +description: |- + Manages IBM Cloud Infrastructure Direct Link Gateway. +--- + +# dl_import_route_filter + +Import the details of an existing IBM Cloud Infrastructure Direct Link Gateway and its virtual connections. For more information, about IBM Cloud Direct Link, see [getting started with IBM Cloud Direct Link](https://cloud.ibm.com/docs/dl?topic=dl-get-started-with-ibm-cloud-dl). + + +## Example usage + +--- +```terraform +data "dl_import_route_filter" "test_dl_import_route_filter" { + gateway = ibm_dl_gateway.test_dl_gateway.id + im_filter_id = ibm_dl_gateway.test_dl_gateway.import_route_filters[0].im_filter_id +} +``` +--- +## Argument reference +Review the argument reference that you can specify for your resource. + +- `gateway`- (Required, String) Direct Link Gateway ID. +- `im_filter_id` - (Required, String) Import Route Filter ID + + +## Attribute reference +In addition to the argument reference list, you can access the following attribute references after your data source is created. + +- `created_at` - (String) The date and time resource is created. +- `id` - (String) The unique identifier of Import Route Filter. +- `action` - (String) Whether to permit or deny the prefix filter. +- `before` - (String) Identifier of prefix filter that handles the ordering and follow semantics. When a filter reference another filter in it's before field, then the filter making the reference is applied before the referenced filter. For example: if filter A references filter B in its before field, A is applied before B. +- `ge` - (Int) The minimum matching length of the prefix-set. +- `le` - (Int) The maximum matching length of the prefix-set. +- `prefix` - (String) IP prefix representing an address and mask length of the prefix-set. +- `updated_at` - (String) The date and time resource is last updated. + diff --git a/website/docs/d/dl_import_route_filters.html.markdown b/website/docs/d/dl_import_route_filters.html.markdown new file mode 100644 index 0000000000..dda8b94cd5 --- /dev/null +++ b/website/docs/d/dl_import_route_filters.html.markdown @@ -0,0 +1,43 @@ + +subcategory: "Direct Link Gateway" +layout: "ibm" +page_title: "IBM : dl_import_route_filters" +description: |- + Manages IBM Cloud Infrastructure Direct Link Gateway. +--- + +# dl_import_route_filters + +Import the details of an existing IBM Cloud Infrastructure Direct Link Gateway and its virtual connections. For more information, about IBM Cloud Direct Link, see [getting started with IBM Cloud Direct Link](https://cloud.ibm.com/docs/dl?topic=dl-get-started-with-ibm-cloud-dl). + + +## Example usage + +--- +```terraform +data "dl_import_route_filters" "test_dl_import_route_filters" { + gateway = ibm_dl_gateway.test_dl_gateway.id +} +``` +--- +## Argument reference +Review the argument reference that you can specify for your resource. + +- `gateway`- (Required, String) Direct Link Gateway ID. + + +## Attribute reference +In addition to the argument reference list, you can access the following attribute references after your data source is created. + +- `import_route_filters` - List of all import route filters for a given direct link gateway. + + Nested scheme for `import_route_filters`: + - `created_at` - (String) The date and time resource is created. + - `im_filter_id` - (String) The unique identifier of Import Route Filter. + - `action` - (String) Whether to permit or deny the prefix filter. + - `before` - (String) Identifier of prefix filter that handles the ordering and follow semantics. When a filter reference another filter in it's before field, then the filter making the reference is applied before the referenced filter. For example: if filter A references filter B in its before field, A is applied before B. + - `ge` - (Int) The minimum matching length of the prefix-set. + - `le` - (Int) The maximum matching length of the prefix-set. + - `prefix` - (String) IP prefix representing an address and mask length of the prefix-set. + - `updated_at` - (String) The date and time resource is last updated. + diff --git a/website/docs/r/cis_domain_settings.html.markdown b/website/docs/r/cis_domain_settings.html.markdown index 94e9d5edf5..0cf1282fa7 100644 --- a/website/docs/r/cis_domain_settings.html.markdown +++ b/website/docs/r/cis_domain_settings.html.markdown @@ -1,4 +1,3 @@ ---- subcategory: "Internet services" layout: "ibm" @@ -13,6 +12,7 @@ Customize the IBM Cloud Internet Services domain settings. For more information, ## Example usage 1 +--- ```terraform resource "ibm_cis_domain_settings" "test_domain_settings" { cis_id = data.ibm_cis.cis.id @@ -55,6 +55,7 @@ resource "ibm_cis_domain_settings" "test_domain_settings" { include_subdomains = false max_age = 0 nosniff = false + preload = false } mobile_redirect { status = "on" @@ -71,9 +72,11 @@ resource "ibm_cis_domain_settings" "test" { min_tls_version = "1.2" } ``` +--- ## Example usage 2 : For TLS v1.3 +--- ```terraform resource "ibm_cis_domain_settings" "test_domain_settings" { cis_id = data.ibm_cis.cis.id @@ -116,6 +119,7 @@ resource "ibm_cis_domain_settings" "test_domain_settings" { include_subdomains = false max_age = 0 nosniff = false + preload = false } mobile_redirect { status = "on" @@ -132,6 +136,7 @@ resource "ibm_cis_domain_settings" "test" { min_tls_version = "1.3" } ``` +--- ## Argument reference Review the argument references that you can specify for your resource. @@ -178,6 +183,7 @@ Review the argument references that you can specify for your resource. - `security_header.include_subdomains`- (Bool) Required-Supported values are **true** and **false**. - `security_header.max_age`- (Required, Integer) Maximum age of the security header. - `security_header.nosniff`- (Bool) Required-No sniff. +- `security_header.preload`- (Required, Bool) Whether or not to permit browsers to preload security_header config. - `ssl` - (Optional, String) Allowed values: `off`, `flexible`, `full`, `strict`, `origin_pull`. - `tls_client_auth` - (Optional, String) Supported values are `off` and `on`. - `true_client_ip_header` - (Optional, String) Supported values are `off` and `on`. diff --git a/website/docs/r/dl_gateway.html.markdown b/website/docs/r/dl_gateway.html.markdown index 313b493b42..46afa1c90d 100644 --- a/website/docs/r/dl_gateway.html.markdown +++ b/website/docs/r/dl_gateway.html.markdown @@ -1,4 +1,4 @@ ---- + subcategory: "Direct Link Gateway" layout: "ibm" page_title: "IBM : dl_gateway" @@ -14,6 +14,7 @@ Create, update, or delete a Direct Link Gateway by using the Direct Link Gateway ## Example usage to create Direct Link of dedicated type In the following example, you can create Direct Link of dedicated type: +--- ```terraform data "ibm_dl_routers" "test_dl_routers" { offering_type = "dedicated" @@ -21,6 +22,20 @@ data "ibm_dl_routers" "test_dl_routers" { } resource ibm_dl_gateway test_dl_gateway { + export_route_filters { + action = "deny" + prefix = "150.167.10.0/12" + ge =19 + le = 29 + } + import_route_filters { + action = "permit" + prefix = "140.167.10.0/12" + ge =17 + le = 30 + } + default_export_route_filter = "permit" + default_import_route_filter = "deny" bgp_asn = 64999 global = true metered = false @@ -35,11 +50,12 @@ resource ibm_dl_gateway test_dl_gateway { } ``` - +--- ## Sample usage to create Direct Link of connect type In the following example, you can create Direct Link of connect type: +--- ```terraform data "ibm_dl_ports" "test_ds_dl_ports" { @@ -56,7 +72,20 @@ resource "ibm_dl_gateway" "test_dl_connect" { policy = "export" specific_prefixes = ["10.10.9.0/24","10.10.10.0/24"] } - + export_route_filters { + action = "deny" + prefix = "150.167.10.0/12" + ge =19 + le = 29 + } + import_route_filters { + action = "permit" + prefix = "140.167.10.0/12" + ge =17 + le = 30 + } + default_export_route_filter = "permit" + default_import_route_filter = "deny" bgp_asn = 64999 global = true metered = false @@ -66,18 +95,30 @@ resource "ibm_dl_gateway" "test_dl_connect" { port = data.ibm_dl_ports.test_ds_dl_ports.ports[0].port_id } ``` - +--- ## Argument reference Review the argument reference that you can specify for your resource. - `as_prepends` - (Optional, List) List of AS Prepend configuration information - - Nested scheme for `as_prepend`: + + Nested scheme for `as_prepend`: - `length` - (Required, Integer ) Number of times the ASN to appended to the AS Path. - `policy` - (Required, String) Route type this AS Prepend applies to. Possible values are `import` and `export`. - `prefix` - (Optional, Deprecated, String) Comma separated list of prefixes this AS Prepend applies to. Maximum of 10 prefixes. If not specified, this AS Prepend applies to all prefixes. prefix will be deprecated and support will be removed. Use specific_prefixes instead - `specific_prefixes` - (Optional, Array of Strings) Array of prefixes this AS Prepend applies to. If this property is absent, the AS Prepend applies to all prefixes. +- `export_route_filters` - (Optional, List) List of Export Route Filter configuration information. + Nested scheme for `export_route_filter`: + - `action` - (Required, String) Determines whether the routes that match the prefix-set will be permit or deny + - `prefix` - (Required, String) IP prefix representing an address and mask length of the prefix-set + - `ge` - (Optional, Integer) The minimum matching length of the prefix-set + - `le` - (Optional, Integer) The maximum matching length of the prefix-set +- `import_route_filters` - (Optional, List) List of Import Route Filter configuration information. + Nested scheme for `import_route_filter`: + - `action` - (Required, String) Determines whether the routes that match the prefix-set will be permit or deny + - `prefix` - (Required, String) IP prefix representing an address and mask length of the prefix-set + - `ge` - (Optional, Integer) The minimum matching length of the prefix-set + - `le` - (Optional, Integer) The maximum matching length of the prefix-set - `authentication_key` - (Optional, String) BGP MD5 authentication key. - `bfd_interval` - (String) Minimum interval in milliseconds at which the local routing device transmits hello packets and then expects to receive a reply from a neighbor with which it has established a BFD session. - `bfd_multiplier` - (String) The number of hello packets not received by a neighbor that causes the originating interface to be declared down. @@ -97,31 +138,33 @@ Review the argument reference that you can specify for your resource. - `resource_group` - (Optional, Forces new resource, String) The resource group. If unspecified, the account's default resource group is used. - `speed_mbps`- (Required, Integer) The gateway speed in MBPS. For example, `10.254.30.78/30`. - `type` - (Required, Forces new resource, String) The gateway type, allowed values are `dedicated` and `connect`. +- `default_export_route_filter` - (String) The default directional route filter action that applies to routes that do not match any directional route filters. +- `default_import_route_filter` - (String) The default directional route filter action that applies to routes that do not match any directional route filters. ## Attribute reference In addition to all argument references list, you can access the following attribute references after your resource is created. -- `as_prepends` - (List) List of AS Prepend configuration information - Nested scheme for `as_prepend`: + + + + +- `as_prepends` - (List) List of AS Prepend configuration informationNested scheme for - `created_at`- (String) The date and time AS Prepend was created. - `id` - (String) The unique identifier for this AS Prepend. - `updated_at`- (String) The date and time AS Prepend was updated. - - `bfd_status` - (String) Gateway BFD status - `bfd_status_updated_at` - (String) Date and time BFD status was updated at -- `bgp_asn` - (String) The IBM BGP ASN. - `bgp_status` - (String) The gateway BGP status. +- `bgp_status_updated_at` - (String) Date and time bgp status was updated. - `completion_notice_reject_reason` - (String) The reason for completion notice rejection. - `crn` - (String) The CRN of the gateway. - `created_at` - (String) The date and time resource created. - `id` - (String) The unique ID of the gateway. - `location_display_name` - (String) The gateway location long name. - `link_status` - (String) The gateway link status. You can include only on `type=dedicated` gateways. For example, `down`, `up`. -- `name` - (String) The unique user-defined name for the gateway. +- `link_status_updated_at` - (String) Date and time link status was updated. - `operational_status` - (String) The gateway operational status. For gateways pending LOA approval, patch operational_status to the appropriate value to approve or reject its LOA. For example, `loa_accepted`. -- `port` - (String) The gateway port for `type=connect` gateways. - `provider_api_managed` - (String) Indicates whether gateway changes need to be made via a provider portal. -- `resource_group` - (String) The resource group reference. - `vlan` - (String) The VLAN allocated for the gateway. You can set only for `type=connect` gateways created directly through the IBM portal. **Note** @@ -133,13 +176,15 @@ The `ibm_dl_gateway` resource can be imported by using gateway ID. **Syntax** +--- ``` $ terraform import ibm_dl_gateway.example ``` - +--- **Example** +--- ``` $ terraform import ibm_dl_gateway.example 5ffda12064634723b079acdb018ef308 ``` - +---