Skip to content

Commit 65aa9e0

Browse files
author
brickzzhang
committed
[support vpngw bound to ccn instance]
1. add ccn type when creating vpngw 2. support vpngw bound to ccn instance 3. bugfix for new Set function, remove * symbol [commiter: brickzzhang]
1 parent 48fac55 commit 65aa9e0

15 files changed

+164
-34
lines changed

CHANGELOG.md

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

33
ENHANCEMENTS:
44
Resource: `tencentcloud_redis_instance` add new argument `type_id`,`redis_shard_num`,`redis_replicas_num`
5+
Resource: `tencentcloud_ccn_attachment` add new type `CNN_INSTANCE_TYPE_VPNGW` for field `instance_type`
6+
Resource: `tencentcloud_vpn_gateway` add new type `CCN` for field `type`
57
Data Source: `tencentcloud_redis_instances` add new argument `type_id`,`redis_shard_num`,`redis_replicas_num`
68
Data Source: `tencentcloud_redis_zone_config` add output argument `type_id` and new output argument `type_id`,`redis_shard_nums`,`redis_replicas_nums`
9+
Data Source: `tencentcloud_ccn_instances` add new type `VPNGW` for field `instance_type`
10+
Data Source: `tencentcloud_vpn_gateways` add new type `CCN` for field `type`
711

812
DEPRECATED:
913
* Resource: `tencentcloud_redis_instance`: optional argument `type` is no longer supported, replace by `type_id`.

examples/tencentcloud-ccn/main.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,28 @@ resource tencentcloud_ccn_bandwidth_limit limit1 {
3737
region = var.other_region
3838
bandwidth_limit = 500
3939
}
40+
41+
resource tencentcloud_vpn_gateway ccn_vpngw {
42+
name = "ci-temp-ccn-vpngw"
43+
vpc_id = ""
44+
bandwidth = 5
45+
zone = var.availability_zone
46+
type = "CCN"
47+
48+
tags = {
49+
test = "ccn-vpngw-test"
50+
}
51+
}
52+
53+
resource tencentcloud_ccn vpngw_ccn_main {
54+
name = "ci-temp-test-vpngw-ccn"
55+
description = "ci-temp-test-vpngw-ccn-des"
56+
qos = "AG"
57+
}
58+
59+
resource tencentcloud_ccn_attachment vpngw_ccn_attachment {
60+
ccn_id = tencentcloud_ccn.vpngw_ccn_main.id
61+
instance_type = "VPNGW"
62+
instance_id = tencentcloud_vpn_gateway.ccn_vpngw.id
63+
instance_region = var.region
64+
}

