Skip to content

Commit

Permalink
[Feat.] DC v3 Virtual Interface (#2697)
Browse files Browse the repository at this point in the history
[Feat.] DC v3 Virtual Interface

Summary of the Pull Request
New resource DC virtual interface v3
PR Checklist

 Refers to: #2650
 Tests added/passed.
 Documentation updated.
 Schema updated.
 Release notes added.

Acceptance Steps Performed
=== RUN   TestAccVirtualInterface_basic
=== PAUSE TestAccVirtualInterface_basic
=== CONT  TestAccVirtualInterface_basic
--- PASS: TestAccVirtualInterface_basic (57.53s)
PASS

Process finished with exit code 0

Reviewed-by: Artem Lifshits
Reviewed-by: Anton Sidelnikov
  • Loading branch information
anton-sidelnikov authored Oct 28, 2024
1 parent 87250f1 commit 36980f7
Show file tree
Hide file tree
Showing 5 changed files with 874 additions and 0 deletions.
200 changes: 200 additions & 0 deletions docs/resources/dc_virtual_interface_v3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
---
subcategory: "Direct Connect (DCaaS)"
layout: "opentelekomcloud"
page_title: "OpenTelekomCloud: opentelekomcloud_dc_virtual_interface_v3"
sidebar_current: "docs-opentelekomcloud-resource-dc-virtual-interface-v3"
description: |-
Manages a Direct Connect Virtual Interface v3 resource within OpenTelekomCloud.
---


# opentelekomcloud_dc_virtual_interface_v3

Manages a virtual interface v3 resource within OpenTelekomCloud.

-> **NOTE:** Direct Connect v3 API that are used in this resource officially supported only on SwissCloud now.

## Example Usage

```hcl
variable "direct_connect_id" {}
variable "gateway_id" {}
variable "interface_name" {}
resource "opentelekomcloud_dc_virtual_interface_v3" "vi" {
direct_connect_id = var.direct_connect_id
vgw_id = var.gateway_id
name = var.interface_name
type = "private"
route_mode = "static"
vlan = 522
bandwidth = 5
remote_ep_group = [
"1.1.1.0/30",
]
address_family = "ipv4"
local_gateway_v4_ip = "1.1.1.1/30"
remote_gateway_v4_ip = "1.1.1.2/30"
}
```

## Argument Reference

The following arguments are supported:

* `direct_connect_id` - (Required, String, ForceNew) Specifies the ID of the direct connection associated with the
virtual interface.
Changing this will create a new resource.

* `vgw_id` - (Required, String, ForceNew) Specifies the ID of the virtual gateway to which the virtual interface is
connected.
Changing this will create a new resource.

* `name` - (Required, String) Specifies the name of the virtual interface.

* `type` - (Required, String, ForceNew) Specifies the type of the virtual interface.
The valid value is `private`.
Changing this will create a new resource.

* `route_mode` - (Required, String, ForceNew) Specifies the route mode of the virtual interface.
The valid values are `static` and `bgp`.
Changing this will create a new resource.

* `vlan` - (Required, Int, ForceNew) Specifies the customer VLAN to be connected.
The valid value is range from `0` to `3,999`.
Changing this will create a new resource.

* `bandwidth` - (Required, Int) Specifies the bandwidth of the virtual interface. The unit is Mbit/s.
The size range depends on the direct connection.

* `remote_ep_group` - (Required, List) Specifies the CIDR list of remote subnets.
A CIDR that contains CIDRs of local subnet (corresponding to the parameter `local_gateway_v4_ip` or
`local_gateway_v6_ip`) and remote subnet (corresponding to the parameter `remote_gateway_v4_ip` or
`remote_gateway_v6_ip`) must exist in the list.

* `service_ep_group` - (Optional, List) Specifies the subnets that access Internet services through a connection.

* `description` - (Optional, String) Specifies the description of the virtual interface.
The description contain a maximum of `128` characters and the angle brackets (`<` and `>`) are not allowed.
Chinese characters must be in `UTF-8` or `Unicode` format.

* `local_gateway_v4_ip` - (Optional, String, ForceNew) Specifies the IPv4 address of the virtual interface in cloud
side. This parameter is mandatory if `address_family` is set to `ipv4`.
Changing this will create a new resource.

* `remote_gateway_v4_ip` - (Optional, String, ForceNew) Specifies the IPv4 address of the virtual interface in client
side. This parameter is mandatory if `address_family` is set to `ipv4`.
Changing this will create a new resource.

* `address_family` - (Optional, String, ForceNew) Specifies the service type of the virtual interface.
The valid values are `ipv4` and `ipv6`. Defaults to `ipv4`.
Changing this will create a new resource.

* `local_gateway_v6_ip` - (Optional, String, ForceNew) Specifies the IPv6 address of the virtual interface in cloud
side. This parameter is mandatory if `address_family` is set to `ipv6`.
Changing this will create a new resource.

* `remote_gateway_v6_ip` - (Optional, String, ForceNew) Specifies the IPv6 address of the virtual interface in client
side. This parameter is mandatory if `address_family` is set to `ipv6`.
Changing this will create a new resource.

-> The CIDRs of `local_gateway_v4_ip` and `remote_gateway_v4_ip` (or `local_gateway_v6_ip` and `remote_gateway_v6_ip`)
must be in the same subnet.

* `asn` - (Optional, Int, ForceNew) Specifies the local BGP ASN of the virtual interface.
The valid value is range from `1` to `4,294,967,295`, except `64,512`.
Changing this will create a new resource.

* `bgp_md5` - (Optional, String, ForceNew) Specifies the (MD5) password for the local BGP.
Changing this will create a new resource.

* `enable_bfd` - (Optional, Bool) Specifies whether to enable the Bidirectional Forwarding Detection (BFD) function.
Defaults to `false`. (This is a reserved parameter and is not supported currently.)

* `enable_nqa` - (Optional, Bool) Specifies whether to enable the Network Quality Analysis (NQA) function.
Defaults to `false`. (This is a reserved parameter and is not supported currently.)

-> The values of parameter `enable_bfd` and `enable_nqa` cannot be `true` at the same time.

* `lag_id` - (Optional, String, ForceNew) Specifies the ID of the link aggregation group (LAG) associated with the
virtual interface.
Changing this will create a new resource.

* `resource_tenant_id` - (Optional, String, ForceNew) Specifies the project ID of another tenant in the same region
which is used to create virtual interface across tenant. After the across tenant virtual interface is successfully
created, the target tenant needs to accept the virtual interface request for the virtual interface to take effect.
Changing this will create a new resource.

-> 1. When `resource_tenant_id` is specified, `vgw_id` must be the target tenant virtual gateway id.
<br/>2. When `resource_tenant_id` is specified, the tags can only be configured after the target tenant accepts the
virtual interface request and the virtual interface takes effect.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The ID of the virtual interface.

* `device_id` - The attributed device ID.

* `status` - The current status of the virtual interface.

* `created_at` - The creation time of the virtual interface

* `region` - The region where the virtual interface is located.

* `vif_peers` - The peer information of the virtual interface.
The [vif_peers](#DCVirtualInterface_vif_peers) structure is documented below.

<a name="DCVirtualInterface_vif_peers"></a>
The `vif_peers` block supports:

* `id` - The VIF peer resource ID.

* `name` - The name of the virtual interface peer.

* `description` - The description of the virtual interface peer.

* `address_family` - The address family type of the virtual interface, which can be `IPv4` or `IPv6`.

* `local_gateway_ip` - The address of the virtual interface peer used on the cloud.

* `remote_gateway_ip` - The address of the virtual interface peer used in the on-premises data center.

* `route_mode` - The routing mode, which can be `static` or `bgp`.

* `bgp_asn` - The ASN of the BGP peer.

* `bgp_md5` - The MD5 password of the BGP peer.

* `device_id` - The ID of the device that the virtual interface peer belongs to.

* `enable_bfd` - Whether to enable BFD.

* `enable_nqa` - Whether to enable NQA.

* `bgp_route_limit` - The BGP route configuration.

* `bgp_status` - The BGP protocol status of the virtual interface peer. If the virtual interface peer uses `static`
routing, the status is null.

* `status` - The status of the virtual interface peer.

* `vif_id` - The ID of the virtual interface corresponding to the virtual interface peer.

* `receive_route_num` - The number of received BGP routes if `bgp` routing is used. If `static` routing is used,
this parameter is meaningless and the value is `-1`.

* `remote_ep_group` - The remote subnet list, which records the CIDR blocks used in the on-premises data center.

* `service_ep_group` - The list of public network addresses that can be accessed by the on-premises data center.

## Import

Virtual interfaces can be imported using their `id`, e.g.

```shell
$ terraform import opentelekomcloud_dc_virtual_interface_v3.vi e41748a0-aed9-463e-9817-5c6162265d10
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
package dcaas

import (
"fmt"
"os"
"testing"

"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"
virtual_interface "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcaas/v3/virtual-interface"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/env"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg"
)

func getVirtualInterfaceFunc(conf *cfg.Config, state *terraform.ResourceState) (interface{}, error) {
c, err := conf.DCaaSV3Client(env.OS_REGION_NAME)
if err != nil {
return nil, fmt.Errorf("error creating OpenTelekomCloud DCaaS v3 client: %s", err)
}
return virtual_interface.Get(c, state.Primary.ID)
}

func TestAccVirtualInterface_basic(t *testing.T) {
dcId := os.Getenv("OS_DIRECT_CONNECT_ID")
if dcId == "" {
t.Skip("OS_DIRECT_CONNECT_ID should be set for acceptance tests")
}
var (
vi virtual_interface.VirtualInterface

rName = "opentelekomcloud_dc_virtual_interface_v3.vi"
name = fmt.Sprintf("dc_acc_vi%s", acctest.RandString(5))
updateName = fmt.Sprintf("dc_acc_vi_up%s", acctest.RandString(5))
vlan = acctest.RandIntRange(1, 3999)
)

rc := common.InitResourceCheck(
rName,
&vi,
getVirtualInterfaceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
common.TestAccPreCheck(t)
},
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccVirtualInterface_basic(name, vlan),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "direct_connect_id", dcId),
resource.TestCheckResourceAttrPair(rName, "vgw_id", "opentelekomcloud_dc_virtual_gateway_v3.gw", "id"),
resource.TestCheckResourceAttr(rName, "name", name),
resource.TestCheckResourceAttr(rName, "description", "Created by acc test"),
resource.TestCheckResourceAttr(rName, "type", "private"),
resource.TestCheckResourceAttr(rName, "route_mode", "static"),
resource.TestCheckResourceAttr(rName, "vlan", fmt.Sprintf("%v", vlan)),
resource.TestCheckResourceAttr(rName, "bandwidth", "5"),
resource.TestCheckResourceAttr(rName, "enable_bfd", "false"),
resource.TestCheckResourceAttr(rName, "enable_nqa", "false"),
resource.TestCheckResourceAttr(rName, "remote_ep_group.0", "1.1.1.0/30"),
resource.TestCheckResourceAttr(rName, "address_family", "ipv4"),
resource.TestCheckResourceAttr(rName, "local_gateway_v4_ip", "1.1.1.1/30"),
resource.TestCheckResourceAttr(rName, "remote_gateway_v4_ip", "1.1.1.2/30"),
resource.TestCheckResourceAttrSet(rName, "device_id"),
resource.TestCheckResourceAttrSet(rName, "created_at"),
resource.TestCheckResourceAttrSet(rName, "status"),
resource.TestCheckResourceAttr(rName, "vif_peers.#", "1"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.address_family"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.bgp_asn"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.bgp_route_limit"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.device_id"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.enable_bfd"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.enable_nqa"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.id"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.local_gateway_ip"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.name"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.receive_route_num"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.remote_ep_group.#"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.remote_gateway_ip"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.route_mode"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.status"),
resource.TestCheckResourceAttrSet(rName, "vif_peers.0.vif_id"),
),
},
{
Config: testAccVirtualInterface_update(updateName, vlan),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "direct_connect_id", dcId),
resource.TestCheckResourceAttrPair(rName, "vgw_id", "opentelekomcloud_dc_virtual_gateway_v3.gw", "id"),
resource.TestCheckResourceAttr(rName, "name", updateName),
resource.TestCheckResourceAttr(rName, "description", ""),
resource.TestCheckResourceAttr(rName, "type", "private"),
resource.TestCheckResourceAttr(rName, "route_mode", "static"),
resource.TestCheckResourceAttr(rName, "vlan", fmt.Sprintf("%v", vlan)),
resource.TestCheckResourceAttr(rName, "bandwidth", "10"),
resource.TestCheckResourceAttr(rName, "enable_bfd", "false"),
resource.TestCheckResourceAttr(rName, "enable_nqa", "false"),
resource.TestCheckResourceAttr(rName, "remote_ep_group.0", "1.1.1.0/30"),
resource.TestCheckResourceAttr(rName, "remote_ep_group.1", "1.1.2.0/30"),
resource.TestCheckResourceAttr(rName, "address_family", "ipv4"),
resource.TestCheckResourceAttr(rName, "local_gateway_v4_ip", "1.1.1.1/30"),
resource.TestCheckResourceAttr(rName, "remote_gateway_v4_ip", "1.1.1.2/30"),
resource.TestCheckResourceAttrSet(rName, "device_id"),
resource.TestCheckResourceAttrSet(rName, "created_at"),
resource.TestCheckResourceAttrSet(rName, "status"),
),
},
{
ResourceName: rName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccVirtualInterface_base(name string) string {
return fmt.Sprintf(`
%s
resource "opentelekomcloud_dc_virtual_gateway_v3" "gw" {
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
name = "%s"
description = "Created by acc test"
local_ep_group = [
"192.168.0.0/16",
]
}
`, common.DataSourceSubnet, name)
}

func testAccVirtualInterface_basic(name string, vlan int) string {
return fmt.Sprintf(`
%[1]s
resource "opentelekomcloud_dc_virtual_interface_v3" "vi" {
direct_connect_id = "%[2]s"
vgw_id = opentelekomcloud_dc_virtual_gateway_v3.gw.id
name = "%[3]s"
description = "Created by acc test"
type = "private"
route_mode = "static"
vlan = %[4]d
bandwidth = 5
remote_ep_group = [
"1.1.1.0/30",
]
address_family = "ipv4"
local_gateway_v4_ip = "1.1.1.1/30"
remote_gateway_v4_ip = "1.1.1.2/30"
}
`, testAccVirtualInterface_base(name), os.Getenv("OS_DIRECT_CONNECT_ID"), name, vlan)
}

func testAccVirtualInterface_update(name string, vlan int) string {
return fmt.Sprintf(`
%[1]s
resource "opentelekomcloud_dc_virtual_interface_v3" "vi" {
direct_connect_id = "%[2]s"
vgw_id = opentelekomcloud_dc_virtual_gateway_v3.gw.id
name = "%[3]s"
type = "private"
route_mode = "static"
vlan = %[4]d
bandwidth = 10
remote_ep_group = [
"1.1.1.0/30",
"1.1.2.0/30",
]
address_family = "ipv4"
local_gateway_v4_ip = "1.1.1.1/30"
remote_gateway_v4_ip = "1.1.1.2/30"
}
`, testAccVirtualInterface_base(name), os.Getenv("OS_DIRECT_CONNECT_ID"), name, vlan)
}
1 change: 1 addition & 0 deletions opentelekomcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ func Provider() *schema.Provider {
"opentelekomcloud_dc_virtual_gateway_v2": dcaas.ResourceVirtualGatewayV2(),
"opentelekomcloud_dc_hosted_connect_v3": dcaas.ResourceHostedConnectV3(),
"opentelekomcloud_dc_virtual_gateway_v3": dcaas.ResourceVirtualGatewayV3(),
"opentelekomcloud_dc_virtual_interface_v3": dcaas.ResourceVirtualInterfaceV3(),
"opentelekomcloud_dcs_instance_v1": dcs.ResourceDcsInstanceV1(),
"opentelekomcloud_dcs_instance_v2": dcs.ResourceDcsInstanceV2(),
"opentelekomcloud_dds_backup_v3": dds.ResourceDdsBackupV3(),
Expand Down
Loading

0 comments on commit 36980f7

Please sign in to comment.