Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vpn operation #1636

Merged
merged 2 commits into from
Mar 31, 2023
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
7 changes: 7 additions & 0 deletions .changelog/1636.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-resource
tencentcloud_vpn_connection_reset
```

```release-note:new-resource
tencentcloud_vpn_customer_gateway_configuration_download
```
576 changes: 290 additions & 286 deletions tencentcloud/provider.go

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions tencentcloud/resource_tc_vpn_connection_reset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
Provides a resource to create a vpc vpn_connection_reset

Example Usage

```hcl
resource "tencentcloud_vpn_connection_reset" "vpn_connection_reset" {
vpn_gateway_id = "vpngw-gt8bianl"
vpn_connection_id = "vpnx-kme2tx8m"
}
```
*/
package tencentcloud

import (
"log"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func resourceTencentCloudVpnConnectionReset() *schema.Resource {
return &schema.Resource{
Create: resourceTencentCloudVpnConnectionResetCreate,
Read: resourceTencentCloudVpnConnectionResetRead,
Delete: resourceTencentCloudVpnConnectionResetDelete,
Schema: map[string]*schema.Schema{
"vpn_gateway_id": {
Required: true,
ForceNew: true,
Type: schema.TypeString,
Description: "VPN GATEWAY INSTANCE ID.",
},

"vpn_connection_id": {
Required: true,
ForceNew: true,
Type: schema.TypeString,
Description: "VPN CONNECTION INSTANCE ID.",
},
},
}
}

func resourceTencentCloudVpnConnectionResetCreate(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_vpn_connection_reset.read")()
defer inconsistentCheck(d, meta)()

logId := getLogId(contextNil)

var (
request = vpc.NewResetVpnConnectionRequest()
vpnGatewayId string
vpnConnectionId string
)
if v, ok := d.GetOk("vpn_gateway_id"); ok {
vpnGatewayId = v.(string)
request.VpnGatewayId = helper.String(v.(string))
}

if v, ok := d.GetOk("vpn_connection_id"); ok {
vpnConnectionId = v.(string)
request.VpnConnectionId = helper.String(v.(string))
}

err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().ResetVpnConnection(request)
if e != nil {
return retryError(e)
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}
return nil
})
if err != nil {
log.Printf("[CRITAL]%s operate vpc vpnConnectionReset failed, reason:%+v", logId, err)
return nil
}

d.SetId(vpnGatewayId + FILED_SP + vpnConnectionId)

return resourceTencentCloudVpnConnectionResetRead(d, meta)
}

func resourceTencentCloudVpnConnectionResetRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("resource.tencentcloud_vpn_connection_reset.read")()
defer inconsistentCheck(d, meta)()

return nil
}

func resourceTencentCloudVpnConnectionResetDelete(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("resource.tencentcloud_vpn_connection_reset.delete")()
defer inconsistentCheck(d, meta)()

return nil
}
32 changes: 32 additions & 0 deletions tencentcloud/resource_tc_vpn_connection_reset_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package tencentcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccTencentCloudVpnConnectionResetResource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccVpcVpnConnectionReset,
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_vpn_connection_reset.vpn_connection_reset", "id")),
},
},
})
}

const testAccVpcVpnConnectionReset = `

resource "tencentcloud_vpn_connection_reset" "vpn_connection_reset" {
vpn_gateway_id = "vpngw-gt8bianl"
vpn_connection_id = "vpnx-kme2tx8m"
}

