Skip to content

Commit 64eb351

Browse files
authored
Merge pull request #183 from terraform-tencentcloud/vpn-dev
add resrouce `vpn gateway`, `customer gateway` and `vpn connection`
2 parents 1d976fb + dbcb941 commit 64eb351

28 files changed

+3964
-28
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
FEATURES:
44

5+
* **New Data Source**: `tencentcloud_vpn_gateways`
6+
* **New Data Source**: `tencentcloud_customer_gateways`
7+
* **New Data Source**: `tencentcloud_vpn_connections`
8+
* **New Resource**: `tencentcloud_vpn_gateway`
9+
* **New Resource**: `tencentcloud_customer_gateway`
10+
* **New Resource**: `tencentcloud_vpn_connection`
511
* **New Data Source**: `tencentcloud_images`
612
* **Provider TencentCloud**: add `security_token` argument
713

@@ -31,6 +37,7 @@ FEATURES:
3137
* **New Resource**: `tencentcloud_scf_function`
3238
* **New Resource**: `tencentcloud_scf_namespace`
3339

40+
3441
## 1.21.2 (October 29, 2019)
3542

3643
BUG FIXES:

examples/tencentcloud-vpn/main.tf

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
resource "tencentcloud_vpn_customer_gateway" "example" {
3+
name = "example"
4+
public_ip_address = "3.3.3.3"
5+
6+
tags = {
7+
test = "example"
8+
}
9+
}
10+
11+
data "tencentcloud_vpc_instances" "example" {
12+
name = "Default-VPC"
13+
}
14+
15+
resource "tencentcloud_vpn_gateway" "example" {
16+
name = "example"
17+
vpc_id = "${data.tencentcloud_vpc_instances.example.instance_list.0.vpc_id}"
18+
bandwidth = 5
19+
zone = "${var.availability_zone}"
20+
21+
tags = {
22+
test = "test"
23+
}
24+
}
25+
26+
resource "tencentcloud_vpn_connection" "example" {
27+
name = "example"
28+
vpc_id = "${data.tencentcloud_vpc_instances.example.instance_list.0.vpc_id}"
29+
vpn_gateway_id = "${tencentcloud_vpn_gateway.example.id}"
30+
customer_gateway_id = "${tencentcloud_vpn_customer_gateway.example.id}"
31+
pre_share_key = "test"
32+
ike_proto_encry_algorithm = "3DES-CBC"
33+
ike_proto_authen_algorithm = "MD5"
34+
ike_local_identity = "ADDRESS"
35+
ike_local_address = "${tencentcloud_vpn_gateway.example.public_ip_address}"
36+
ike_remote_identity = "ADDRESS"
37+
ike_remote_address = "${tencentcloud_vpn_customer_gateway.example.public_ip_address}"
38+
ike_dh_group_name = "GROUP1"
39+
ike_sa_lifetime_seconds = 86400
40+
ipsec_encrypt_algorithm = "3DES-CBC"
41+
ipsec_integrity_algorithm = "MD5"
42+
ipsec_sa_lifetime_seconds = 3600
43+
ipsec_pfs_dh_group = "DH-GROUP1"
44+
ipsec_sa_lifetime_traffic = 2560
45+
46+
security_group_policy {
47+
local_cidr_block = "172.16.0.0/16"
48+
remote_cidr_block = ["3.3.3.0/32", ]
49+
}
50+
tags = {
51+
test = "test"
52+
}
53+
}
54+
55+
data "tencentcloud_vpn_customer_gateways" "example" {
56+
id = "${tencentcloud_vpn_customer_gateway.example.id}"
57+
}
58+
59+
data "tencentcloud_vpn_gateways" "example" {
60+
id = "${tencentcloud_vpn_gateway.example.id}"
61+
}
62+
63+
data "tencentcloud_vpn_connections" "example" {
64+
id = "${tencentcloud_vpn_connection.example.id}"
65+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
variable "availability_zone" {
2+
default = "ap-guangzhou-3"
3+
}

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
327327
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
328328
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
329329
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
330+
github.com/keegancsmith/rpc v1.1.0 h1:bXVRk3EzbtrEegTGKxNTc+St1lR7t/Z1PAO8misBnCc=
331+
github.com/keegancsmith/rpc v1.1.0/go.mod h1:Xow74TKX34OPPiPCdz6x1o9c0SCxRqGxDuKGk7ZOo8s=
330332
github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba/go.mod h1:ghbZscTyKdM07+Fw3KSi0hcJm+AlEUWj8QLlPtijN/M=
331333
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
332334
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
@@ -583,6 +585,8 @@ golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8U
583585
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M=
584586
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
585587
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
588+
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
589+
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 h1:x/bBzNauLQAlE3fLku/xy92Y8QwKX5HZymrMz2IiKFc=
586590
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
587591
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
588592
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=

tencentcloud/data_source_tc_nat_gateways.go

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ func dataSourceTencentCloudNatGateways() *schema.Resource {
3434
"name": {
3535
Type: schema.TypeString,
3636
Optional: true,
37-
Description: "Name of the nat gateway.",
37+
Description: "Name of the NAT gateway.",
3838
},
3939
"id": {
4040
Type: schema.TypeString,
4141
Optional: true,
42-
Description: "ID of the nat gateway.",
42+
Description: "ID of the NAT gateway.",
4343
},
4444
"result_output_file": {
4545
Type: schema.TypeString,
@@ -51,13 +51,13 @@ func dataSourceTencentCloudNatGateways() *schema.Resource {
5151
"nats": {
5252
Type: schema.TypeList,
5353
Computed: true,
54-
Description: "Information list of the dedicated tunnels.",
54+
Description: "Information list of the dedicated nats.",
5555
Elem: &schema.Resource{
5656
Schema: map[string]*schema.Schema{
5757
"id": {
5858
Type: schema.TypeString,
5959
Computed: true,
60-
Description: "ID of the nat gateway.",
60+
Description: "ID of the NAT gateway.",
6161
},
6262
"vpc_id": {
6363
Type: schema.TypeString,
@@ -67,22 +67,22 @@ func dataSourceTencentCloudNatGateways() *schema.Resource {
6767
"name": {
6868
Type: schema.TypeString,
6969
Computed: true,
70-
Description: "Name of the nat gateway.",
70+
Description: "Name of the NAT gateway.",
7171
},
7272
"state": {
7373
Type: schema.TypeInt,
7474
Computed: true,
75-
Description: "State of the nat gateway.",
75+
Description: "State of the NAT gateway.",
7676
},
7777
"max_concurrent": {
7878
Type: schema.TypeInt,
7979
Computed: true,
80-
Description: "The upper limit of concurrent connection of nat gateway, the available values include: 1000000,3000000,10000000. Default is 1000000.",
80+
Description: "The upper limit of concurrent connection of NAT gateway, the available values include: 1000000,3000000,10000000. Default is 1000000.",
8181
},
8282
"bandwidth": {
8383
Type: schema.TypeInt,
8484
Computed: true,
85-
Description: "The maximum public network output bandwidth of nat gateway (unit: Mbps), the available values include: 20,50,100,200,500,1000,2000,5000. Default is 100.",
85+
Description: "The maximum public network output bandwidth of NAT gateway (unit: Mbps), the available values include: 20,50,100,200,500,1000,2000,5000. Default is 100.",
8686
},
8787
"assigned_eip_set": {
8888
Type: schema.TypeList,
@@ -93,7 +93,7 @@ func dataSourceTencentCloudNatGateways() *schema.Resource {
9393
"create_time": {
9494
Type: schema.TypeString,
9595
Computed: true,
96-
Description: "Create time of the nat gateway.",
96+
Description: "Create time of the NAT gateway.",
9797
},
9898
},
9999
},
@@ -126,24 +126,38 @@ func dataSourceTencentCloudNatGatewaysRead(d *schema.ResourceData, meta interfac
126126
}
127127
request.Filters = append(request.Filters, filter)
128128
}
129-
var response *vpc.DescribeNatGatewaysResponse
130-
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
131-
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().DescribeNatGateways(request)
132-
if e != nil {
133-
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
134-
logId, request.GetAction(), request.ToJsonString(), e.Error())
135-
return retryError(e)
129+
offset := uint64(0)
130+
request.Offset = &offset
131+
result := make([]*vpc.NatGateway, 0)
132+
limit := uint64(NAT_DESCRIBE_LIMIT)
133+
for {
134+
var response *vpc.DescribeNatGatewaysResponse
135+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
136+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().DescribeNatGateways(request)
137+
if e != nil {
138+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
139+
logId, request.GetAction(), request.ToJsonString(), e.Error())
140+
return retryError(e)
141+
}
142+
response = result
143+
return nil
144+
})
145+
if err != nil {
146+
log.Printf("[CRITAL]%s read NAT gateway failed, reason:%s\n ", logId, err.Error())
147+
return err
148+
} else {
149+
result = append(result, response.Response.NatGatewaySet...)
150+
if len(response.Response.NatGatewaySet) < NAT_DESCRIBE_LIMIT {
151+
break
152+
} else {
153+
offset = offset + limit
154+
request.Offset = &offset
155+
}
136156
}
137-
response = result
138-
return nil
139-
})
140-
if err != nil {
141-
log.Printf("[CRITAL]%s read nat gateway failed, reason:%s\n ", logId, err.Error())
142-
return err
143157
}
144-
ids := make([]string, 0, len(response.Response.NatGatewaySet))
145-
natList := make([]map[string]interface{}, 0, len(response.Response.NatGatewaySet))
146-
for _, nat := range response.Response.NatGatewaySet {
158+
ids := make([]string, 0, len(result))
159+
natList := make([]map[string]interface{}, 0, len(result))
160+
for _, nat := range result {
147161
mapping := map[string]interface{}{
148162
"id": *nat.NatGatewayId,
149163
"vpc_id": *nat.VpcId,
@@ -159,7 +173,7 @@ func dataSourceTencentCloudNatGatewaysRead(d *schema.ResourceData, meta interfac
159173
}
160174
d.SetId(dataResourceIdsHash(ids))
161175
if e := d.Set("nats", natList); e != nil {
162-
log.Printf("[CRITAL]%s provider set clb list fail, reason:%s\n ", logId, e.Error())
176+
log.Printf("[CRITAL]%s provider set NAT list fail, reason:%s\n ", logId, e.Error())
163177
return e
164178
}
165179

0 commit comments

Comments
 (0)