Skip to content

Commit 4ef8058

Browse files
committed
vpnngw support update prepaid period
1 parent 8d4f516 commit 4ef8058

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

tencentcloud/resource_tc_vpn_gateway.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func resourceTencentCloudVpnGateway() *schema.Resource {
120120
Optional: true,
121121
Default: 1,
122122
ValidateFunc: validateAllowedIntValue([]int{1, 2, 3, 4, 6, 7, 8, 9, 12, 24, 36}),
123-
Description: "Period of instance to be prepaid. Valid value: `1`, `2`, `3`, `4`, `6`, `7`, `8`, `9`, `12`, `24`, `36`. The 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.",
123+
Description: "Period of instance to be prepaid. Valid value: `1`, `2`, `3`, `4`, `6`, `7`, `8`, `9`, `12`, `24`, `36`. The 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 changed on `IPSEC` vpn gateway.",
124124
},
125125
"charge_type": {
126126
Type: schema.TypeString,
@@ -351,7 +351,6 @@ func resourceTencentCloudVpnGatewayUpdate(d *schema.ResourceData, meta interface
351351
gatewayId := d.Id()
352352

353353
unsupportedUpdateFields := []string{
354-
"prepaid_period",
355354
"type",
356355
}
357356
for _, field := range unsupportedUpdateFields {
@@ -360,6 +359,33 @@ func resourceTencentCloudVpnGatewayUpdate(d *schema.ResourceData, meta interface
360359
}
361360
}
362361

362+
if d.HasChange("prepaid_period") {
363+
chargeType := d.Get("charge_type").(string)
364+
period := d.Get("prepaid_period").(int)
365+
if chargeType != VPN_CHARGE_TYPE_PREPAID {
366+
return fmt.Errorf("Invalid renew flag change. Only support pre-paid vpn.")
367+
}
368+
request := vpc.NewRenewVpnGatewayRequest()
369+
request.VpnGatewayId = &gatewayId
370+
var preChargePara vpc.InstanceChargePrepaid
371+
preChargePara.Period = helper.IntUint64(period)
372+
request.InstanceChargePrepaid = &preChargePara
373+
374+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
375+
_, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().RenewVpnGateway(request)
376+
if e != nil {
377+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
378+
logId, request.GetAction(), request.ToJsonString(), e.Error())
379+
return retryError(e)
380+
}
381+
return nil
382+
})
383+
if err != nil {
384+
log.Printf("[CRITAL]%s modify VPN gateway prepaid period failed, reason:%s\n", logId, err.Error())
385+
return err
386+
}
387+
}
388+
363389
if d.HasChange("prepaid_renew_flag") {
364390
chargeType := d.Get("charge_type").(string)
365391
renewFlag := d.Get("prepaid_renew_flag").(string)

website/docs/r/vpn_gateway.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ The following arguments are supported:
5757
* `cdc_id` - (Optional, String) CDC instance ID.
5858
* `charge_type` - (Optional, String) Charge Type of the VPN gateway. Valid value: `PREPAID`, `POSTPAID_BY_HOUR`. The default is `POSTPAID_BY_HOUR`.
5959
* `max_connection` - (Optional, Int) Maximum number of connected clients allowed for the SSL VPN gateway. Valid values: [5, 10, 20, 50, 100]. This parameter is only required for SSL VPN gateways.
60-
* `prepaid_period` - (Optional, Int) Period of instance to be prepaid. Valid value: `1`, `2`, `3`, `4`, `6`, `7`, `8`, `9`, `12`, `24`, `36`. The 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.
60+
* `prepaid_period` - (Optional, Int) Period of instance to be prepaid. Valid value: `1`, `2`, `3`, `4`, `6`, `7`, `8`, `9`, `12`, `24`, `36`. The 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 changed on `IPSEC` vpn gateway.
6161
* `prepaid_renew_flag` - (Optional, String) Flag indicates whether to renew or not. Valid value: `NOTIFY_AND_AUTO_RENEW`, `NOTIFY_AND_MANUAL_RENEW`.
6262
* `tags` - (Optional, Map) A list of tags used to associate different resources.
6363
* `type` - (Optional, String) Type of gateway instance. Valid value: `IPSEC`, `SSL` and `CCN`. Note: CCN type is only for whitelist customer now.

0 commit comments

Comments
 (0)