Skip to content

Commit

Permalink
[DCAAS] refactoring `resource/opentelekomcloud_dc_virtual_interface_v…
Browse files Browse the repository at this point in the history
…2` (#2408)

[DCAAS] refactoring `resource/opentelekomcloud_dc_virtual_interface_v2`

Summary of the Pull Request
PR Checklist

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

Acceptance Steps Performed
=== RUN   TestDirectConnectVirtualInterfaceV2Resource_basic
--- PASS: TestDirectConnectVirtualInterfaceV2Resource_basic (86.16s)
PASS

Process finished with the exit code 0

Reviewed-by: Artem Lifshits
Reviewed-by: Aloento
  • Loading branch information
anton-sidelnikov authored Jan 11, 2024
1 parent 0610319 commit 24a5492
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 76 deletions.
2 changes: 1 addition & 1 deletion docs/resources/dс_virtual_gateway_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The following arguments are supported:
* `description` (String, Optional) - Provides supplementary information about the virtual gateway.
* `asn` (Int, Optional, ForceNew) - Specifies the BGP ASN of the virtual gateway.
* `device_id` (String, Optional) - Specifies the ID of the physical device used by the virtual gateway.
* `project_id` (String, Optional) - Specifies the project ID.
* `redundant_device_id` (String, Optional) - Specifies the ID of the redundant physical device used by the virtual gateway.

## Attributes Reference
Expand All @@ -44,7 +45,6 @@ The following attributes are exported:

* `id` - ID of the virtual gateway.
* `status` - Virtual gateway status.
* `project_id` - Project id.
* `local_ep_group_id` - ID of the local endpoint group that records CIDR blocks of the VPC subnets.

## Import
Expand Down
46 changes: 27 additions & 19 deletions docs/resources/dс_virtual_interface_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,34 @@ data "opentelekomcloud_identity_project_v3" "project" {
name = "eu-de_project_1"
}
resource "opentelekomcloud_dc_endpoint_group_v2" "dc_endpoint_group" {
name = "tf_acc_eg_1"
type = "cidr"
endpoints = ["10.2.0.0/24", "10.3.0.0/24"]
description = "first"
project_id = data.opentelekomcloud_identity_project_v3.project.id
}
resource "opentelekomcloud_dc_virtual_gateway_v2" "vgw_1" {
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
name = "my_virtual_gateway"
description = "acc test"
local_ep_group_id = opentelekomcloud_dc_endpoint_group_v2.dc_endpoint_group.id
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
name = "my_virtual_gateway"
description = "acc test"
local_ep_group {
name = "tf_acc_eg_1"
endpoints = ["10.2.0.0/24", "10.3.0.0/24"]
description = "first"
}
}
resource "opentelekomcloud_dc_virtual_interface_v2" "int_1" {
resource "opentelekomcloud_dc_virtual_interface_v2" "vi_1" {
direct_connect_id = var.direct_connect_id
virtual_gateway_id = opentelekomcloud_dc_virtual_gateway_v2.vgw_1.id
service_type = "vpc"
name = "vi_1"
name = "my_virtual_interface"
description = "description"
type = "private"
route_mode = "static"
vlan = 100
bandwidth = 5
remote_ep_group_id = opentelekomcloud_dc_endpoint_group_v2.dc_endpoint_group.id
bandwidth = 10
remote_ep_group {
name = "tf_acc_reg_1"
endpoints = ["100.20.0.0/24", "100.30.0.0/24"]
description = "first"
project_id = data.opentelekomcloud_identity_project_v3.project.id
}
local_gateway_v4_ip = "180.1.1.1/24"
remote_gateway_v4_ip = "180.1.1.2/24"
}
Expand All @@ -58,7 +59,13 @@ The following arguments are supported:
* `route_mode` (String, Required, ForceNew) - Specifies the routing mode. The value can be `static` or `bgp`.
* `vlan` (Int, Required, ForceNew) - Specifies the VLAN used by the local gateway to communicate with the remote gateway.
* `bandwidth` (Int, Required) - Specifies the virtual interface bandwidth.
* `remote_ep_group_id` (String, Required) - Specifies the ID of the remote endpoint group that records the CIDR blocks used by the on-premises network.
* `remote_ep_group` (String, Required, List) - Specifies the ID of the remote endpoint group that records the CIDR blocks used by the on-premises network.
The `remote_ep_group` block supports:
* `name` (String, Optional) - Specifies the name of the Direct Connect endpoint group.
* `description` (String, Optional) - Provides supplementary information about the Direct Connect endpoint group.
* `endpoints` (List, Required) - Specifies the list of the endpoints in a Direct Connect endpoint group.
* `type` (String, Required, ForceNew) - Specifies the type of the Direct Connect endpoints. The value can only be `cidr`. Default value: `cidr`.
* `project_id` (String, Optional, ForceNew) - Specifies the project ID.
* `description` (String, Optional) - Provides supplementary information about the virtual interface.
* `service_type` (String, Required, ForceNew) - Specifies what is to be accessed over the connection. The value can only be `vpc`.
* `local_gateway_v4_ip` (String, Optional, ForceNew) - Specifies the IPv4 address of the local gateway.
Expand All @@ -75,6 +82,7 @@ The following attributes are exported:
* `enable_bfd` - Bidirectional Forwarding Detection (BFD) function status.
* `enable_nqa` - Network Quality Analysis (NQA) function status.
* `lag_id` - The ID of the link aggregation group (LAG) associated with the virtual interface.
* `remote_ep_group_id`- The ID of the remote endpoint group that records the CIDR blocks used by the on-premises network.
* `status` - The current status of the virtual interface.
* `created_at` - The creation time of the virtual interface.

Expand All @@ -83,5 +91,5 @@ The following attributes are exported:
Direct Connect Virtual Interface can be imported using `id`, e.g.

```sh
$ terraform import opentelekomcloud_dc_virtual_interface_v2.vgw <id>
$ terraform import opentelekomcloud_dc_virtual_interface_v2.vi <id>
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/jinzhu/copier v0.3.5
github.com/keybase/go-crypto v0.0.0-20200123153347-de78d2cb44f4
github.com/mitchellh/go-homedir v1.1.0
github.com/opentelekomcloud/gophertelekomcloud v0.8.1-0.20240108103338-13bba7d2bc2a
github.com/opentelekomcloud/gophertelekomcloud v0.8.1-0.20240110123148-5cecd78ce1d5
github.com/unknwon/com v1.0.1
golang.org/x/crypto v0.17.0
golang.org/x/sync v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/opentelekomcloud/gophertelekomcloud v0.8.1-0.20240108103338-13bba7d2bc2a h1:ZBOOSd7b6uQcWqzEmruiNqw1JIsTJ7NwyAQnrOHFpe8=
github.com/opentelekomcloud/gophertelekomcloud v0.8.1-0.20240108103338-13bba7d2bc2a/go.mod h1:52hmT1BkuU3niQC6fgHOHdNkYOTh9ry4HYbmuSOjDkw=
github.com/opentelekomcloud/gophertelekomcloud v0.8.1-0.20240110123148-5cecd78ce1d5 h1:yicSBCs8QpDnijnPZUNZ/24FB95I71fZA7DUzo48aZk=
github.com/opentelekomcloud/gophertelekomcloud v0.8.1-0.20240110123148-5cecd78ce1d5/go.mod h1:52hmT1BkuU3niQC6fgHOHdNkYOTh9ry4HYbmuSOjDkw=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ func TestDirectConnectVirtualInterfaceV2Resource_basic(t *testing.T) {
),
},
{
ResourceName: vi,
ImportState: true,
ImportStateVerify: true,
ResourceName: vi,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"service_type"},
},
},
})
Expand Down Expand Up @@ -119,22 +120,18 @@ func testAccVirtualInterfaceV2_basic(name, dcId string) string {
%s
resource "opentelekomcloud_dc_endpoint_group_v2" "dc_endpoint_group" {
name = "tf_acc_eg_1"
type = "cidr"
endpoints = ["10.2.0.0/24", "10.3.0.0/24"]
description = "first"
project_id = data.opentelekomcloud_identity_project_v3.project.id
}
resource "opentelekomcloud_dc_virtual_gateway_v2" "vgw_1" {
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
name = "tf_acc_vgw_1"
description = "acc test"
local_ep_group_id = opentelekomcloud_dc_endpoint_group_v2.dc_endpoint_group.id
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
name = "tf_acc_vgw_1"
description = "acc test"
local_ep_group {
name = "tf_acc_eg_1"
endpoints = ["10.2.0.0/24", "10.3.0.0/24"]
description = "first"
}
}
resource "opentelekomcloud_dc_virtual_interface_v2" "int_1" {
resource "opentelekomcloud_dc_virtual_interface_v2" "vi_1" {
direct_connect_id = "%s"
virtual_gateway_id = opentelekomcloud_dc_virtual_gateway_v2.vgw_1.id
service_type = "vpc"
Expand All @@ -145,7 +142,12 @@ resource "opentelekomcloud_dc_virtual_interface_v2" "int_1" {
vlan = 100
bandwidth = 5
remote_ep_group_id = opentelekomcloud_dc_endpoint_group_v2.dc_endpoint_group.id
remote_ep_group {
name = "tf_acc_reg_1"
endpoints = ["100.20.0.0/24"]
description = "first"
project_id = data.opentelekomcloud_identity_project_v3.project.id
}
local_gateway_v4_ip = "180.1.1.1/24"
remote_gateway_v4_ip = "180.1.1.2/24"
}
Expand All @@ -158,22 +160,18 @@ func testAccVirtualInterfaceV2_update(name, dcId string) string {
%s
resource "opentelekomcloud_dc_endpoint_group_v2" "dc_endpoint_group" {
name = "tf_acc_eg_1"
type = "cidr"
endpoints = ["10.2.0.0/24", "10.3.0.0/24"]
description = "first"
project_id = data.opentelekomcloud_identity_project_v3.project.id
}
resource "opentelekomcloud_dc_virtual_gateway_v2" "vgw_1" {
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
name = "tf_acc_vgw_1"
description = "acc test updated"
local_ep_group_id = opentelekomcloud_dc_endpoint_group_v2.dc_endpoint_group.id
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
name = "tf_acc_vgw_1"
description = "acc test updated"
local_ep_group {
name = "tf_acc_eg_1"
endpoints = ["10.2.0.0/24", "10.3.0.0/24"]
description = "first"
}
}
resource "opentelekomcloud_dc_virtual_interface_v2" "int_1" {
resource "opentelekomcloud_dc_virtual_interface_v2" "vi_1" {
direct_connect_id = "%s"
virtual_gateway_id = opentelekomcloud_dc_virtual_gateway_v2.vgw_1.id
service_type = "vpc"
Expand All @@ -184,7 +182,12 @@ resource "opentelekomcloud_dc_virtual_interface_v2" "int_1" {
vlan = 100
bandwidth = 10
remote_ep_group_id = opentelekomcloud_dc_endpoint_group_v2.dc_endpoint_group.id
remote_ep_group {
name = "tf_acc_reg_1"
endpoints = ["100.20.0.0/24", "100.30.0.0/24"]
description = "first"
project_id = data.opentelekomcloud_identity_project_v3.project.id
}
local_gateway_v4_ip = "180.1.1.1/24"
remote_gateway_v4_ip = "180.1.1.2/24"
}
Expand Down
8 changes: 8 additions & 0 deletions opentelekomcloud/services/dcaas/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ const (
)

const egDeprecated = "This resource is not longer supported. Please use opentelekomcloud_dc_virtual_gateway_v2 with local_ep_group block instead."

func GetEndpoints(e []interface{}) []string {
endpoints := make([]string, 0)
for _, val := range e {
endpoints = append(endpoints, val.(string))
}
return endpoints
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ func ResourceVirtualGatewayV2() *schema.Resource {
},
}
}
func resourceEgCreate(client *golangsdk.ServiceClient, d *schema.ResourceData) (*dceg.DCEndpointGroup, error) {

func resourceLocalEgCreate(client *golangsdk.ServiceClient, d *schema.ResourceData) (*dceg.DCEndpointGroup, error) {
var createOpts = dceg.CreateOpts{}
projectId := d.Get("project_id").(string)
if projectId == "" {
Expand All @@ -131,14 +132,6 @@ func resourceEgCreate(client *golangsdk.ServiceClient, d *schema.ResourceData) (
return eg, err
}

func GetEndpoints(e []interface{}) []string {
endpoints := make([]string, 0)
for _, val := range e {
endpoints = append(endpoints, val.(string))
}
return endpoints
}

func resourceVirtualGatewayV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*cfg.Config)
client, err := common.ClientFromCtx(ctx, keyClientV2, func() (*golangsdk.ServiceClient, error) {
Expand All @@ -148,7 +141,7 @@ func resourceVirtualGatewayV2Create(ctx context.Context, d *schema.ResourceData,
return fmterr.Errorf(errCreateClient, err)
}

eg, err := resourceEgCreate(client, d)
eg, err := resourceLocalEgCreate(client, d)
if err != nil {
return fmterr.Errorf("error creating DC endpoint group: %s", err)
}
Expand All @@ -162,6 +155,7 @@ func resourceVirtualGatewayV2Create(ctx context.Context, d *schema.ResourceData,
DeviceId: d.Get("device_id").(string),
RedundantDeviceId: d.Get("redundant_device_id").(string),
Type: "default",
ProjectId: d.Get("project_id").(string),
}
vg, err := virtual_gateway.Create(client, opts)
if err != nil {
Expand Down Expand Up @@ -230,9 +224,9 @@ func resourceVirtualGatewayV2Update(ctx context.Context, d *schema.ResourceData,
}

if d.HasChange("local_ep_group") {
newEg, err := resourceEgCreate(client, d)
newEg, err := resourceLocalEgCreate(client, d)
if err != nil {
return fmterr.Errorf("error creating new DC endpoint group: %s", err)
return fmterr.Errorf("error creating new local DC endpoint group: %s", err)
}

vg, err := virtual_gateway.Get(client, d.Id())
Expand All @@ -250,7 +244,7 @@ func resourceVirtualGatewayV2Update(ctx context.Context, d *schema.ResourceData,

err = dceg.Delete(client, vg.LocalEPGroupID)
if err != nil {
return fmterr.Errorf("error deleting old DC endpoint group: %s", err)
return fmterr.Errorf("error deleting old local DC endpoint group: %s", err)
}
}

Expand Down
Loading

0 comments on commit 24a5492

Please sign in to comment.