Skip to content

Commit c878630

Browse files
tongyimingmikatong
andauthored
Fix/vpn connection healthcheck (#1110)
* vpn connection support healthcheck * update vpn connection doc Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 079630d commit c878630

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

tencentcloud/resource_tc_vpn_connection.go

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,24 @@ func resourceTencentCloudVpnConnection() *schema.Resource {
279279
Computed: true,
280280
Description: "Net status of the VPN connection. Valid value: `AVAILABLE`.",
281281
},
282+
"enable_health_check": {
283+
Type: schema.TypeBool,
284+
Optional: true,
285+
Computed: true,
286+
Description: "Whether intra-tunnel health checks are supported.",
287+
},
288+
"health_check_local_ip": {
289+
Type: schema.TypeString,
290+
Optional: true,
291+
Computed: true,
292+
Description: "Health check the address of this terminal.",
293+
},
294+
"health_check_remote_ip": {
295+
Type: schema.TypeString,
296+
Optional: true,
297+
Computed: true,
298+
Description: "Health check peer address.",
299+
},
282300
},
283301
}
284302
}
@@ -394,7 +412,15 @@ func resourceTencentCloudVpnConnectionCreate(d *schema.ResourceData, meta interf
394412
ipsecSaLifetimeTraffic64 := uint64(ipsecSaLifetimeTraffic)
395413
ipsecOptionsSpecification.IPSECSaLifetimeTraffic = &ipsecSaLifetimeTraffic64
396414
request.IPSECOptionsSpecification = &ipsecOptionsSpecification
397-
415+
if v, ok := d.GetOk("enable_health_check"); ok {
416+
request.EnableHealthCheck = helper.Bool(v.(bool))
417+
}
418+
if v, ok := d.GetOk("health_check_local_ip"); ok {
419+
request.HealthCheckLocalIp = helper.String(v.(string))
420+
}
421+
if v, ok := d.GetOk("health_check_remote_ip"); ok {
422+
request.HealthCheckRemoteIp = helper.String(v.(string))
423+
}
398424
var response *vpc.CreateVpnConnectionResponse
399425
err = resource.Retry(readRetryTimeout, func() *resource.RetryError {
400426
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().CreateVpnConnection(request)
@@ -609,7 +635,9 @@ func resourceTencentCloudVpnConnectionRead(d *schema.ResourceData, meta interfac
609635
_ = d.Set("vpn_proto", *connection.VpnProto)
610636
_ = d.Set("encrypt_proto", *connection.EncryptProto)
611637
_ = d.Set("route_type", *connection.RouteType)
612-
638+
_ = d.Set("enable_health_check", *connection.EnableHealthCheck)
639+
_ = d.Set("health_check_local_ip", *connection.HealthCheckLocalIp)
640+
_ = d.Set("health_check_remote_ip", *connection.HealthCheckRemoteIp)
613641
//tags
614642
tagService := TagService{client: meta.(*TencentCloudClient).apiV3Conn}
615643
region := meta.(*TencentCloudClient).apiV3Conn.Region
@@ -641,6 +669,19 @@ func resourceTencentCloudVpnConnectionUpdate(d *schema.ResourceData, meta interf
641669
request.PreShareKey = helper.String(d.Get("pre_share_key").(string))
642670
changeFlag = true
643671
}
672+
//healthcheck
673+
if d.HasChange("enable_health_check") {
674+
request.EnableHealthCheck = helper.Bool(d.Get("enable_health_check").(bool))
675+
changeFlag = true
676+
}
677+
if d.HasChange("health_check_local_ip") {
678+
request.HealthCheckLocalIp = helper.String(d.Get("health_check_local_ip").(string))
679+
changeFlag = true
680+
}
681+
if d.HasChange("health_check_remote_ip") {
682+
request.HealthCheckRemoteIp = helper.String(d.Get("health_check_remote_ip").(string))
683+
changeFlag = true
684+
}
644685

645686
//set up SecurityPolicyDatabases
646687
if d.HasChange("security_group_policy") {
@@ -780,6 +821,15 @@ func resourceTencentCloudVpnConnectionUpdate(d *schema.ResourceData, meta interf
780821
if d.HasChange("security_group_policy") {
781822
d.SetPartial("security_group_policy")
782823
}
824+
if d.HasChange("enable_health_check") {
825+
d.SetPartial("enable_health_check")
826+
}
827+
if d.HasChange("health_check_local_ip") {
828+
d.SetPartial("health_check_local_ip")
829+
}
830+
if d.HasChange("health_check_remote_ip") {
831+
d.SetPartial("health_check_remote_ip")
832+
}
783833

784834
for key := range ikeChangeKeySet {
785835
if ikeChangeKeySet[key] {

tencentcloud/resource_tc_vpn_connection_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ func TestAccTencentCloudVpnConnection_basic(t *testing.T) {
4343
resource.TestCheckResourceAttrSet("tencentcloud_vpn_connection.connection", "encrypt_proto"),
4444
resource.TestCheckResourceAttrSet("tencentcloud_vpn_connection.connection", "route_type"),
4545
resource.TestCheckResourceAttrSet("tencentcloud_vpn_connection.connection", "vpn_proto"),
46+
resource.TestCheckResourceAttr("tencentcloud_vpn_connection.connection", "enable_health_check", "true"),
47+
resource.TestCheckResourceAttr("tencentcloud_vpn_connection.connection", "health_check_local_ip", "192.168.0.2"),
48+
resource.TestCheckResourceAttr("tencentcloud_vpn_connection.connection", "health_check_remote_ip", "3.3.3.2"),
4649
),
4750
},
4851
{
@@ -70,6 +73,7 @@ func TestAccTencentCloudVpnConnection_basic(t *testing.T) {
7073
resource.TestCheckResourceAttrSet("tencentcloud_vpn_connection.connection", "encrypt_proto"),
7174
resource.TestCheckResourceAttrSet("tencentcloud_vpn_connection.connection", "route_type"),
7275
resource.TestCheckResourceAttrSet("tencentcloud_vpn_connection.connection", "vpn_proto"),
76+
resource.TestCheckResourceAttr("tencentcloud_vpn_connection.connection", "enable_health_check", "false"),
7377
),
7478
},
7579
},
@@ -213,6 +217,9 @@ resource "tencentcloud_vpn_connection" "connection" {
213217
tags = {
214218
test = "test"
215219
}
220+
enable_health_check = true
221+
health_check_local_ip = "192.168.0.2"
222+
health_check_remote_ip = "3.3.3.2"
216223
}
217224
`
218225

@@ -265,5 +272,6 @@ resource "tencentcloud_vpn_connection" "connection" {
265272
tags = {
266273
test = "testt"
267274
}
275+
enable_health_check = false
268276
}
269277
`

website/docs/r/vpn_connection.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ The following arguments are supported:
5454
* `pre_share_key` - (Required) Pre-shared key of the VPN connection.
5555
* `security_group_policy` - (Required) Security group policy of the VPN connection.
5656
* `vpn_gateway_id` - (Required, ForceNew) ID of the VPN gateway.
57+
* `enable_health_check` - (Optional) Whether intra-tunnel health checks are supported.
58+
* `health_check_local_ip` - (Optional) Health check the address of this terminal.
59+
* `health_check_remote_ip` - (Optional) Health check peer address.
5760
* `ike_dh_group_name` - (Optional) DH group name of the IKE operation specification. Valid values: `GROUP1`, `GROUP2`, `GROUP5`, `GROUP14`, `GROUP24`. Default value is `GROUP1`.
5861
* `ike_exchange_mode` - (Optional) Exchange mode of the IKE operation specification. Valid values: `AGGRESSIVE`, `MAIN`. Default value is `MAIN`.
5962
* `ike_local_address` - (Optional) Local address of IKE operation specification, valid when ike_local_identity is `ADDRESS`, generally the value is `public_ip_address` of the related VPN gateway.

0 commit comments

Comments
 (0)