Skip to content

Commit 0070a6a

Browse files
authored
Fix bugs that cos unsupported logging regions (#584)
1 parent cf3b1bf commit 0070a6a

File tree

7 files changed

+90
-37
lines changed

7 files changed

+90
-37
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
## 1.53.2 (Unreleased)
2+
3+
ENHANCEMENTS:
4+
5+
* Resource `tencentcloud_cbs_storage` add `throughput_performance` to support adding extra performance to the cbs resources.
6+
7+
BUG FIXES:
8+
9+
* Resource: `tencentcloud_cos_bucket` fix bug that error happens when applying unsupported logging region.
10+
* Resource: `tencentcloud_as_scaling_policy` fix bug that missing required parameters error happened when update metric parameters.
11+
12+
213
## 1.53.1 (January 23, 2021)
314

415
ENHANCEMENTS:

tencentcloud/resource_tc_as_scaling_policy.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,24 +223,17 @@ func resourceTencentCloudAsScalingPolicyUpdate(d *schema.ResourceData, meta inte
223223
request.AdjustmentValue = &adjustmentValue
224224
}
225225
request.MetricAlarm = &as.MetricAlarm{}
226-
if d.HasChange("comparison_operator") {
226+
if d.HasChange("comparison_operator") || d.HasChange("threshold") || d.HasChange("metric_name") || d.HasChange("period") ||
227+
d.HasChange("continuous_time") || d.HasChange("statistic") {
228+
//these two parameter must pass together
227229
request.MetricAlarm.ComparisonOperator = helper.String(d.Get("comparison_operator").(string))
228-
}
229-
if d.HasChange("metric_name") {
230-
request.MetricAlarm.MetricName = helper.String(d.Get("metric_name").(string))
231-
}
232-
if d.HasChange("threshold") {
233230
request.MetricAlarm.Threshold = helper.IntUint64(d.Get("threshold").(int))
234-
}
235-
if d.HasChange("period") {
231+
request.MetricAlarm.MetricName = helper.String(d.Get("metric_name").(string))
236232
request.MetricAlarm.Period = helper.IntUint64(d.Get("period").(int))
237-
}
238-
if d.HasChange("continuous_time") {
239233
request.MetricAlarm.ContinuousTime = helper.IntUint64(d.Get("continuous_time").(int))
240-
}
241-
if d.HasChange("statistic") {
242234
request.MetricAlarm.Statistic = helper.String(d.Get("statistic").(string))
243235
}
236+
244237
if d.HasChange("cooldown") {
245238
request.Cooldown = helper.IntUint64(d.Get("cooldown").(int))
246239
}

tencentcloud/resource_tc_cbs_storage.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ func resourceTencentCloudCbsStorage() *schema.Resource {
5151

5252
Schema: map[string]*schema.Schema{
5353
"storage_type": {
54-
Type: schema.TypeString,
55-
Required: true,
56-
ForceNew: true,
57-
ValidateFunc: validateAllowedStringValue(CBS_STORAGE_TYPE),
58-
Description: "Type of CBS medium. Valid values: CLOUD_BASIC, CLOUD_PREMIUM and CLOUD_SSD.",
54+
Type: schema.TypeString,
55+
Required: true,
56+
ForceNew: true,
57+
Description: "Type of CBS medium. Valid values: CLOUD_BASIC, CLOUD_PREMIUM, CLOUD_SSD, CLOUD_TSSD and CLOUD_HSSD.",
5958
},
6059
"storage_size": {
6160
Type: schema.TypeInt,
@@ -132,7 +131,12 @@ func resourceTencentCloudCbsStorage() *schema.Resource {
132131
Default: false,
133132
Description: "Indicate whether to delete CBS instance directly or not. Default is false. If set true, the instance will be deleted instead of staying recycle bin.",
134133
},
135-
134+
"throughput_performance": {
135+
Type: schema.TypeInt,
136+
Optional: true,
137+
Default: 0,
138+
Description: "Add extra performance to the data disk. Only works when disk type is `CLOUD_TSSD` or `CLOUD_HSSD`.",
139+
},
136140
// computed
137141
"storage_status": {
138142
Type: schema.TypeString,
@@ -173,7 +177,13 @@ func resourceTencentCloudCbsStorageCreate(d *schema.ResourceData, meta interface
173177
if _, ok := d.GetOk("encrypt"); ok {
174178
request.Encrypt = helper.String("ENCRYPT")
175179
}
180+
181+
if v, ok := d.GetOk("throughput_performance"); ok {
182+
request.ThroughputPerformance = helper.IntUint64(v.(int))
183+
}
184+
176185
chargeType := d.Get("charge_type").(string)
186+
177187
request.DiskChargeType = &chargeType
178188

179189
if chargeType == CBS_CHARGE_TYPE_PREPAID {
@@ -279,6 +289,7 @@ func resourceTencentCloudCbsStorageRead(d *schema.ResourceData, meta interface{}
279289
_ = d.Set("attached", storage.Attached)
280290
_ = d.Set("charge_type", storage.DiskChargeType)
281291
_ = d.Set("prepaid_renew_flag", storage.RenewFlag)
292+
_ = d.Set("throughput_performance", storage.ThroughputPerformance)
282293

283294
if *storage.DiskChargeType == CBS_CHARGE_TYPE_PREPAID {
284295
_ = d.Set("prepaid_renew_flag", storage.RenewFlag)
@@ -420,6 +431,23 @@ func resourceTencentCloudCbsStorageUpdate(d *schema.ResourceData, meta interface
420431
d.SetPartial("snapshot_id")
421432
}
422433

434+
if d.HasChange("throughput_performance") {
435+
throughputPerformance := d.Get("throughput_performance").(int)
436+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
437+
e := cbsService.ModifyThroughputPerformance(ctx, storageId, throughputPerformance)
438+
if e != nil {
439+
return retryError(e)
440+
}
441+
return nil
442+
})
443+
if err != nil {
444+
log.Printf("[CRITAL]%s update cbs failed, reason:%s\n ", logId, err.Error())
445+
return err
446+
}
447+
448+
d.SetPartial("throughput_performance")
449+
}
450+
423451
if d.HasChange("tags") {
424452

425453
oldValue, newValue := d.GetChange("tags")

tencentcloud/resource_tc_cos_bucket.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ import (
122122
"github.com/aws/aws-sdk-go/service/s3"
123123
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
124124
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
125+
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
125126
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
126127
)
127128

@@ -438,11 +439,16 @@ func resourceTencentCloudCosBucketRead(d *schema.ResourceData, meta interface{})
438439
//read the log
439440
logEnable, logTargetBucket, logPrefix, err := cosService.GetBucketLogStatus(ctx, bucket)
440441
if err != nil {
441-
return err
442+
if e, ok := err.(*errors.TencentCloudSDKError); ok {
443+
if e.GetCode() != "UnSupportedLoggingRegion" {
444+
return err
445+
}
446+
}
447+
} else {
448+
_ = d.Set("log_enable", logEnable)
449+
_ = d.Set("log_target_bucket", logTargetBucket)
450+
_ = d.Set("log_prefix", logPrefix)
442451
}
443-
_ = d.Set("log_enable", logEnable)
444-
_ = d.Set("log_target_bucket", logTargetBucket)
445-
_ = d.Set("log_prefix", logPrefix)
446452

447453
// read the tags
448454
tags, err := cosService.GetBucketTags(ctx, bucket)

tencentcloud/resource_tc_gaap_proxy.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,21 @@ func resourceTencentCloudGaapProxy() *schema.Resource {
7171
Description: "Maximum bandwidth of the GAAP proxy, unit is Mbps. Valid value: `10`, `20`, `50`, `100`, `200`, `500` and `1000`.",
7272
},
7373
"concurrent": {
74-
Type: schema.TypeInt,
75-
Required: true,
76-
ValidateFunc: validateAllowedIntValue([]int{2, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}),
77-
Description: "Maximum concurrency of the GAAP proxy, unit is 10k. Valid value: `2`, `5`, `10`, `20`, `30`, `40`, `50`, `60`, `70`, `80`, `90` and `100`.",
74+
Type: schema.TypeInt,
75+
Required: true,
76+
Description: "Maximum concurrency of the GAAP proxy, unit is 10k. Valid value: `2`, `5`, `10`, `20`, `30`, `40`, `50`, `60`, `70`, `80`, `90` and `100`.",
7877
},
7978
"access_region": {
80-
Type: schema.TypeString,
81-
Required: true,
82-
ForceNew: true,
83-
ValidateFunc: validateAllowedStringValue([]string{"NorthChina", "EastChina", "SouthChina", "SouthwestChina", "Hongkong", "SL_TAIWAN", "SoutheastAsia", "Korea", "SL_India", "SL_Australia", "Europe", "SL_UK", "SL_SouthAmerica", "NorthAmerica", "SL_MiddleUSA", "Canada", "SL_VIET", "WestIndia", "Thailand", "Virginia", "Russia", "Japan", "SL_Indonesia"}),
84-
Description: "Access region of the GAAP proxy. Valid value: `NorthChina`, `EastChina`, `SouthChina`, `SouthwestChina`, `Hongkong`, `SL_TAIWAN`, `SoutheastAsia`, `Korea`, `SL_India`, `SL_Australia`, `Europe`, `SL_UK`, `SL_SouthAmerica`, `NorthAmerica`, `SL_MiddleUSA`, `Canada`, `SL_VIET`, `WestIndia`, `Thailand`, `Virginia`, `Russia`, `Japan` and `SL_Indonesia`.",
79+
Type: schema.TypeString,
80+
Required: true,
81+
ForceNew: true,
82+
Description: "Access region of the GAAP proxy. Valid value: `NorthChina`, `EastChina`, `SouthChina`, `SouthwestChina`, `Hongkong`, `SL_TAIWAN`, `SoutheastAsia`, `Korea`, `SL_India`, `SL_Australia`, `Europe`, `SL_UK`, `SL_SouthAmerica`, `NorthAmerica`, `SL_MiddleUSA`, `Canada`, `SL_VIET`, `WestIndia`, `Thailand`, `Virginia`, `Russia`, `Japan` and `SL_Indonesia`.",
8583
},
8684
"realserver_region": {
87-
Type: schema.TypeString,
88-
Required: true,
89-
ForceNew: true,
90-
ValidateFunc: validateAllowedStringValue([]string{"NorthChina", "EastChina", "SouthChina", "SouthwestChina", "Hongkong", "SL_TAIWAN", "SoutheastAsia", "Korea", "SL_India", "SL_Australia", "Europe", "SL_UK", "SL_SouthAmerica", "NorthAmerica", "SL_MiddleUSA", "Canada", "SL_VIET", "WestIndia", "Thailand", "Virginia", "Russia", "Japan", "SL_Indonesia"}),
91-
Description: "Region of the GAAP realserver. Valid value: `NorthChina`, `EastChina`, `SouthChina`, `SouthwestChina`, `Hongkong`, `SL_TAIWAN`, `SoutheastAsia`, `Korea`, `SL_India`, `SL_Australia`, `Europe`, `SL_UK`, `SL_SouthAmerica`, `NorthAmerica`, `SL_MiddleUSA`, `Canada`, `SL_VIET`, `WestIndia`, `Thailand`, `Virginia`, `Russia`, `Japan` and `SL_Indonesia`.",
85+
Type: schema.TypeString,
86+
Required: true,
87+
ForceNew: true,
88+
Description: "Region of the GAAP realserver. Valid value: `NorthChina`, `EastChina`, `SouthChina`, `SouthwestChina`, `Hongkong`, `SL_TAIWAN`, `SoutheastAsia`, `Korea`, `SL_India`, `SL_Australia`, `Europe`, `SL_UK`, `SL_SouthAmerica`, `NorthAmerica`, `SL_MiddleUSA`, `Canada`, `SL_VIET`, `WestIndia`, `Thailand`, `Virginia`, `Russia`, `Japan` and `SL_Indonesia`.",
9289
},
9390
"enable": {
9491
Type: schema.TypeBool,

tencentcloud/service_tencentcloud_cbs.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ func (me *CbsService) ResizeDisk(ctx context.Context, diskId string, diskSize in
135135
return nil
136136
}
137137

138+
func (me *CbsService) ModifyThroughputPerformance(ctx context.Context, diskId string, throughputPerformance int) error {
139+
logId := getLogId(ctx)
140+
request := cbs.NewModifyDiskExtraPerformanceRequest()
141+
request.DiskId = &diskId
142+
request.ThroughputPerformance = helper.IntUint64(throughputPerformance)
143+
ratelimit.Check(request.GetAction())
144+
response, err := me.client.UseCbsClient().ModifyDiskExtraPerformance(request)
145+
if err != nil {
146+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
147+
logId, request.GetAction(), request.ToJsonString(), err.Error())
148+
return err
149+
}
150+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
151+
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
152+
return nil
153+
}
154+
138155
func (me *CbsService) ApplySnapshot(ctx context.Context, diskId, snapshotId string) error {
139156
logId := getLogId(ctx)
140157
request := cbs.NewApplySnapshotRequest()

website/docs/r/cbs_storage.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The following arguments are supported:
3535
* `availability_zone` - (Required, ForceNew) The available zone that the CBS instance locates at.
3636
* `storage_name` - (Required) Name of CBS. The maximum length can not exceed 60 bytes.
3737
* `storage_size` - (Required) Volume of CBS, and unit is GB. If storage type is `CLOUD_SSD`, the size range is [100, 16000], and the others are [10-16000].
38-
* `storage_type` - (Required, ForceNew) Type of CBS medium. Valid values: CLOUD_BASIC, CLOUD_PREMIUM and CLOUD_SSD.
38+
* `storage_type` - (Required, ForceNew) Type of CBS medium. Valid values: CLOUD_BASIC, CLOUD_PREMIUM, CLOUD_SSD, CLOUD_TSSD and CLOUD_HSSD.
3939
* `charge_type` - (Optional) The charge type of CBS instance. Valid values are `PREPAID` and `POSTPAID_BY_HOUR`. The default is `POSTPAID_BY_HOUR`.
4040
* `encrypt` - (Optional, ForceNew) Indicates whether CBS is encrypted.
4141
* `force_delete` - (Optional) Indicate whether to delete CBS instance directly or not. Default is false. If set true, the instance will be deleted instead of staying recycle bin.
@@ -45,6 +45,7 @@ The following arguments are supported:
4545
* `project_id` - (Optional) ID of the project to which the instance belongs.
4646
* `snapshot_id` - (Optional) ID of the snapshot. If specified, created the CBS by this snapshot.
4747
* `tags` - (Optional) The available tags within this CBS.
48+
* `throughput_performance` - (Optional) Add extra performance to the data disk. Only works when disk type is `CLOUD_TSSD` or `CLOUD_HSSD`.
4849

4950
## Attributes Reference
5051

0 commit comments

Comments
 (0)