Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions tencentcloud/data_source_tc_vpn_connections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ func TestAccTencentCloudVpnConnectionsDataSource(t *testing.T) {
const testAccTencentCloudVpnConnectionsDataSourceConfig_basic = `
resource "tencentcloud_vpn_customer_gateway" "cgw" {
name = "terraform_test"
public_ip_address = "3.3.3.3"

public_ip_address = "3.2.3.3"
}

# Create VPC and Subnet
Expand Down
2 changes: 1 addition & 1 deletion tencentcloud/data_source_tc_vpn_gateway_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ resource "tencentcloud_vpn_gateway_route" "route1" {
vpn_gateway_id = data.tencentcloud_vpn_gateways.foo.gateway_list.0.id
destination_cidr_block = "10.0.0.0/16"
instance_type = "VPNCONN"
instance_id = data.tencentcloud_vpn_connection.conns.connection_list.0.id
instance_id = data.tencentcloud_vpn_connections.conns.connection_list.0.id
priority = "100"
status = "ENABLE"
}
Expand Down
5 changes: 2 additions & 3 deletions tencentcloud/resource_tc_vpn_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func testAccCheckVpnConnectionExists(n string) resource.TestCheckFunc {
const testAccVpnConnectionConfig = `
resource "tencentcloud_vpn_customer_gateway" "cgw" {
name = "terraform_test"
public_ip_address = "3.3.3.3"
public_ip_address = "1.3.3.3"

}

Expand Down Expand Up @@ -219,8 +219,7 @@ resource "tencentcloud_vpn_connection" "connection" {
const testAccVpnConnectionConfigUpdate = `
resource "tencentcloud_vpn_customer_gateway" "cgw" {
name = "terraform_test"
public_ip_address = "3.3.3.3"

public_ip_address = "1.3.3.3"
}

# Create VPC and Subnet
Expand Down
42 changes: 42 additions & 0 deletions tencentcloud/resource_tc_vpn_customer_gateway_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tencentcloud

import (
"context"
"fmt"
"log"
"testing"
Expand All @@ -11,6 +12,47 @@ import (
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
)

func init() {
resource.AddTestSweepers("tencentcloud_vpn_customer_gateway", &resource.Sweeper{
Name: "tencentcloud_vpn_customer_gateway",
F: testSweepVpnCustomerGateway,
})
}

func testSweepVpnCustomerGateway(region string) error {
logId := getLogId(contextNil)
ctx := context.WithValue(context.TODO(), logIdKey, logId)

sharedClient, err := sharedClientForRegion(region)
if err != nil {
return fmt.Errorf("getting tencentcloud client error: %s", err.Error())
}
client := sharedClient.(*TencentCloudClient)

vpcService := VpcService{
client: client.apiV3Conn,
}

instances, err := vpcService.DescribeCustomerGatewayByFilter(ctx, nil)
if err != nil {
return fmt.Errorf("get instance list error: %s", err.Error())
}

for _, v := range instances {
customerGwId := *v.CustomerGatewayId

//if !strings.HasPrefix(instanceName, defaultInsName) {
// continue
//}

if err = vpcService.DeleteCustomerGateway(ctx, customerGwId); err != nil {
log.Printf("[ERROR] sweep instance %s error: %s", customerGwId, err.Error())
}
}

return nil
}

func TestAccTencentCloudVpnCustomerGateway_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
Expand Down
9 changes: 4 additions & 5 deletions tencentcloud/resource_tc_vpn_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ func testSweepVpnGateway(region string) error {
}

for _, v := range instances {
vpnGwId := *v.VpnGatewayId
//vpnGwName := *v.VpnGatewayName

//if !strings.HasPrefix(instanceName, defaultInsName) {
//if !strings.HasPrefix(vpnGwName, defaultInsName) {
// continue
//}

instanceId := *v.VpnGatewayId

vpnGwId := *v.VpnGatewayId
if err = vpcService.DeleteVpnGateway(ctx, vpnGwId); err != nil {
log.Printf("[ERROR] sweep instance %s error: %s", instanceId, err.Error())
log.Printf("[ERROR] sweep instance %s error: %s", vpnGwId, err.Error())
}
}

Expand Down
65 changes: 65 additions & 0 deletions tencentcloud/service_tencentcloud_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3602,6 +3602,71 @@ func (me *VpcService) DeleteVpnGateway(ctx context.Context, vpnGatewayId string)
return
}

func (me *VpcService) DescribeCustomerGatewayByFilter(ctx context.Context, filters map[string]string) (instances []*vpc.CustomerGateway, errRet error) {
var (
logId = getLogId(ctx)
request = vpc.NewDescribeCustomerGatewaysRequest()
)
request.Filters = make([]*vpc.Filter, 0, len(filters))
for k, v := range filters {
filter := vpc.Filter{
Name: helper.String(k),
Values: []*string{helper.String(v)},
}
request.Filters = append(request.Filters, &filter)
}

var offset uint64 = 0
var pageSize uint64 = 100
instances = make([]*vpc.CustomerGateway, 0)

for {
request.Offset = &offset
request.Limit = &pageSize
ratelimit.Check(request.GetAction())
response, err := me.client.UseVpcClient().DescribeCustomerGateways(request)
if err != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
logId, request.GetAction(), request.ToJsonString(), err.Error())
errRet = err
return
}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

if response == nil || len(response.Response.CustomerGatewaySet) < 1 {
break
}
instances = append(instances, response.Response.CustomerGatewaySet...)
if len(response.Response.CustomerGatewaySet) < int(pageSize) {
break
}
offset += pageSize
}
return
}

func (me *VpcService) DeleteCustomerGateway(ctx context.Context, customerGatewayId string) (errRet error) {
logId := getLogId(ctx)
request := vpc.NewDeleteCustomerGatewayRequest()
defer func() {
if errRet != nil {
log.Printf("[CRITAL]%s api[%s] fail,reason[%s]", logId, request.GetAction(), errRet.Error())
}
}()
request.CustomerGatewayId = &customerGatewayId

errRet = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
ratelimit.Check(request.GetAction())
_, errRet = me.client.UseVpcClient().DeleteCustomerGateway(request)
if errRet != nil {
return retryError(errRet, InternalError)
}
return nil
})
return
}

func (me *VpcService) CreateAddressTemplate(ctx context.Context, name string, addresses []interface{}) (templateId string, errRet error) {
logId := getLogId(ctx)
request := vpc.NewCreateAddressTemplateRequest()
Expand Down