diff --git a/docs/data-sources/vpn_gateway_v5.md b/docs/data-sources/vpn_gateway_v5.md new file mode 100644 index 000000000..902bf2877 --- /dev/null +++ b/docs/data-sources/vpn_gateway_v5.md @@ -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. + + +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. diff --git a/opentelekomcloud/acceptance/vpn/data_source_opentelekomcloud_enterprise_vpn_gateway_v5_test.go b/opentelekomcloud/acceptance/vpn/data_source_opentelekomcloud_enterprise_vpn_gateway_v5_test.go new file mode 100644 index 000000000..2f95b7d9a --- /dev/null +++ b/opentelekomcloud/acceptance/vpn/data_source_opentelekomcloud_enterprise_vpn_gateway_v5_test.go @@ -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" +} +` diff --git a/opentelekomcloud/provider.go b/opentelekomcloud/provider.go index 78a367140..9130ea32e 100644 --- a/opentelekomcloud/provider.go +++ b/opentelekomcloud/provider.go @@ -371,6 +371,7 @@ func Provider() *schema.Provider { "opentelekomcloud_vpc_subnet_v1": vpc.DataSourceVpcSubnetV1(), "opentelekomcloud_vpc_subnet_ids_v1": vpc.DataSourceVpcSubnetIdsV1(), "opentelekomcloud_vpnaas_service_v2": vpn.DataSourceVpnServiceV2(), + "opentelekomcloud_enterprise_vpn_gateway_v5": vpn.DataSourceEnterpriseVpnGateway(), "opentelekomcloud_waf_dedicated_reference_tables_v1": waf.DataSourceWafDedicatedRefTablesV1(), }, diff --git a/opentelekomcloud/services/vpn/data_source_opentelekomcloud_enterprise_vpn_gateway_v5.go b/opentelekomcloud/services/vpn/data_source_opentelekomcloud_enterprise_vpn_gateway_v5.go new file mode 100644 index 000000000..a8a7e394b --- /dev/null +++ b/opentelekomcloud/services/vpn/data_source_opentelekomcloud_enterprise_vpn_gateway_v5.go @@ -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()) +} diff --git a/releasenotes/notes/vpn-add-datasource-enterprise-gateway-v5-19952586b1b692cf.yaml b/releasenotes/notes/vpn-add-datasource-enterprise-gateway-v5-19952586b1b692cf.yaml new file mode 100644 index 000000000..4a4fdbad9 --- /dev/null +++ b/releasenotes/notes/vpn-add-datasource-enterprise-gateway-v5-19952586b1b692cf.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + **[VPN]** New Data Source: ``opentelekomcloud_enterprise_vpn_gateway_v5`` (`#2810 `_)