-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added directlink provider datasource
- Loading branch information
Showing
7 changed files
with
330 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
package ibm | ||
|
||
import ( | ||
dlProviderV2 "github.com/IBM/networking-go-sdk/directlinkproviderv2" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"log" | ||
"time" | ||
) | ||
|
||
const ( | ||
dlProviderGateways = "gateways" | ||
dlProviderGatewaysID = "id" | ||
) | ||
|
||
func dataSourceIBMDirectLinkProviderGateways() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceIBMDirectLinkProviderGatewaysRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
|
||
dlProviderGateways: { | ||
|
||
Type: schema.TypeList, | ||
Description: "Collection of direct link provider ports", | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
|
||
Schema: map[string]*schema.Schema{ | ||
dlProviderGatewaysID: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Id of the data source gateways", | ||
}, | ||
dlBgpAsn: { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "BGP ASN", | ||
}, | ||
|
||
dlBgpCerCidr: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "BGP customer edge router CIDR", | ||
}, | ||
dlBgpIbmAsn: { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "IBM BGP ASN", | ||
}, | ||
dlBgpIbmCidr: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "BGP IBM CIDR", | ||
}, | ||
dlBgpStatus: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Gateway BGP status", | ||
}, | ||
customerAccountID: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Customer IBM Cloud account ID for the new gateway. A gateway object containing the pending create request will become available in the specified account.", | ||
}, | ||
dlCreatedAt: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The date and time resource was created", | ||
}, | ||
dlCrn: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The CRN (Cloud Resource Name) of this gateway", | ||
}, | ||
|
||
dlName: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The unique user-defined name for this gateway", | ||
}, | ||
dlOperationalStatus: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Gateway operational status", | ||
}, | ||
dlChangeRequest: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Changes pending approval for provider managed Direct Link gateways", | ||
}, | ||
dlPort: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Gateway port", | ||
}, | ||
dlProviderAPIManaged: { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Indicates whether gateway was created through a provider portal", | ||
}, | ||
dlResourceGroup: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Gateway resource group", | ||
}, | ||
dlSpeedMbps: { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Gateway speed in megabits per second", | ||
}, | ||
dlType: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Gateway type", | ||
}, | ||
dlVlan: { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "VLAN allocated for this gateway", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceIBMDirectLinkProviderGatewaysRead(d *schema.ResourceData, meta interface{}) error { | ||
directLinkProvider, err := directlinkProviderClient(meta) | ||
if err != nil { | ||
return err | ||
} | ||
start := "" | ||
allrecs := []dlProviderV2.ProviderGateway{} | ||
for { | ||
listProviderGatewaysOptions := directLinkProvider.NewListProviderGatewaysOptions() | ||
if start != "" { | ||
listProviderGatewaysOptions.Start = &start | ||
} | ||
|
||
providerGateways, resp, err := directLinkProvider.ListProviderGateways(listProviderGatewaysOptions) | ||
if err != nil { | ||
log.Println("[WARN] Error listing dl provider gateways", providerGateways, resp, err) | ||
return err | ||
} | ||
start = GetNext(providerGateways.Next) | ||
allrecs = append(allrecs, providerGateways.Gateways...) | ||
if start == "" { | ||
break | ||
} | ||
} | ||
gatewayCollections := make([]map[string]interface{}, 0) | ||
for _, instance := range allrecs { | ||
gatewayCollection := map[string]interface{}{} | ||
|
||
if instance.ID != nil { | ||
gatewayCollection[dlProviderGatewaysID] = *instance.ID | ||
} | ||
if instance.Name != nil { | ||
gatewayCollection[dlName] = *instance.Name | ||
} | ||
if instance.Crn != nil { | ||
gatewayCollection[dlCrn] = *instance.Crn | ||
} | ||
if instance.BgpAsn != nil { | ||
gatewayCollection[dlBgpAsn] = *instance.BgpAsn | ||
} | ||
if instance.BgpIbmCidr != nil { | ||
gatewayCollection[dlBgpIbmCidr] = *instance.BgpIbmCidr | ||
} | ||
if instance.BgpIbmAsn != nil { | ||
gatewayCollection[dlBgpIbmAsn] = *instance.BgpIbmAsn | ||
} | ||
|
||
if instance.BgpCerCidr != nil { | ||
gatewayCollection[dlBgpCerCidr] = *instance.BgpCerCidr | ||
} | ||
|
||
if instance.ProviderApiManaged != nil { | ||
gatewayCollection[dlProviderAPIManaged] = *instance.ProviderApiManaged | ||
} | ||
if instance.Type != nil { | ||
gatewayCollection[dlType] = *instance.Type | ||
} | ||
if instance.SpeedMbps != nil { | ||
gatewayCollection[dlSpeedMbps] = *instance.SpeedMbps | ||
} | ||
if instance.OperationalStatus != nil { | ||
gatewayCollection[dlOperationalStatus] = *instance.OperationalStatus | ||
} | ||
if instance.BgpStatus != nil { | ||
gatewayCollection[dlBgpStatus] = *instance.BgpStatus | ||
} | ||
if instance.Vlan != nil { | ||
gatewayCollection[dlVlan] = *instance.Vlan | ||
} | ||
|
||
if instance.Port != nil { | ||
gatewayCollection[dlPort] = *instance.Port.ID | ||
} | ||
|
||
if instance.CreatedAt != nil { | ||
gatewayCollection[dlCreatedAt] = instance.CreatedAt.String() | ||
} | ||
|
||
gatewayCollections = append(gatewayCollections, gatewayCollection) | ||
} | ||
d.SetId(dataSourceIBMDirectLinkProviderGatewaysReadID(d)) | ||
d.Set(dlProviderGateways, gatewayCollections) | ||
return nil | ||
} | ||
|
||
func dataSourceIBMDirectLinkProviderGatewaysReadID(d *schema.ResourceData) string { | ||
return time.Now().UTC().String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ibm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccIBMDLProviderGWsDataSource_basic(t *testing.T) { | ||
name := "dl_provider_gws" | ||
resName := "data.ibm_dl_provider_gateways.test_dl_provider_gws" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckIBMDLProviderGWsDataSourceConfig(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(resName, "id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckIBMDLProviderGWsDataSourceConfig(name string) string { | ||
return fmt.Sprintf(` | ||
data "ibm_dl_provider_gateways" "test_%s" { | ||
} | ||
`, name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
layout: "ibm" | ||
page_title: "IBM : dl_provider_gateways" | ||
sidebar_current: "docs-ibm-datasource-dl-provider-gateways" | ||
description: |- | ||
Manages IBM Cloud Infrastructure Direct Link Provider Gateway. | ||
--- | ||
|
||
# ibm\_dl_provider_gateways | ||
|
||
Import the details of an existing IBM Cloud Infrastructure direct link provider gateway as a read-only data source. You can then reference the fields of the data source in other resources within the same configuration using interpolation syntax. | ||
|
||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "ibm_dl_provider_gateways" "ds_dlproviderGateways" { | ||
} | ||
``` | ||
|
||
## Attribute Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `gateways` - List of all Direct Link provider gateways in the IBM Cloud Infrastructure. | ||
* `bgp_asn` - Customer BGP ASN. | ||
* `created_at` - The date and time resource was created. | ||
* `crn` - The CRN (Cloud Resource Name) of this gateway. | ||
* `global` - Gateways with global routing (true) can connect to networks outside their associated region. | ||
* `id` - The unique identifier of this gateway. | ||
* `name` - The unique user-defined name for this gateway. | ||
* `operational_status` - Gateway operational status. | ||
* `resource_group` - Resource group identifier. | ||
* `speed_mbps` - Gateway speed in megabits per second. | ||
* `type` - Gateway type. | ||
* `bgp_cer_cidr` - BGP customer edge router CIDR. | ||
* `bgp_ibm_asn` - IBM BGP ASN. | ||
* `bgp_ibm_cidr` - BGP IBM CIDR. | ||
* `bgp_status` - Gateway BGP status. | ||
* `port` - Port Identifier. | ||
* `provider_api_managed` - Indicates whether gateway was created through a provider portal. If true, gateway can only be changed or deleted through the corresponding provider portal. | ||
* `vlan` - VLAN allocated for this gateway. Only set for type=connect gateways created directly through the IBM portal. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters