Skip to content

Commit 91834b6

Browse files
committed
add vpn ccn routes
1 parent 2c4a42f commit 91834b6

File tree

6 files changed

+304
-0
lines changed

6 files changed

+304
-0
lines changed

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ VPN Connections(VPN)
723723
tencentcloud_vpn_connection_reset
724724
tencentcloud_vpn_customer_gateway_configuration_download
725725
tencentcloud_vpn_gateway_ssl_client_cert
726+
tencentcloud_vpn_gateway_ccn_routes
726727
727728
MapReduce(EMR)
728729
Data Source
@@ -1494,6 +1495,7 @@ func Provider() terraform.ResourceProvider {
14941495
"tencentcloud_vpn_connection_reset": resourceTencentCloudVpnConnectionReset(),
14951496
"tencentcloud_vpn_customer_gateway_configuration_download": resourceTencentCloudVpnCustomerGatewayConfigurationDownload(),
14961497
"tencentcloud_vpn_gateway_ssl_client_cert": resourceTencentCloudVpnGatewaySslClientCert(),
1498+
"tencentcloud_vpn_gateway_ccn_routes": resourceTencentCloudVpnGatewayCcnRoutes(),
14971499
"tencentcloud_ha_vip": resourceTencentCloudHaVip(),
14981500
"tencentcloud_ha_vip_eip_attachment": resourceTencentCloudHaVipEipAttachment(),
14991501
"tencentcloud_security_group": resourceTencentCloudSecurityGroup(),
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
Provides a resource to create a vpn_gateway_ccn_routes
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_vpn_gateway_ccn_routes" "vpn_gateway_ccn_routes" {
8+
destination_cidr_block = "192.168.1.0/24"
9+
route_id = "vpnr-akdy0757"
10+
status = "DISABLE"
11+
vpn_gateway_id = "vpngw-lie1a4u7"
12+
}
13+
14+
```
15+
16+
Import
17+
18+
vpc vpn_gateway_ccn_routes can be imported using the id, e.g.
19+
20+
```
21+
terraform import tencentcloud_vpn_gateway_ccn_routes.vpn_gateway_ccn_routes vpn_gateway_id#ccn_routes_id
22+
```
23+
*/
24+
package tencentcloud
25+
26+
import (
27+
"context"
28+
"fmt"
29+
"log"
30+
"strings"
31+
32+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
33+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
34+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
35+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
36+
)
37+
38+
func resourceTencentCloudVpnGatewayCcnRoutes() *schema.Resource {
39+
return &schema.Resource{
40+
Create: resourceTencentCloudVpnGatewayCcnRoutesCreate,
41+
Read: resourceTencentCloudVpnGatewayCcnRoutesRead,
42+
Update: resourceTencentCloudVpnGatewayCcnRoutesUpdate,
43+
Delete: resourceTencentCloudVpnGatewayCcnRoutesDelete,
44+
Importer: &schema.ResourceImporter{
45+
State: schema.ImportStatePassthrough,
46+
},
47+
Schema: map[string]*schema.Schema{
48+
"vpn_gateway_id": {
49+
Required: true,
50+
ForceNew: true,
51+
Type: schema.TypeString,
52+
Description: "VPN GATEWAY INSTANCE ID.",
53+
},
54+
"route_id": {
55+
Type: schema.TypeString,
56+
ForceNew: true,
57+
Required: true,
58+
Description: "Route Id.",
59+
},
60+
"status": {
61+
Type: schema.TypeString,
62+
Required: true,
63+
Description: "Whether routing information is enabled. `ENABLE`: Enable Route, `DISABLE`: Disable Route.",
64+
},
65+
"destination_cidr_block": {
66+
Type: schema.TypeString,
67+
Required: true,
68+
ForceNew: true,
69+
Description: "Routing CIDR.",
70+
},
71+
},
72+
}
73+
}
74+
75+
func resourceTencentCloudVpnGatewayCcnRoutesCreate(d *schema.ResourceData, meta interface{}) error {
76+
defer logElapsed("resource.tencentcloud_vpn_gateway_ccn_routes.create")()
77+
defer inconsistentCheck(d, meta)()
78+
79+
var (
80+
vpnGwId string
81+
routeId string
82+
)
83+
84+
if v, ok := d.GetOk("vpn_gateway_id"); ok {
85+
vpnGwId = v.(string)
86+
}
87+
88+
if v, ok := d.GetOk("route_id"); ok {
89+
routeId = v.(string)
90+
}
91+
92+
d.SetId(vpnGwId + FILED_SP + routeId)
93+
94+
return resourceTencentCloudVpnGatewayCcnRoutesUpdate(d, meta)
95+
}
96+
97+
func resourceTencentCloudVpnGatewayCcnRoutesRead(d *schema.ResourceData, meta interface{}) error {
98+
defer logElapsed("resource.tencentcloud_vpn_gateway_ccn_routes.read")()
99+
defer inconsistentCheck(d, meta)()
100+
101+
logId := getLogId(contextNil)
102+
103+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
104+
105+
service := VpcService{client: meta.(*TencentCloudClient).apiV3Conn}
106+
107+
idSplit := strings.Split(d.Id(), FILED_SP)
108+
if len(idSplit) != 2 {
109+
return fmt.Errorf("id is broken,%s", d.Id())
110+
}
111+
vpnGatewayId := idSplit[0]
112+
routeId := idSplit[1]
113+
114+
vpnGatewayCcnRoutes, err := service.DescribeVpcVpnGatewayCcnRoutesById(ctx, vpnGatewayId, routeId)
115+
if err != nil {
116+
return err
117+
}
118+
119+
if vpnGatewayCcnRoutes == nil {
120+
d.SetId("")
121+
log.Printf("[WARN]%s resource `VpcVpnGatewayCcnRoutes` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
122+
return nil
123+
}
124+
125+
_ = d.Set("vpn_gateway_id", vpnGatewayId)
126+
_ = d.Set("route_id", vpnGatewayCcnRoutes.RouteId)
127+
_ = d.Set("status", vpnGatewayCcnRoutes.Status)
128+
_ = d.Set("destination_cidr_block", vpnGatewayCcnRoutes.DestinationCidrBlock)
129+
130+
return nil
131+
}
132+
133+
func resourceTencentCloudVpnGatewayCcnRoutesUpdate(d *schema.ResourceData, meta interface{}) error {
134+
defer logElapsed("resource.tencentcloud_vpn_gateway_ccn_routes.update")()
135+
defer inconsistentCheck(d, meta)()
136+
137+
logId := getLogId(contextNil)
138+
139+
request := vpc.NewModifyVpnGatewayCcnRoutesRequest()
140+
141+
idSplit := strings.Split(d.Id(), FILED_SP)
142+
if len(idSplit) != 2 {
143+
return fmt.Errorf("id is broken,%s", d.Id())
144+
}
145+
vpnGatewayId := idSplit[0]
146+
routeId := idSplit[1]
147+
148+
request.VpnGatewayId = &vpnGatewayId
149+
route := vpc.VpngwCcnRoutes{}
150+
route.RouteId = &routeId
151+
route.Status = helper.String(d.Get("status").(string))
152+
route.DestinationCidrBlock = helper.String(d.Get("destination_cidr_block").(string))
153+
request.Routes = append(request.Routes, &route)
154+
155+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
156+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().ModifyVpnGatewayCcnRoutes(request)
157+
if e != nil {
158+
return retryError(e)
159+
} else {
160+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
161+
}
162+
return nil
163+
})
164+
if err != nil {
165+
log.Printf("[CRITAL]%s update vpnGatewayCcnRoutes failed, reason:%+v", logId, err)
166+
return err
167+
}
168+
169+
return resourceTencentCloudVpnGatewayCcnRoutesRead(d, meta)
170+
}
171+
172+
func resourceTencentCloudVpnGatewayCcnRoutesDelete(d *schema.ResourceData, meta interface{}) error {
173+
defer logElapsed("resource.tencentcloud_vpn_gateway_ccn_routes.delete")()
174+
defer inconsistentCheck(d, meta)()
175+
176+
return nil
177+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudNeedFixVpnGatewayCcnRoutesResource_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: testAccVpcVpnGatewayCcnRoutes,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_vpn_gateway_ccn_routes.vpn_gateway_ccn_routes", "id")),
20+
},
21+
{
22+
ResourceName: "tencentcloud_vpn_gateway_ccn_routes.vpn_gateway_ccn_routes",
23+
ImportState: true,
24+
ImportStateVerify: true,
25+
},
26+
},
27+
})
28+
}
29+
30+
const testAccVpcVpnGatewayCcnRoutes = `
31+
32+
resource "tencentcloud_vpn_gateway_ccn_routes" "vpn_gateway_ccn_routes" {
33+
destination_cidr_block = "192.168.1.0/24"
34+
route_id = "vpnr-akdy0757"
35+
status = "DISABLE"
36+
vpn_gateway_id = "vpngw-lie1a4u7"
37+
}
38+
39+
`

tencentcloud/service_tencentcloud_vpc.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6052,3 +6052,37 @@ func (me *VpcService) DescribeVpnCustomerGatewayVendors(ctx context.Context) (vp
60526052
vpnCustomerGatewayVendors = response.Response.CustomerGatewayVendorSet
60536053
return
60546054
}
6055+
6056+
func (me *VpcService) DescribeVpcVpnGatewayCcnRoutesById(ctx context.Context, vpnGatewayId string, routeId string) (vpnGatewayCcnRoutes *vpc.VpngwCcnRoutes, errRet error) {
6057+
logId := getLogId(ctx)
6058+
6059+
request := vpc.NewDescribeVpnGatewayCcnRoutesRequest()
6060+
request.VpnGatewayId = &vpnGatewayId
6061+
6062+
defer func() {
6063+
if errRet != nil {
6064+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
6065+
}
6066+
}()
6067+
6068+
ratelimit.Check(request.GetAction())
6069+
6070+
response, err := me.client.UseVpcClient().DescribeVpnGatewayCcnRoutes(request)
6071+
if err != nil {
6072+
errRet = err
6073+
return
6074+
}
6075+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
6076+
6077+
if len(response.Response.RouteSet) < 1 {
6078+
return
6079+
}
6080+
6081+
for _, route := range response.Response.RouteSet {
6082+
if *route.RouteId == routeId {
6083+
vpnGatewayCcnRoutes = route
6084+
break
6085+
}
6086+
}
6087+
return
6088+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
subcategory: "VPN Connections(VPN)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_vpn_gateway_ccn_routes"
5+
sidebar_current: "docs-tencentcloud-resource-vpn_gateway_ccn_routes"
6+
description: |-
7+
Provides a resource to create a vpn_gateway_ccn_routes
8+
---
9+
10+
# tencentcloud_vpn_gateway_ccn_routes
11+
12+
Provides a resource to create a vpn_gateway_ccn_routes
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_vpn_gateway_ccn_routes" "vpn_gateway_ccn_routes" {
18+
destination_cidr_block = "192.168.1.0/24"
19+
route_id = "vpnr-akdy0757"
20+
status = "DISABLE"
21+
vpn_gateway_id = "vpngw-lie1a4u7"
22+
}
23+
```
24+
25+
## Argument Reference
26+
27+
The following arguments are supported:
28+
29+
* `destination_cidr_block` - (Required, String, ForceNew) Routing CIDR.
30+
* `route_id` - (Required, String, ForceNew) Route Id.
31+
* `status` - (Required, String) Whether routing information is enabled. `ENABLE`: Enable Route, `DISABLE`: Disable Route.
32+
* `vpn_gateway_id` - (Required, String, ForceNew) VPN GATEWAY INSTANCE ID.
33+
34+
## Attributes Reference
35+
36+
In addition to all arguments above, the following attributes are exported:
37+
38+
* `id` - ID of the resource.
39+
40+
41+
42+
## Import
43+
44+
vpc vpn_gateway_ccn_routes can be imported using the id, e.g.
45+
46+
```
47+
terraform import tencentcloud_vpn_gateway_ccn_routes.vpn_gateway_ccn_routes vpn_gateway_id#ccn_routes_id
48+
```
49+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,9 @@
29312931
<li>
29322932
<a href="/docs/providers/tencentcloud/r/vpn_gateway.html">tencentcloud_vpn_gateway</a>
29332933
</li>
2934+
<li>
2935+
<a href="/docs/providers/tencentcloud/r/vpn_gateway_ccn_routes.html">tencentcloud_vpn_gateway_ccn_routes</a>
2936+
</li>
29342937
<li>
29352938
<a href="/docs/providers/tencentcloud/r/vpn_gateway_route.html">tencentcloud_vpn_gateway_route</a>
29362939
</li>

0 commit comments

Comments
 (0)