Skip to content

Commit 6864e9c

Browse files
authored
ccn bandwidth limit support delete (#2290)
* ccn bandwidth limit support delete * ccn bandwidth limit support delete * add changelog
1 parent ab7a91e commit 6864e9c

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

.changelog/2290.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
tencentcloud_ccn_bandwidth_limit: Support recover bandwidth limit when run `terraform destroy`
3+
```

tencentcloud/resource_tc_ccn_bandwidth_limit.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func resourceTencentCloudCcnBandwidthLimit() *schema.Resource {
8484
Type: schema.TypeInt,
8585
Optional: true,
8686
Computed: true,
87-
Description: "Limitation of bandwidth.",
87+
Description: "Limitation of bandwidth. Default is `0`.",
8888
},
8989
"dst_region": {
9090
Type: schema.TypeString,
@@ -128,7 +128,7 @@ func resourceTencentCloudCcnBandwidthLimitCreate(d *schema.ResourceData, meta in
128128
if v, ok := d.GetOk("bandwidth_limit"); ok {
129129
limit = int64(v.(int))
130130
}
131-
if err := service.SetCcnRegionBandwidthLimits(ctx, ccnId, region, dstRegion, limit); err != nil {
131+
if err := service.SetCcnRegionBandwidthLimits(ctx, ccnId, region, dstRegion, limit, false); err != nil {
132132
return err
133133
}
134134
d.SetId(id)
@@ -161,7 +161,7 @@ func resourceTencentCloudCcnBandwidthLimitUpdate(d *schema.ResourceData, meta in
161161
limitTemp = int64(v.(int))
162162
}
163163
_, dstRegion := d.GetChange("dst_region")
164-
if err := service.SetCcnRegionBandwidthLimits(ctx, ccnId, region, dstRegion.(string), limitTemp); err != nil {
164+
if err := service.SetCcnRegionBandwidthLimits(ctx, ccnId, region, dstRegion.(string), limitTemp, false); err != nil {
165165
return err
166166
}
167167
}
@@ -222,7 +222,26 @@ func resourceTencentCloudCcnBandwidthLimitRead(d *schema.ResourceData, meta inte
222222
func resourceTencentCloudCcnBandwidthLimitDelete(d *schema.ResourceData, meta interface{}) error {
223223
defer logElapsed("resource.tencentcloud_ccn_bandwidth_limit.delete")()
224224

225-
_, _ = d, meta
225+
var (
226+
ccnId = d.Get("ccn_id").(string)
227+
region = d.Get("region").(string)
228+
dstRegion string
229+
limit int64
230+
)
231+
232+
logId := getLogId(contextNil)
233+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
226234

235+
service := VpcService{client: meta.(*TencentCloudClient).apiV3Conn}
236+
237+
if v, ok := d.GetOk("dst_region"); ok {
238+
dstRegion = v.(string)
239+
}
240+
if v, ok := d.GetOk("bandwidth_limit"); ok {
241+
limit = int64(v.(int))
242+
}
243+
if err := service.SetCcnRegionBandwidthLimits(ctx, ccnId, region, dstRegion, limit, true); err != nil {
244+
return err
245+
}
227246
return nil
228247
}

tencentcloud/service_tencentcloud_ccn.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ func (me *VpcService) GetCcnRegionBandwidthLimits(ctx context.Context,
623623
}
624624

625625
func (me *VpcService) SetCcnRegionBandwidthLimits(ctx context.Context, ccnId, region, dstRegion string,
626-
bandwidth int64) (errRet error) {
626+
bandwidth int64, setFlag bool) (errRet error) {
627627

628628
logId := getLogId(ctx)
629629
request := vpc.NewSetCcnRegionBandwidthLimitsRequest()
@@ -638,6 +638,8 @@ func (me *VpcService) SetCcnRegionBandwidthLimits(ctx context.Context, ccnId, re
638638
}
639639

640640
request.CcnRegionBandwidthLimits = []*vpc.CcnRegionBandwidthLimit{&ccnRegionBandwidthLimit}
641+
642+
request.SetDefaultLimitFlag = helper.Bool(setFlag)
641643
ratelimit.Check(request.GetAction())
642644
response, err := me.client.UseVpcClient().SetCcnRegionBandwidthLimits(request)
643645

website/docs/r/ccn_bandwidth_limit.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The following arguments are supported:
6565

6666
* `ccn_id` - (Required, String, ForceNew) ID of the CCN.
6767
* `region` - (Required, String, ForceNew) Limitation of region.
68-
* `bandwidth_limit` - (Optional, Int) Limitation of bandwidth.
68+
* `bandwidth_limit` - (Optional, Int) Limitation of bandwidth. Default is `0`.
6969
* `dst_region` - (Optional, String, ForceNew) Destination area restriction. If the `CCN` rate limit type is `OUTER_REGION_LIMIT`, this value does not need to be set.
7070

7171
## Attributes Reference

0 commit comments

Comments
 (0)