examples/tencentcloud-ccn/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ variable "region" {
55
variable "other_region" {
66
default = "ap-shanghai"
77
}
8+
9+
variable "availability_zone" {
10+
default = "ap-guangzhou-3"
11+
}

examples/tencentcloud-vpn/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,17 @@ data "tencentcloud_vpn_gateways" "example" {
6363
data "tencentcloud_vpn_connections" "example" {
6464
id = tencentcloud_vpn_connection.example.id
6565
}
66+
67+
# The example below shows how to create a vpng gateway in ccn type if it is needed. Then could be used when creating
68+
# vpn tunnel in the usual way.
69+
resource tencentcloud_vpn_gateway ccn_vpngw_example {
70+
name = "ccn-vpngw-example"
71+
vpc_id = ""
72+
bandwidth = 5
73+
zone = var.availability_zone
74+
type = "CCN"
75+
76+
tags = {
77+
test = "ccn-vpngw-example"
78+
}
79+
}

tencentcloud/data_source_tc_ccn_instances.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func dataSourceTencentCloudCcnInstances() *schema.Resource {
9393
"instance_type": {
9494
Type: schema.TypeString,
9595
Computed: true,
96-
Description: "Type of attached instance network, and available values include VPC, DIRECTCONNECT and BMVPC.",
96+
Description: "Type of attached instance network, and available values include VPC, DIRECTCONNECT, BMVPC and VPNGW.",
9797
},
9898
"instance_region": {
9999
Type: schema.TypeString,

tencentcloud/data_source_tc_vpn_gateways.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func dataSourceTencentCloudVpnGateways() *schema.Resource {
107107
"type": {
108108
Type: schema.TypeString,
109109
Computed: true,
110-
Description: "Type of gateway instance, valid values are `IPSEC`, `SSL`.",
110+
Description: "Type of gateway instance, valid values are `IPSEC`, `SSL` and `CCN`.",
111111
},
112112
"state": {
113113
Type: schema.TypeString,

tencentcloud/extension_cnn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ const CNN_QOS_AG = "AG"
77
const CNN_INSTANCE_TYPE_VPC = "VPC"
88
const CNN_INSTANCE_TYPE_DIRECTCONNECT = "DIRECTCONNECT"
99
const CNN_INSTANCE_TYPE_BMVPC = "BMVPC"
10+
const CNN_INSTANCE_TYPE_VPNGW = "VPNGW"

tencentcloud/resource_tc_ccn_attachment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ func resourceTencentCloudCcnAttachment() *schema.Resource {
7373
"instance_type": {
7474
Type: schema.TypeString,
7575
Required: true,
76-
ValidateFunc: validateAllowedStringValue([]string{CNN_INSTANCE_TYPE_VPC, CNN_INSTANCE_TYPE_DIRECTCONNECT, CNN_INSTANCE_TYPE_BMVPC}),
76+
ValidateFunc: validateAllowedStringValue([]string{CNN_INSTANCE_TYPE_VPC, CNN_INSTANCE_TYPE_DIRECTCONNECT, CNN_INSTANCE_TYPE_BMVPC, CNN_INSTANCE_TYPE_VPNGW}),
7777
ForceNew: true,
78-
Description: "Type of attached instance network, and available values include VPC, DIRECTCONNECT and BMVPC.",
78+
Description: "Type of attached instance network, and available values include VPC, DIRECTCONNECT, BMVPC and VPNGW. Note: VPNGW type is only for whitelist customer now.",
7979
},
8080
"instance_region": {
8181
Type: schema.TypeString,

tencentcloud/resource_tc_ccn_attachment_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
func TestAccTencentCloudCcnV3AttachmentBasic(t *testing.T) {
1414
keyName := "tencentcloud_ccn_attachment.attachment"
15+
keyNameVpngw := "tencentcloud_ccn_attachment.vpngw_ccn_attachment"
1516
resource.Test(t, resource.TestCase{
1617
PreCheck: func() { testAccPreCheck(t) },
1718
Providers: testAccProviders,
@@ -30,6 +31,19 @@ func TestAccTencentCloudCcnV3AttachmentBasic(t *testing.T) {
3031
resource.TestCheckResourceAttrSet(keyName, "cidr_block.#"),
3132
),
3233
},
34+
{
35+
Config: testAccCcnAttachmentVpngwConfig,
36+
Check: resource.ComposeTestCheckFunc(
37+
testAccCheckCcnAttachmentExists(keyNameVpngw),
38+
resource.TestCheckResourceAttrSet(keyNameVpngw, "ccn_id"),
39+
resource.TestCheckResourceAttrSet(keyNameVpngw, "instance_type"),
40+
resource.TestCheckResourceAttrSet(keyNameVpngw, "instance_region"),
41+
resource.TestCheckResourceAttrSet(keyNameVpngw, "instance_id"),
42+
resource.TestCheckResourceAttrSet(keyNameVpngw, "state"),
43+
resource.TestCheckResourceAttrSet(keyNameVpngw, "attached_time"),
44+
resource.TestCheckResourceAttrSet(keyNameVpngw, "cidr_block.#"),
45+
),
46+
},
3347
},
3448
})
3549
}
@@ -113,3 +127,34 @@ resource tencentcloud_ccn_attachment attachment {
113127
instance_region = var.region
114128
}
115129
`
130+
131+
const testAccCcnAttachmentVpngwConfig = `
132+
variable "region" {
133+
default = "ap-guangzhou"
134+
}
135+
136+
resource tencentcloud_vpn_gateway ccn_vpngw {
137+
name = "ci-temp-ccn-vpngw"
138+
vpc_id = ""
139+
bandwidth = 5
140+
zone = "ap-guangzhou-3"
141+
type = "CCN"
142+
143+
tags = {
144+
test = "ccn-vpngw-test"
145+
}
146+
}
147+
148+
resource tencentcloud_ccn vpngw_ccn_main {
149+
name = "ci-temp-test-vpngw-ccn"
150+
description = "ci-temp-test-vpngw-ccn-des"
151+
qos = "AG"
152+
}
153+
154+
resource tencentcloud_ccn_attachment vpngw_ccn_attachment {
155+
ccn_id = tencentcloud_ccn.vpngw_ccn_main.id
156+
instance_type = "VPNGW"
157+
instance_id = tencentcloud_vpn_gateway.ccn_vpngw.id
158+
instance_region = var.region
159+
}
160+
`

tencentcloud/resource_tc_vpn_gateway.go

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ func resourceTencentCloudVpnGateway() *schema.Resource {
9696
"type": {
9797
Type: schema.TypeString,
9898
Computed: true,
99-
Description: "Type of gateway instance, valid values are `IPSEC`, `SSL`.",
99+
Optional: true,
100+
Description: "Type of gateway instance, valid values are `IPSEC`, `SSL` and `CCN`.",
100101
},
101102
"state": {
102103
Type: schema.TypeString,
@@ -184,6 +185,9 @@ func resourceTencentCloudVpnGatewayCreate(d *schema.ResourceData, meta interface
184185
request.InstanceChargePrepaid = &preChargePara
185186
}
186187
request.InstanceChargeType = &chargeType
188+
if v, ok := d.GetOk("type"); ok {
189+
request.Type = helper.String(v.(string))
190+
}
187191
var response *vpc.CreateVpnGatewayResponse
188192
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
189193
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().CreateVpnGateway(request)
@@ -290,19 +294,19 @@ func resourceTencentCloudVpnGatewayRead(d *schema.ResourceData, meta interface{}
290294

291295
gateway := response.Response.VpnGatewaySet[0]
292296

293-
_ = d.Set("name", *gateway.VpnGatewayName)
294-
_ = d.Set("public_ip_address", *gateway.PublicIpAddress)
297+
_ = d.Set("name", gateway.VpnGatewayName)
298+
_ = d.Set("public_ip_address", gateway.PublicIpAddress)
295299
_ = d.Set("bandwidth", int(*gateway.InternetMaxBandwidthOut))
296-
_ = d.Set("type", *gateway.Type)
297-
_ = d.Set("create_time", *gateway.CreatedTime)
298-
_ = d.Set("state", *gateway.State)
299-
_ = d.Set("prepaid_renew_flag", *gateway.RenewFlag)
300-
_ = d.Set("charge_type", *gateway.InstanceChargeType)
301-
_ = d.Set("expired_time", *gateway.ExpiredTime)
302-
_ = d.Set("is_address_blocked", *gateway.IsAddressBlocked)
303-
_ = d.Set("new_purchase_plan", *gateway.NewPurchasePlan)
304-
_ = d.Set("restrict_state", *gateway.RestrictState)
305-
_ = d.Set("zone", *gateway.Zone)
300+
_ = d.Set("type", gateway.Type)
301+
_ = d.Set("create_time", gateway.CreatedTime)
302+
_ = d.Set("state", gateway.State)
303+
_ = d.Set("prepaid_renew_flag", gateway.RenewFlag)
304+
_ = d.Set("charge_type", gateway.InstanceChargeType)
305+
_ = d.Set("expired_time", gateway.ExpiredTime)
306+
_ = d.Set("is_address_blocked", gateway.IsAddressBlocked)
307+
_ = d.Set("new_purchase_plan", gateway.NewPurchasePlan)
308+
_ = d.Set("restrict_state", gateway.RestrictState)
309+
_ = d.Set("zone", gateway.Zone)
306310

307311
//tags
308312
tagService := TagService{client: meta.(*TencentCloudClient).apiV3Conn}
@@ -325,9 +329,15 @@ func resourceTencentCloudVpnGatewayUpdate(d *schema.ResourceData, meta interface
325329
d.Partial(true)
326330
gatewayId := d.Id()
327331

328-
//renew
329-
if d.HasChange("prepaid_period") || d.HasChange("prepaid_renew_flag") {
330-
return fmt.Errorf("Do not support renew operation in update operation. Please renew the instance on controller web page.")
332+
unsupportedUpdateFields := []string{
333+
"prepaid_period",
334+
"prepaid_renew_flag",
335+
"type",
336+
}
337+
for _, field := range unsupportedUpdateFields {
338+
if d.HasChange(field) {
339+
return fmt.Errorf("Template resource_tc_vpn_gateway update on %s is not supportted yet. Please renew it on controller web page.", field)
340+
}
331341
}
332342

333343
if d.HasChange("name") || d.HasChange("charge_type") {
@@ -416,13 +426,14 @@ func resourceTencentCloudVpnGatewayDelete(d *schema.ResourceData, meta interface
416426

417427
gatewayId := d.Id()
418428

419-
//prepaid instances can not be deleted
429+
//prepaid instances or instances which attached to ccn can not be deleted
420430
//to get expire_time of the VPN gateway
421431
//to get the status of gateway
422-
chargeRequest := vpc.NewDescribeVpnGatewaysRequest()
423-
chargeRequest.VpnGatewayIds = []*string{&gatewayId}
424-
chargeErr := resource.Retry(readRetryTimeout, func() *resource.RetryError {
425-
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().DescribeVpnGateways(chargeRequest)
432+
//to get the type and networkinstanceid of gateway
433+
vpngwRequest := vpc.NewDescribeVpnGatewaysRequest()
434+
vpngwRequest.VpnGatewayIds = []*string{&gatewayId}
435+
vpngwErr := resource.Retry(readRetryTimeout, func() *resource.RetryError {
436+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().DescribeVpnGateways(vpngwRequest)
426437
if e != nil {
427438
return retryError(e)
428439
} else {
@@ -440,16 +451,17 @@ func resourceTencentCloudVpnGatewayDelete(d *schema.ResourceData, meta interface
440451
if time.Until(t) > 0 {
441452
return resource.NonRetryableError(fmt.Errorf("Delete operation is unsupport when VPN gateway is not expired."))
442453
}
443-
return nil
444454
}
445-
return nil
455+
}
456+
if *result.Response.VpnGatewaySet[0].Type == GATE_WAY_TYPE_CCN && *result.Response.VpnGatewaySet[0].NetworkInstanceId != "" {
457+
return resource.NonRetryableError(fmt.Errorf("Delete operation is unsupported when VPN gateway is attached to CCN instance."))
446458
}
447459
return nil
448460
}
449461
})
450-
if chargeErr != nil {
451-
log.Printf("[CRITAL]%s describe VPN gateway failed, reason:%s\n", logId, chargeErr.Error())
452-
return chargeErr
462+
if vpngwErr != nil {
463+
log.Printf("[CRITAL]%s describe VPN gateway failed, reason:%s\n", logId, vpngwErr.Error())
464+
return vpngwErr
453465
}
454466

455467
//check the vpn gateway is not related with any tunnel

tencentcloud/resource_tc_vpn_gateway_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ func TestAccTencentCloudVpnGateway_basic(t *testing.T) {
3939
resource.TestCheckResourceAttrSet("tencentcloud_vpn_gateway.my_cgw", "state"),
4040
),
4141
},
42+
{
43+
Config: testAccCcnVpnGatewayConfig,
44+
Check: resource.ComposeTestCheckFunc(
45+
testAccCheckVpnGatewayExists("tencentcloud_vpn_gateway.my_ccn_cgw"),
46+
resource.TestCheckResourceAttr("tencentcloud_vpn_gateway.my_ccn_cgw", "name", "terraform_ccn_vpngw_test"),
47+
resource.TestCheckResourceAttr("tencentcloud_vpn_gateway.my_ccn_cgw", "bandwidth", "5"),
48+
resource.TestCheckResourceAttr("tencentcloud_vpn_gateway.my_ccn_cgw", "charge_type", "POSTPAID_BY_HOUR"),
49+
resource.TestCheckResourceAttr("tencentcloud_vpn_gateway.my_ccn_cgw", "tags.test", "tf-ccn-vpngw"),
50+
resource.TestCheckResourceAttrSet("tencentcloud_vpn_gateway.my_ccn_cgw", "state"),
51+
),
52+
},
4253
},
4354
})
4455
}
@@ -163,5 +174,19 @@ resource "tencentcloud_vpn_gateway" "my_cgw" {
163174
test = "test"
164175
}
165176
}
177+
`
166178

179+
const testAccCcnVpnGatewayConfig = `
180+
# Create VPNGW of CCN type
181+
resource "tencentcloud_vpn_gateway" "my_ccn_cgw" {
182+
name = "terraform_ccn_vpngw_test"
183+
bandwidth = 5
184+
zone = "ap-guangzhou-3"
185+
vpc_id = ""
186+
type = "CCN"
187+
188+
tags = {
189+
test = "tf-ccn-vpngw"
190+
}
191+
}
167192
`

website/docs/d/ccn_instances.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ In addition to all arguments above, the following attributes are exported:
4646
* `cidr_block` - A network address block of the instance that is attached.
4747
* `instance_id` - ID of instance is attached.
4848
* `instance_region` - The region that the instance locates at.
49-
* `instance_type` - Type of attached instance network, and available values include VPC, DIRECTCONNECT and BMVPC.
49+
* `instance_type` - Type of attached instance network, and available values include VPC, DIRECTCONNECT, BMVPC and VPNGW.
5050
* `state` - States of instance is attached, and available values include PENDING, ACTIVE, EXPIRED, REJECTED, DELETED, FAILED(asynchronous forced disassociation after 2 hours), ATTACHING, DETACHING and DETACHFAILED(asynchronous forced disassociation after 2 hours).
5151
* `ccn_id` - ID of the CCN.
5252
* `create_time` - Creation time of resource.

website/docs/d/vpn_gateways.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ In addition to all arguments above, the following attributes are exported:
5555
* `restrict_state` - Restrict state of VPN gateway, valid values are `PRETECIVELY_ISOLATED`, `NORMAL`.
5656
* `state` - State of the VPN gateway, valid values are `PENDING`, `DELETING`, `AVAILABLE`.
5757
* `tags` - A list of tags used to associate different resources.
58-
* `type` - Type of gateway instance, valid values are `IPSEC`, `SSL`.
58+
* `type` - Type of gateway instance, valid values are `IPSEC`, `SSL` and `CCN`.
5959
* `vpc_id` - ID of the VPC.
6060
* `zone` - Zone of the VPN gateway.
6161

website/docs/r/ccn_attachment.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The following arguments are supported:
6161
* `ccn_id` - (Required, ForceNew) ID of the CCN.
6262
* `instance_id` - (Required, ForceNew) ID of instance is attached.
6363
* `instance_region` - (Required, ForceNew) The region that the instance locates at.
64-
* `instance_type` - (Required, ForceNew) Type of attached instance network, and available values include VPC, DIRECTCONNECT and BMVPC.
64+
* `instance_type` - (Required, ForceNew) Type of attached instance network, and available values include VPC, DIRECTCONNECT, BMVPC and VPNGW. Note: VPNGW type is only for whitelist customer now.
6565
* `ccn_uin` - (Optional, ForceNew) Uin of the ccn attached. Default is ``, which means the uin of this account. This parameter is used with case when attaching ccn of other account to the instance of this account. For now only support instance type `VPC`.
6666

6767
## Attributes Reference

website/docs/r/vpn_gateway.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ The following arguments are supported:
5858
* `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.
5959
* `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.
6060
* `tags` - (Optional) A list of tags used to associate different resources.
61+
* `type` - (Optional) Type of gateway instance, valid values are `IPSEC`, `SSL` and `CCN`.
6162

6263
## Attributes Reference
6364

@@ -71,7 +72,6 @@ In addition to all arguments above, the following attributes are exported:
7172
* `public_ip_address` - Public ip of the VPN gateway.
7273
* `restrict_state` - Restrict state of gateway, valid values are `PRETECIVELY_ISOLATED`, `NORMAL`.
7374
* `state` - State of the VPN gateway, valid values are `PENDING`, `DELETING`, `AVAILABLE`.
74-
* `type` - Type of gateway instance, valid values are `IPSEC`, `SSL`.
7575

7676

7777
## Import

0 commit comments

Comments
 (0)