-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat.] VPN: Add datasource enterprise vpn gateway (#2810)
[Feat.] VPN: Add datasource enterprise vpn gateway Summary of the Pull Request Adds data source for Enterprise VPN gateway. PR Checklist Refers to: #2807 Tests added/passed. Documentation updated. Schema updated. Release notes added. Acceptance Steps Performed === RUN TestAccVpnEnterpriseGatewayV5DataSource_basic --- PASS: TestAccVpnEnterpriseGatewayV5DataSource_basic (96.22s) PASS Reviewed-by: Aloento
- Loading branch information
1 parent
2aa7494
commit b023323
Showing
5 changed files
with
373 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
--- | ||
subcategory: "Virtual Private Network (VPN)" | ||
layout: "opentelekomcloud" | ||
page_title: "OpenTelekomCloud: opentelekomcloud_enterprise_vpn_gateway_v5" | ||
sidebar_current: "docs-opentelekomcloud-resource-enterprise-vpn-gateway-v5" | ||
description: |- | ||
Get details about a specific Enterprise VPN Gateway Service resource within OpenTelekomCloud. | ||
--- | ||
|
||
Up-to-date reference of API arguments for EVPN you can get at | ||
[documentation portal](https://docs.otc.t-systems.com/virtual-private-network/api-ref/api_reference_enterprise_edition_vpn/apis_of_enterprise_edition_vpn/vpn_gateway/index.html) | ||
|
||
|
||
# opentelekomcloud_enterprise_vpn_gateway_v5 | ||
|
||
Use this data source to get details about a specific Enterprise VPN gateway resource within OpenTelekomCloud. | ||
|
||
## Example Usage | ||
|
||
### Basic Usage | ||
|
||
```hcl | ||
variable "id" {} | ||
data "opentelekomcloud_enterprise_vpn_gateway_v5" "gw_1" { | ||
id = var.id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `id` - (Required, String) Specifies the unique ID of the Enterprise VPN gateway. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `name` - Indicates the name of the VPN gateway. | ||
|
||
* `availability_zones` - Indicates the list of availability zone IDs. | ||
|
||
* `flavor` - Indicates the flavor of the VPN gateway. | ||
|
||
* `attachment_type` - Indicates the attachment type. | ||
|
||
* `network_type` - Indicates the network type. | ||
|
||
* `vpc_id` - Indicates the ID of the VPC to which the VPN gateway is connected. | ||
|
||
* `local_subnets` - Indicates the list of local subnets. | ||
|
||
* `connect_subnet` - Indicates the Network ID of the VPC subnet used by the VPN gateway. | ||
|
||
* `er_id` - Indicates the enterprise router ID to attach with to VPN gateway. | ||
|
||
* `ha_mode` - Indicates the HA mode of VPN gateway. | ||
|
||
* `access_vpc_id` - Indicates the access VPC ID. | ||
|
||
* `access_subnet_id` - Indicates the access subnet ID. | ||
|
||
* `access_private_ip_1` - Indicates the private IP 1 in private network type VPN gateway. | ||
|
||
* `access_private_ip_2` - Indicates the private IP 2 in private network type VPN gateway. | ||
|
||
* `asn` - Indicates the ASN number of BGP. | ||
|
||
* `status` - Indicates the status of VPN gateway. | ||
|
||
* `created_at` - Indicates the create time. | ||
|
||
* `updated_at` - Indicates the update time. | ||
|
||
* `used_connection_group` - Indicates the number of used connection groups. | ||
|
||
* `used_connection_number` - Indicates the number of used connections. | ||
|
||
* `region` - Indicates the region in which resource is created. | ||
|
||
* `eip1` - Indicates the master 1 IP in active-active VPN gateway or the master IP in active-standby VPN gateway. | ||
The [object](#GatewayGetResponseEip) structure is documented below. | ||
|
||
* `eip2` - Indicates the master 2 IP in active-active VPN gateway or the slave IP in active-standby VPN gateway. | ||
The [object](#GatewayGetResponseEip) structure is documented below. | ||
|
||
<a name="GatewayGetResponseEip"></a> | ||
The `eip1` or `eip2` block supports: | ||
|
||
* `id` - Indicates the public IP ID. | ||
|
||
* `bandwidth_name` - Indicates the bandwidth name. | ||
|
||
* `bandwidth_size` - Indicates the Bandwidth size in Mbit/s. | ||
|
||
* `charge_mode` - Indicates the charge mode of the bandwidth. | ||
|
||
* `type` - Indicates the EIP type. | ||
|
||
* `bandwidth_id` - The bandwidth ID. | ||
|
||
* `ip_address` - The public IP address. | ||
|
||
* `ip_version` - Specifies the EIP version. |
50 changes: 50 additions & 0 deletions
50
...elekomcloud/acceptance/vpn/data_source_opentelekomcloud_enterprise_vpn_gateway_v5_test.go
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,50 @@ | ||
package acceptance | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common" | ||
) | ||
|
||
const dataVPNEnterpriseGatewayName = "data.opentelekomcloud_enterprise_vpn_gateway_v5.gw_1" | ||
|
||
func TestAccVpnEnterpriseGatewayV5DataSource_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { common.TestAccPreCheck(t) }, | ||
ProviderFactories: common.TestAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceVpnEnterpriseGatewayV5ConfigBasic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckVPNEnterpriseGatewayDataSourceID(dataVPNEnterpriseGatewayName), | ||
resource.TestCheckResourceAttrSet(dataVPNEnterpriseGatewayName, "name"), | ||
resource.TestCheckResourceAttrSet(dataVPNEnterpriseGatewayName, "vpc_id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckVPNEnterpriseGatewayDataSourceID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("can't find Enterprise VPN gateway data source: %s ", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("Enterprise VPN gateway data source ID not set ") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccDataSourceVpnEnterpriseGatewayV5ConfigBasic = ` | ||
data "opentelekomcloud_enterprise_vpn_gateway_v5" "gw_1" { | ||
id = "a7c33913-0eb3-40e2-a473-53c699592235" | ||
} | ||
` |
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
213 changes: 213 additions & 0 deletions
213
opentelekomcloud/services/vpn/data_source_opentelekomcloud_enterprise_vpn_gateway_v5.go
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,213 @@ | ||
package vpn | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/hashicorp/go-multierror" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/evpn/v5/gateway" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/fmterr" | ||
) | ||
|
||
func DataSourceEnterpriseVpnGateway() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceEvpnGatewayRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"availability_zones": { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Computed: true, | ||
}, | ||
"flavor": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"attachment_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"network_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"vpc_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"local_subnets": { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Computed: true, | ||
}, | ||
"connect_subnet": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"er_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"ha_mode": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"eip1": { | ||
Type: schema.TypeList, | ||
Elem: DSGatewayEipSchema(), | ||
Computed: true, | ||
}, | ||
"eip2": { | ||
Type: schema.TypeList, | ||
Elem: DSGatewayEipSchema(), | ||
Computed: true, | ||
}, | ||
"access_vpc_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"access_subnet_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"asn": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"access_private_ip_1": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"access_private_ip_2": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"created_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"updated_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"used_connection_group": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"used_connection_number": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"region": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func DSGatewayEipSchema() *schema.Resource { | ||
sc := schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"bandwidth_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"bandwidth_size": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"charge_mode": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"bandwidth_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"ip_address": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"ip_version": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
return &sc | ||
} | ||
|
||
func dataSourceEvpnGatewayRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
config := meta.(*cfg.Config) | ||
client, err := common.ClientFromCtx(ctx, keyClientV5, func() (*golangsdk.ServiceClient, error) { | ||
return config.EvpnV5Client(config.GetRegion(d)) | ||
}) | ||
if err != nil { | ||
return fmterr.Errorf(errCreationV5Client, err) | ||
} | ||
gatewayId := d.Get("id").(string) | ||
gw, err := gateway.Get(client, gatewayId) | ||
if err != nil { | ||
return diag.Errorf("error retrieving OpenTelekomCloud EVPN gateway (%s): %s", gatewayId, err) | ||
} | ||
d.SetId(gw.ID) | ||
|
||
log.Printf("[DEBUG] Retrieved Enterprise VPN Gateway %s: %#v", d.Id(), gw) | ||
|
||
mErr := multierror.Append( | ||
nil, | ||
d.Set("id", gw.ID), | ||
d.Set("region", config.GetRegion(d)), | ||
d.Set("attachment_type", gw.AttachmentType), | ||
d.Set("availability_zones", gw.AvailabilityZoneIds), | ||
d.Set("asn", gw.BgpAsn), | ||
d.Set("connect_subnet", gw.ConnectSubnet), | ||
d.Set("created_at", gw.CreatedAt), | ||
d.Set("flavor", gw.Flavor), | ||
d.Set("local_subnets", gw.LocalSubnets), | ||
d.Set("ha_mode", gw.HaMode), | ||
d.Set("eip1", flattenEvpGatewayResponseEip(gw.Eip1)), | ||
d.Set("name", gw.Name), | ||
d.Set("eip2", flattenEvpGatewayResponseEip(gw.Eip2)), | ||
d.Set("status", gw.Status), | ||
d.Set("updated_at", gw.UpdatedAt), | ||
d.Set("used_connection_group", gw.UsedConnectionGroup), | ||
d.Set("used_connection_number", gw.UsedConnectionNumber), | ||
d.Set("vpc_id", gw.VpcId), | ||
d.Set("access_vpc_id", gw.AccessVpcId), | ||
d.Set("access_subnet_id", gw.AccessSubnetId), | ||
d.Set("er_id", gw.ErId), | ||
d.Set("network_type", gw.NetworkType), | ||
d.Set("access_private_ip_1", gw.AccessPrivateIp1), | ||
d.Set("access_private_ip_2", gw.AccessPrivateIp2), | ||
) | ||
|
||
return diag.FromErr(mErr.ErrorOrNil()) | ||
} |
4 changes: 4 additions & 0 deletions
4
releasenotes/notes/vpn-add-datasource-enterprise-gateway-v5-19952586b1b692cf.yaml
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,4 @@ | ||
--- | ||
features: | ||
- | | ||
**[VPN]** New Data Source: ``opentelekomcloud_enterprise_vpn_gateway_v5`` (`#2810 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/2810>`_) |