`
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
Provides a resource to create a vpc vpn_customer_gateway_configuration_download

Example Usage

```hcl
resource "tencentcloud_vpn_customer_gateway_configuration_download" "vpn_customer_gateway_configuration_download" {
vpn_gateway_id = "vpngw-gt8bianl"
vpn_connection_id = "vpnx-kme2tx8m"
customer_gateway_vendor {
platform = "comware"
software_version = "V1.0"
vendor_name = "h3c"
}
interface_name = "test"
}
```
*/
package tencentcloud

import (
"log"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func resourceTencentCloudVpnCustomerGatewayConfigurationDownload() *schema.Resource {
return &schema.Resource{
Create: resourceTencentCloudVpnCustomerGatewayConfigurationDownloadCreate,
Read: resourceTencentCloudVpnCustomerGatewayConfigurationDownloadRead,
Delete: resourceTencentCloudVpnCustomerGatewayConfigurationDownloadDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"vpn_gateway_id": {
Required: true,
ForceNew: true,
Type: schema.TypeString,
Description: "VPN Gateway Instance ID.",
},

"vpn_connection_id": {
Required: true,
ForceNew: true,
Type: schema.TypeString,
Description: "VPN Connection Instance id.",
},

"customer_gateway_vendor": {
Required: true,
ForceNew: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "Customer Gateway Vendor Info.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"platform": {
Type: schema.TypeString,
Required: true,
Description: "Platform.",
},
"software_version": {
Type: schema.TypeString,
Required: true,
Description: "SoftwareVersion.",
},
"vendor_name": {
Type: schema.TypeString,
Required: true,
Description: "VendorName.",
},
},
},
},

"interface_name": {
Required: true,
ForceNew: true,
Type: schema.TypeString,
Description: "VPN connection access device physical interface name.",
},

"customer_gateway_configuration": {
Computed: true,
Type: schema.TypeString,
Description: "xml configuration.",
},
},
}
}

func resourceTencentCloudVpnCustomerGatewayConfigurationDownloadCreate(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_vpn_customer_gateway_configuration_download.read")()
defer inconsistentCheck(d, meta)()

logId := getLogId(contextNil)

var (
request = vpc.NewDownloadCustomerGatewayConfigurationRequest()
response = vpc.NewDownloadCustomerGatewayConfigurationResponse()
vpnGatewayId string
vpnConnectionId string
)
if v, ok := d.GetOk("vpn_gateway_id"); ok {
vpnGatewayId = v.(string)
request.VpnGatewayId = helper.String(v.(string))
}

if v, ok := d.GetOk("vpn_connection_id"); ok {
vpnConnectionId = v.(string)
request.VpnConnectionId = helper.String(v.(string))
}

if dMap, ok := helper.InterfacesHeadMap(d, "customer_gateway_vendor"); ok {
customerGatewayVendor := vpc.CustomerGatewayVendor{}
if v, ok := dMap["platform"]; ok {
customerGatewayVendor.Platform = helper.String(v.(string))
}
if v, ok := dMap["software_version"]; ok {
customerGatewayVendor.SoftwareVersion = helper.String(v.(string))
}
if v, ok := dMap["vendor_name"]; ok {
customerGatewayVendor.VendorName = helper.String(v.(string))
}
request.CustomerGatewayVendor = &customerGatewayVendor
}

if v, ok := d.GetOk("interface_name"); ok {
request.InterfaceName = helper.String(v.(string))
}

err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().DownloadCustomerGatewayConfiguration(request)
if e != nil {
return retryError(e)
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}
response = result
return nil
})
if err != nil {
log.Printf("[CRITAL]%s operate vpc vpnCustomerGatewayConfigurationDownload failed, reason:%+v", logId, err)
return nil
}

d.SetId(vpnGatewayId + FILED_SP + vpnConnectionId)

d.Set("customer_gateway_configuration", response.Response.CustomerGatewayConfiguration)

return resourceTencentCloudVpnCustomerGatewayConfigurationDownloadRead(d, meta)
}

func resourceTencentCloudVpnCustomerGatewayConfigurationDownloadRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("resource.tencentcloud_vpn_customer_gateway_configuration_download.read")()
defer inconsistentCheck(d, meta)()

return nil
}

func resourceTencentCloudVpnCustomerGatewayConfigurationDownloadDelete(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("resource.tencentcloud_vpn_customer_gateway_configuration_download.delete")()
defer inconsistentCheck(d, meta)()

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package tencentcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccTencentCloudVpnCustomerGatewayConfigurationDownloadResource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccVpcVpnCustomerGatewayConfigurationDownload,
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_vpn_customer_gateway_configuration_download.vpn_customer_gateway_configuration_download", "id")),
},
},
})
}

const testAccVpcVpnCustomerGatewayConfigurationDownload = `

resource "tencentcloud_vpn_customer_gateway_configuration_download" "vpn_customer_gateway_configuration_download" {
vpn_gateway_id = "vpngw-gt8bianl"
vpn_connection_id = "vpnx-kme2tx8m"
customer_gateway_vendor {
platform = "comware"
software_version = "V1.0"
vendor_name = "h3c"
}
interface_name = "test"
}

`
37 changes: 37 additions & 0 deletions website/docs/r/vpn_connection_reset.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
subcategory: "VPN Connections(VPN)"
layout: "tencentcloud"
page_title: "TencentCloud: tencentcloud_vpn_connection_reset"
sidebar_current: "docs-tencentcloud-resource-vpn_connection_reset"
description: |-
Provides a resource to create a vpc vpn_connection_reset
---

# tencentcloud_vpn_connection_reset

Provides a resource to create a vpc vpn_connection_reset

## Example Usage

```hcl
resource "tencentcloud_vpn_connection_reset" "vpn_connection_reset" {
vpn_gateway_id = "vpngw-gt8bianl"
vpn_connection_id = "vpnx-kme2tx8m"
}
```

## Argument Reference

The following arguments are supported:

* `vpn_connection_id` - (Required, String, ForceNew) VPN CONNECTION INSTANCE ID.
* `vpn_gateway_id` - (Required, String, ForceNew) VPN GATEWAY INSTANCE ID.

## Attributes Reference

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

* `id` - ID of the resource.



Loading