Skip to content

Commit 12f87c5

Browse files
authored
Merge pull request #491 from brickzzhang/ccn-fix
[vpn connection fix]
2 parents a50f66e + fc394ce commit 12f87c5

File tree

7 files changed

+65
-13
lines changed

7 files changed

+65
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
## 1.40.3 (Unreleased)
1+
## 1.40.3 (Unreleased)
22

33
ENHANCEMENTS:
44

55
* Data Source: `tencentcloud_kubernetes_clusters`add new attributes `cluster_as_enabled`,`node_name_type`,`cluster_extra_args`,`network_type`,`is_non_static_ip_mode`,`kube_proxy_mode`,`service_cidr`,`eni_subnet_ids`,`claim_expired_seconds` and `deletion_protection`.
66

7+
BUG FIXES:
8+
9+
* Resource: `tencentcloud_vpn_gateway` fix creation of instance when `vpc_id` is specified.
10+
* Resource: `tencentcloud_vpn_connection` fix creation of instance when `vpc_id` is specified.
11+
712
## 1.40.2 (August 08, 2020)
813

914
BUG FIXES:

examples/tencentcloud-vpn/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ data "tencentcloud_vpn_connections" "example" {
6868
# vpn tunnel in the usual way.
6969
resource tencentcloud_vpn_gateway ccn_vpngw_example {
7070
name = "ccn-vpngw-example"
71-
vpc_id = ""
7271
bandwidth = 5
7372
zone = var.availability_zone
7473
type = "CCN"

tencentcloud/resource_tc_vpn_connection.go

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ func resourceTencentCloudVpnConnection() *schema.Resource {
7777
},
7878
"vpc_id": {
7979
Type: schema.TypeString,
80-
Required: true,
80+
Optional: true,
8181
ForceNew: true,
82-
Description: "ID of the VPC.",
82+
Description: "ID of the VPC. Required if vpn gateway is not in `CCN` type, and doesn't make sense for `CCN` vpn gateway.",
8383
},
8484
"customer_gateway_id": {
8585
Type: schema.TypeString,
@@ -277,9 +277,46 @@ func resourceTencentCloudVpnConnectionCreate(d *schema.ResourceData, meta interf
277277
logId := getLogId(contextNil)
278278
ctx := context.WithValue(context.TODO(), logIdKey, logId)
279279

280+
// pre check vpn gateway id
281+
requestVpngw := vpc.NewDescribeVpnGatewaysRequest()
282+
requestVpngw.VpnGatewayIds = []*string{helper.String(d.Get("vpn_gateway_id").(string))}
283+
var responseVpngw *vpc.DescribeVpnGatewaysResponse
284+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
285+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().DescribeVpnGateways(requestVpngw)
286+
if e != nil {
287+
ee, ok := e.(*errors.TencentCloudSDKError)
288+
if !ok {
289+
return retryError(e)
290+
}
291+
if ee.Code == VPCNotFound {
292+
return nil
293+
} else {
294+
return retryError(e)
295+
}
296+
}
297+
responseVpngw = result
298+
return nil
299+
})
300+
if err != nil {
301+
return err
302+
}
303+
if len(responseVpngw.Response.VpnGatewaySet) < 1 {
304+
return fmt.Errorf("[CRITAL] vpn_gateway_id %s doesn't exist", d.Get("vpn_gateway_id").(string))
305+
}
306+
307+
gateway := responseVpngw.Response.VpnGatewaySet[0]
308+
309+
// create vpn connection
280310
request := vpc.NewCreateVpnConnectionRequest()
281311
request.VpnConnectionName = helper.String(d.Get("name").(string))
282-
request.VpcId = helper.String(d.Get("vpc_id").(string))
312+
if *gateway.Type != "CCN" {
313+
if _, ok := d.GetOk("vpc_id"); !ok {
314+
return fmt.Errorf("[CRITAL] vpc_id is required for this vpn connection which vpn gateway is in %s type", *gateway.Type)
315+
}
316+
request.VpcId = helper.String(d.Get("vpc_id").(string))
317+
} else {
318+
request.VpcId = helper.String("")
319+
}
283320
request.VpnGatewayId = helper.String(d.Get("vpn_gateway_id").(string))
284321
request.CustomerGatewayId = helper.String(d.Get("customer_gateway_id").(string))
285322
request.PreShareKey = helper.String(d.Get("pre_share_key").(string))
@@ -361,7 +398,7 @@ func resourceTencentCloudVpnConnectionCreate(d *schema.ResourceData, meta interf
361398
request.IPSECOptionsSpecification = &ipsecOptionsSpecification
362399

363400
var response *vpc.CreateVpnConnectionResponse
364-
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
401+
err = resource.Retry(readRetryTimeout, func() *resource.RetryError {
365402
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().CreateVpnConnection(request)
366403
if e != nil {
367404
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
@@ -389,7 +426,7 @@ func resourceTencentCloudVpnConnectionCreate(d *schema.ResourceData, meta interf
389426
if v, ok := d.GetOk("vpn_gateway_id"); ok {
390427
params["vpn-gateway-id"] = v.(string)
391428
}
392-
if v, ok := d.GetOk("vpc_id"); ok {
429+
if v, ok := d.GetOk("vpc_id"); ok && *gateway.Type != "CCN" {
393430
params["vpc-id"] = v.(string)
394431
}
395432
if v, ok := d.GetOk("customer_gateway_id"); ok {

tencentcloud/resource_tc_vpn_gateway.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ func resourceTencentCloudVpnGateway() *schema.Resource {
7777
},
7878
"vpc_id": {
7979
Type: schema.TypeString,
80-
Required: true,
80+
Optional: true,
8181
ForceNew: true,
82-
Description: "ID of the VPC.",
82+
Description: "ID of the VPC. Required if vpn gateway is not in `CCN` type, and doesn't make sense if vpn gateway is in `CCN` type.",
8383
},
8484
"bandwidth": {
8585
Type: schema.TypeInt,
@@ -174,7 +174,6 @@ func resourceTencentCloudVpnGatewayCreate(d *schema.ResourceData, meta interface
174174
bandwidth64 := uint64(bandwidth)
175175
request.InternetMaxBandwidthOut = &bandwidth64
176176
request.Zone = helper.String(d.Get("zone").(string))
177-
request.VpcId = helper.String(d.Get("vpc_id").(string))
178177
chargeType := d.Get("charge_type").(string)
179178
//only support change renew_flag when charge type is pre-paid
180179
if chargeType == VPN_CHARGE_TYPE_PREPAID {
@@ -186,6 +185,19 @@ func resourceTencentCloudVpnGatewayCreate(d *schema.ResourceData, meta interface
186185
request.InstanceChargeType = &chargeType
187186
if v, ok := d.GetOk("type"); ok {
188187
request.Type = helper.String(v.(string))
188+
if v.(string) != "CCN" {
189+
if _, ok := d.GetOk("vpc_id"); !ok {
190+
return fmt.Errorf("[CRITAL] vpc_id is required for vpn gateway in %s type", v.(string))
191+
}
192+
request.VpcId = helper.String(d.Get("vpc_id").(string))
193+
} else {
194+
request.VpcId = helper.String("")
195+
}
196+
} else {
197+
if _, ok := d.GetOk("vpc_id"); !ok {
198+
return fmt.Errorf("[CRITAL] vpc_id is required for vpn gateway in %s type", v.(string))
199+
}
200+
request.VpcId = helper.String(d.Get("vpc_id").(string))
189201
}
190202
var response *vpc.CreateVpnGatewayResponse
191203
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {

tencentcloud/resource_tc_vpn_gateway_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ resource "tencentcloud_vpn_gateway" "my_ccn_cgw" {
182182
name = "terraform_ccn_vpngw_test"
183183
bandwidth = 5
184184
zone = "ap-guangzhou-3"
185-
vpc_id = ""
186185
type = "CCN"
187186
188187
tags = {

website/docs/r/vpn_connection.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ The following arguments are supported:
5252
* `name` - (Required) Name of the VPN connection. The length of character is limited to 1-60.
5353
* `pre_share_key` - (Required) Pre-shared key of the VPN connection.
5454
* `security_group_policy` - (Required) Security group policy of the VPN connection.
55-
* `vpc_id` - (Required, ForceNew) ID of the VPC.
5655
* `vpn_gateway_id` - (Required, ForceNew) ID of the VPN gateway.
5756
* `ike_dh_group_name` - (Optional) DH group name of the IKE operation specification, valid values are `GROUP1`, `GROUP2`, `GROUP5`, `GROUP14`, `GROUP24`. Default value is `GROUP1`.
5857
* `ike_exchange_mode` - (Optional) Exchange mode of the IKE operation specification, valid values are `AGGRESSIVE`, `MAIN`. Default value is `MAIN`.
@@ -72,6 +71,7 @@ The following arguments are supported:
7271
* `ipsec_sa_lifetime_seconds` - (Optional) SA lifetime of the IPSEC operation specification, unit is `second`. The value ranges from 180 to 604800. Default value is 3600 seconds.
7372
* `ipsec_sa_lifetime_traffic` - (Optional) SA lifetime of the IPSEC operation specification, unit is `KB`. The value should not be less then 2560. Default value is 1843200.
7473
* `tags` - (Optional) A list of tags used to associate different resources.
74+
* `vpc_id` - (Optional, ForceNew) ID of the VPC. Required if vpn gateway is not in `CCN` type, and doesn't make sense for `CCN` vpn gateway.
7575

7676
The `security_group_policy` object supports the following:
7777

website/docs/r/vpn_gateway.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ resource "tencentcloud_vpn_gateway" "my_cgw" {
5151
The following arguments are supported:
5252

5353
* `name` - (Required) Name of the VPN gateway. The length of character is limited to 1-60.
54-
* `vpc_id` - (Required, ForceNew) ID of the VPC.
5554
* `zone` - (Required, ForceNew) Zone of the VPN gateway.
5655
* `bandwidth` - (Optional) The maximum public network output bandwidth of VPN gateway (unit: Mbps), the available values include: 5,10,20,50,100,200,500,1000. Default is 5. When charge type is `PREPAID`, bandwidth degradation operation is unsupported.
5756
* `charge_type` - (Optional) Charge Type of the VPN gateway, valid values are `PREPAID`, `POSTPAID_BY_HOUR` and default is `POSTPAID_BY_HOUR`.
5857
* `prepaid_period` - (Optional) Period of instance to be prepaid. Valid values are 1, 2, 3, 4, 6, 7, 8, 9, 12, 24, 36 and unit is month. Caution: when this para and renew_flag para are valid, the request means to renew several months more pre-paid period. This para can only be set to take effect in create operation.
5958
* `prepaid_renew_flag` - (Optional) Flag indicates whether to renew or not, valid values are `NOTIFY_AND_RENEW`, `NOTIFY_AND_AUTO_RENEW`, `NOT_NOTIFY_AND_NOT_RENEW`. This para can only be set to take effect in create operation.
6059
* `tags` - (Optional) A list of tags used to associate different resources.
6160
* `type` - (Optional) Type of gateway instance, valid values are `IPSEC`, `SSL` and `CCN`. Note: CCN type is only for whitelist customer now.
61+
* `vpc_id` - (Optional, ForceNew) ID of the VPC. Required if vpn gateway is not in `CCN` type, and doesn't make sense if vpn gateway is in `CCN` type.
6262

6363
## Attributes Reference
6464

0 commit comments

Comments
 (0)