Skip to content

Commit 39eb4ce

Browse files
authored
Merge pull request #1636 from tencentcloudstack/feat/add_vpn_operation
add vpn operation
2 parents f8a29bf + 8525a29 commit 39eb4ce

9 files changed

+730
-286
lines changed

.changelog/1636.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:new-resource
2+
tencentcloud_vpn_connection_reset
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_vpn_customer_gateway_configuration_download
7+
```

tencentcloud/provider.go

Lines changed: 290 additions & 286 deletions
Large diffs are not rendered by default.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
Provides a resource to create a vpc vpn_connection_reset
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_vpn_connection_reset" "vpn_connection_reset" {
8+
vpn_gateway_id = "vpngw-gt8bianl"
9+
vpn_connection_id = "vpnx-kme2tx8m"
10+
}
11+
```
12+
*/
13+
package tencentcloud
14+
15+
import (
16+
"log"
17+
18+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
19+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
20+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
21+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
22+
)
23+
24+
func resourceTencentCloudVpnConnectionReset() *schema.Resource {
25+
return &schema.Resource{
26+
Create: resourceTencentCloudVpnConnectionResetCreate,
27+
Read: resourceTencentCloudVpnConnectionResetRead,
28+
Delete: resourceTencentCloudVpnConnectionResetDelete,
29+
Schema: map[string]*schema.Schema{
30+
"vpn_gateway_id": {
31+
Required: true,
32+
ForceNew: true,
33+
Type: schema.TypeString,
34+
Description: "VPN GATEWAY INSTANCE ID.",
35+
},
36+
37+
"vpn_connection_id": {
38+
Required: true,
39+
ForceNew: true,
40+
Type: schema.TypeString,
41+
Description: "VPN CONNECTION INSTANCE ID.",
42+
},
43+
},
44+
}
45+
}
46+
47+
func resourceTencentCloudVpnConnectionResetCreate(d *schema.ResourceData, meta interface{}) error {
48+
defer logElapsed("data_source.tencentcloud_vpn_connection_reset.read")()
49+
defer inconsistentCheck(d, meta)()
50+
51+
logId := getLogId(contextNil)
52+
53+
var (
54+
request = vpc.NewResetVpnConnectionRequest()
55+
vpnGatewayId string
56+
vpnConnectionId string
57+
)
58+
if v, ok := d.GetOk("vpn_gateway_id"); ok {
59+
vpnGatewayId = v.(string)
60+
request.VpnGatewayId = helper.String(v.(string))
61+
}
62+
63+
if v, ok := d.GetOk("vpn_connection_id"); ok {
64+
vpnConnectionId = v.(string)
65+
request.VpnConnectionId = helper.String(v.(string))
66+
}
67+
68+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
69+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().ResetVpnConnection(request)
70+
if e != nil {
71+
return retryError(e)
72+
} else {
73+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
74+
}
75+
return nil
76+
})
77+
if err != nil {
78+
log.Printf("[CRITAL]%s operate vpc vpnConnectionReset failed, reason:%+v", logId, err)
79+
return nil
80+
}
81+
82+
d.SetId(vpnGatewayId + FILED_SP + vpnConnectionId)
83+
84+
return resourceTencentCloudVpnConnectionResetRead(d, meta)
85+
}
86+
87+
func resourceTencentCloudVpnConnectionResetRead(d *schema.ResourceData, meta interface{}) error {
88+
defer logElapsed("resource.tencentcloud_vpn_connection_reset.read")()
89+
defer inconsistentCheck(d, meta)()
90+
91+
return nil
92+
}
93+
94+
func resourceTencentCloudVpnConnectionResetDelete(d *schema.ResourceData, meta interface{}) error {
95+
defer logElapsed("resource.tencentcloud_vpn_connection_reset.delete")()
96+
defer inconsistentCheck(d, meta)()
97+
98+
return nil
99+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudVpnConnectionResetResource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccVpcVpnConnectionReset,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_vpn_connection_reset.vpn_connection_reset", "id")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccVpcVpnConnectionReset = `
26+
27+
resource "tencentcloud_vpn_connection_reset" "vpn_connection_reset" {
28+
vpn_gateway_id = "vpngw-gt8bianl"
29+
vpn_connection_id = "vpnx-kme2tx8m"
30+
}
31+
32+
`
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
Provides a resource to create a vpc vpn_customer_gateway_configuration_download
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_vpn_customer_gateway_configuration_download" "vpn_customer_gateway_configuration_download" {
8+
vpn_gateway_id = "vpngw-gt8bianl"
9+
vpn_connection_id = "vpnx-kme2tx8m"
10+
customer_gateway_vendor {
11+
platform = "comware"
12+
software_version = "V1.0"
13+
vendor_name = "h3c"
14+
}
15+
interface_name = "test"
16+
}
17+
```
18+
*/
19+
package tencentcloud
20+
21+
import (
22+
"log"
23+
24+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
25+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
26+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
27+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
28+
)
29+
30+
func resourceTencentCloudVpnCustomerGatewayConfigurationDownload() *schema.Resource {
31+
return &schema.Resource{
32+
Create: resourceTencentCloudVpnCustomerGatewayConfigurationDownloadCreate,
33+
Read: resourceTencentCloudVpnCustomerGatewayConfigurationDownloadRead,
34+
Delete: resourceTencentCloudVpnCustomerGatewayConfigurationDownloadDelete,
35+
Importer: &schema.ResourceImporter{
36+
State: schema.ImportStatePassthrough,
37+
},
38+
Schema: map[string]*schema.Schema{
39+
"vpn_gateway_id": {
40+
Required: true,
41+
ForceNew: true,
42+
Type: schema.TypeString,
43+
Description: "VPN Gateway Instance ID.",
44+
},
45+
46+
"vpn_connection_id": {
47+
Required: true,
48+
ForceNew: true,
49+
Type: schema.TypeString,
50+
Description: "VPN Connection Instance id.",
51+
},
52+
53+
"customer_gateway_vendor": {
54+
Required: true,
55+
ForceNew: true,
56+
Type: schema.TypeList,
57+
MaxItems: 1,
58+
Description: "Customer Gateway Vendor Info.",
59+
Elem: &schema.Resource{
60+
Schema: map[string]*schema.Schema{
61+
"platform": {
62+
Type: schema.TypeString,
63+
Required: true,
64+
Description: "Platform.",
65+
},
66+
"software_version": {
67+
Type: schema.TypeString,
68+
Required: true,
69+
Description: "SoftwareVersion.",
70+
},
71+
"vendor_name": {
72+
Type: schema.TypeString,
73+
Required: true,
74+
Description: "VendorName.",
75+
},
76+
},
77+
},
78+
},
79+
80+
"interface_name": {
81+
Required: true,
82+
ForceNew: true,
83+
Type: schema.TypeString,
84+
Description: "VPN connection access device physical interface name.",
85+
},
86+
87+
"customer_gateway_configuration": {
88+
Computed: true,
89+
Type: schema.TypeString,
90+
Description: "xml configuration.",
91+
},
92+
},
93+
}
94+
}
95+
96+
func resourceTencentCloudVpnCustomerGatewayConfigurationDownloadCreate(d *schema.ResourceData, meta interface{}) error {
97+
defer logElapsed("data_source.tencentcloud_vpn_customer_gateway_configuration_download.read")()
98+
defer inconsistentCheck(d, meta)()
99+
100+
logId := getLogId(contextNil)
101+
102+
var (
103+
request = vpc.NewDownloadCustomerGatewayConfigurationRequest()
104+
response = vpc.NewDownloadCustomerGatewayConfigurationResponse()
105+
vpnGatewayId string
106+
vpnConnectionId string
107+
)
108+
if v, ok := d.GetOk("vpn_gateway_id"); ok {
109+
vpnGatewayId = v.(string)
110+
request.VpnGatewayId = helper.String(v.(string))
111+
}
112+
113+
if v, ok := d.GetOk("vpn_connection_id"); ok {
114+
vpnConnectionId = v.(string)
115+
request.VpnConnectionId = helper.String(v.(string))
116+
}
117+
118+
if dMap, ok := helper.InterfacesHeadMap(d, "customer_gateway_vendor"); ok {
119+
customerGatewayVendor := vpc.CustomerGatewayVendor{}
120+
if v, ok := dMap["platform"]; ok {
121+
customerGatewayVendor.Platform = helper.String(v.(string))
122+
}
123+
if v, ok := dMap["software_version"]; ok {
124+
customerGatewayVendor.SoftwareVersion = helper.String(v.(string))
125+
}
126+
if v, ok := dMap["vendor_name"]; ok {
127+
customerGatewayVendor.VendorName = helper.String(v.(string))
128+
}
129+
request.CustomerGatewayVendor = &customerGatewayVendor
130+
}
131+
132+
if v, ok := d.GetOk("interface_name"); ok {
133+
request.InterfaceName = helper.String(v.(string))
134+
}
135+
136+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
137+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().DownloadCustomerGatewayConfiguration(request)
138+
if e != nil {
139+
return retryError(e)
140+
} else {
141+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
142+
}
143+
response = result
144+
return nil
145+
})
146+
if err != nil {
147+
log.Printf("[CRITAL]%s operate vpc vpnCustomerGatewayConfigurationDownload failed, reason:%+v", logId, err)
148+
return nil
149+
}
150+
151+
d.SetId(vpnGatewayId + FILED_SP + vpnConnectionId)
152+
153+
d.Set("customer_gateway_configuration", response.Response.CustomerGatewayConfiguration)
154+
155+
return resourceTencentCloudVpnCustomerGatewayConfigurationDownloadRead(d, meta)
156+
}
157+
158+
func resourceTencentCloudVpnCustomerGatewayConfigurationDownloadRead(d *schema.ResourceData, meta interface{}) error {
159+
defer logElapsed("resource.tencentcloud_vpn_customer_gateway_configuration_download.read")()
160+
defer inconsistentCheck(d, meta)()
161+
162+
return nil
163+
}
164+
165+
func resourceTencentCloudVpnCustomerGatewayConfigurationDownloadDelete(d *schema.ResourceData, meta interface{}) error {
166+
defer logElapsed("resource.tencentcloud_vpn_customer_gateway_configuration_download.delete")()
167+
defer inconsistentCheck(d, meta)()
168+
169+
return nil
170+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudVpnCustomerGatewayConfigurationDownloadResource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccVpcVpnCustomerGatewayConfigurationDownload,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_vpn_customer_gateway_configuration_download.vpn_customer_gateway_configuration_download", "id")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccVpcVpnCustomerGatewayConfigurationDownload = `
26+
27+
resource "tencentcloud_vpn_customer_gateway_configuration_download" "vpn_customer_gateway_configuration_download" {
28+
vpn_gateway_id = "vpngw-gt8bianl"
29+
vpn_connection_id = "vpnx-kme2tx8m"
30+
customer_gateway_vendor {
31+
platform = "comware"
32+
software_version = "V1.0"
33+
vendor_name = "h3c"
34+
}
35+
interface_name = "test"
36+
}
37+
38+
`
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
subcategory: "VPN Connections(VPN)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_vpn_connection_reset"
5+
sidebar_current: "docs-tencentcloud-resource-vpn_connection_reset"
6+
description: |-
7+
Provides a resource to create a vpc vpn_connection_reset
8+
---
9+
10+
# tencentcloud_vpn_connection_reset
11+
12+
Provides a resource to create a vpc vpn_connection_reset
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_vpn_connection_reset" "vpn_connection_reset" {
18+
vpn_gateway_id = "vpngw-gt8bianl"
19+
vpn_connection_id = "vpnx-kme2tx8m"
20+
}
21+
```
22+
23+
## Argument Reference
24+
25+
The following arguments are supported:
26+
27+
* `vpn_connection_id` - (Required, String, ForceNew) VPN CONNECTION INSTANCE ID.
28+
* `vpn_gateway_id` - (Required, String, ForceNew) VPN GATEWAY INSTANCE ID.
29+
30+
## Attributes Reference
31+
32+
In addition to all arguments above, the following attributes are exported:
33+
34+
* `id` - ID of the resource.
35+
36+
37+

0 commit comments

Comments
 (0)