@@ -35,56 +35,56 @@ func ResourceTencentCloudAsScalingPolicy() *schema.Resource {
3535 },
3636 "adjustment_type" : {
3737 Type : schema .TypeString ,
38- Required : true ,
38+ Optional : true ,
3939 ValidateFunc : tccommon .ValidateAllowedStringValue (SCALING_GROUP_ADJUSTMENT_TYPE ),
4040 Description : "Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values: `CHANGE_IN_CAPACITY`, `EXACT_CAPACITY` and `PERCENT_CHANGE_IN_CAPACITY`." ,
4141 },
4242 "adjustment_value" : {
4343 Type : schema .TypeInt ,
44- Required : true ,
44+ Optional : true ,
4545 Description : "Define the number of instances by which to scale.For `CHANGE_IN_CAPACITY` type or PERCENT_CHANGE_IN_CAPACITY, a positive increment adds to the current capacity and a negative value removes from the current capacity. For `EXACT_CAPACITY` type, it defines an absolute number of the existing Auto Scaling group size." ,
4646 },
4747 "comparison_operator" : {
4848 Type : schema .TypeString ,
49- Required : true ,
49+ Optional : true ,
5050 ValidateFunc : tccommon .ValidateAllowedStringValue (SCALING_GROUP_COMPARISON_OPERATOR ),
5151 Description : "Comparison operator. Valid values: `GREATER_THAN`, `GREATER_THAN_OR_EQUAL_TO`, `LESS_THAN`, `LESS_THAN_OR_EQUAL_TO`, `EQUAL_TO` and `NOT_EQUAL_TO`." ,
5252 },
5353 "metric_name" : {
5454 Type : schema .TypeString ,
55- Required : true ,
55+ Optional : true ,
5656 ValidateFunc : tccommon .ValidateAllowedStringValue (SCALING_GROUP_METRIC_NAME ),
5757 Description : "Name of an indicator. Valid values: `CPU_UTILIZATION`, `MEM_UTILIZATION`, `LAN_TRAFFIC_OUT`, `LAN_TRAFFIC_IN`, `WAN_TRAFFIC_OUT` and `WAN_TRAFFIC_IN`." ,
5858 },
5959 "threshold" : {
6060 Type : schema .TypeInt ,
61- Required : true ,
61+ Optional : true ,
6262 Description : "Alarm threshold." ,
6363 },
6464 "period" : {
6565 Type : schema .TypeInt ,
66- Required : true ,
66+ Optional : true ,
6767 ValidateFunc : tccommon .ValidateAllowedIntValue ([]int {60 , 300 }),
6868 Description : "Time period in second. Valid values: `60` and `300`." ,
6969 },
7070 "continuous_time" : {
7171 Type : schema .TypeInt ,
72- Required : true ,
72+ Optional : true ,
7373 ValidateFunc : tccommon .ValidateIntegerInRange (1 , 10 ),
7474 Description : "Retry times. Valid value ranges: (1~10)." ,
7575 },
7676 "statistic" : {
7777 Type : schema .TypeString ,
7878 Optional : true ,
79- Default : SCALING_GROUP_STATISTIC_AVERAGE ,
79+ Computed : true ,
8080 ValidateFunc : tccommon .ValidateAllowedStringValue (SCALING_GROUP_STATISTIC ),
8181 Description : "Statistic types. Valid values: `AVERAGE`, `MAXIMUM` and `MINIMUM`. Default is `AVERAGE`." ,
8282 },
8383 "cooldown" : {
8484 Type : schema .TypeInt ,
8585 Optional : true ,
86- Default : 300 ,
87- Description : "Cooldwon time in second. Default is `30`0 ." ,
86+ Computed : true ,
87+ Description : "Cooldwon time in second. Default is `300` ." ,
8888 },
8989 "notification_user_group_ids" : {
9090 Type : schema .TypeList ,
@@ -113,6 +113,7 @@ func ResourceTencentCloudAsScalingPolicy() *schema.Resource {
113113 "estimated_instance_warmup" : {
114114 Type : schema .TypeInt ,
115115 Optional : true ,
116+ Computed : true ,
116117 Description : "Instance warm-up time, in seconds, applicable only to target tracking strategies. Value range is 0-3600, with a default warm-up time of 300 seconds." ,
117118 },
118119 "disable_scale_in" : {
@@ -132,18 +133,40 @@ func resourceTencentCloudAsScalingPolicyCreate(d *schema.ResourceData, meta inte
132133 request := as .NewCreateScalingPolicyRequest ()
133134 request .AutoScalingGroupId = helper .String (d .Get ("scaling_group_id" ).(string ))
134135 request .ScalingPolicyName = helper .String (d .Get ("policy_name" ).(string ))
135- request .AdjustmentType = helper .String (d .Get ("adjustment_type" ).(string ))
136- adjustMentValue := int64 (d .Get ("adjustment_value" ).(int ))
137- request .AdjustmentValue = & adjustMentValue
138- request .MetricAlarm = & as.MetricAlarm {}
139- request .MetricAlarm .ComparisonOperator = helper .String (d .Get ("comparison_operator" ).(string ))
140- request .MetricAlarm .MetricName = helper .String (d .Get ("metric_name" ).(string ))
141- request .MetricAlarm .Threshold = helper .IntUint64 (d .Get ("threshold" ).(int ))
142- request .MetricAlarm .Period = helper .IntUint64 (d .Get ("period" ).(int ))
143- request .MetricAlarm .ContinuousTime = helper .IntUint64 (d .Get ("continuous_time" ).(int ))
144-
136+ if v , ok := d .GetOk ("adjustment_type" ); ok {
137+ request .AdjustmentType = helper .String (v .(string ))
138+ }
139+ if v , ok := d .GetOkExists ("adjustment_value" ); ok {
140+ request .AdjustmentValue = helper .IntInt64 (v .(int ))
141+ }
142+ metricAlarm := & as.MetricAlarm {}
143+ var hasMetricAlarm bool
144+ if v , ok := d .GetOk ("comparison_operator" ); ok {
145+ metricAlarm .ComparisonOperator = helper .String (v .(string ))
146+ hasMetricAlarm = true
147+ }
148+ if v , ok := d .GetOk ("metric_name" ); ok {
149+ metricAlarm .MetricName = helper .String (v .(string ))
150+ hasMetricAlarm = true
151+ }
152+ if v , ok := d .GetOkExists ("threshold" ); ok {
153+ metricAlarm .Threshold = helper .IntUint64 (v .(int ))
154+ hasMetricAlarm = true
155+ }
156+ if v , ok := d .GetOkExists ("period" ); ok {
157+ metricAlarm .Period = helper .IntUint64 (v .(int ))
158+ hasMetricAlarm = true
159+ }
160+ if v , ok := d .GetOkExists ("continuous_time" ); ok {
161+ metricAlarm .ContinuousTime = helper .IntUint64 (v .(int ))
162+ hasMetricAlarm = true
163+ }
145164 if v , ok := d .GetOk ("statistic" ); ok {
146- request .MetricAlarm .Statistic = helper .String (v .(string ))
165+ metricAlarm .Statistic = helper .String (v .(string ))
166+ hasMetricAlarm = true
167+ }
168+ if hasMetricAlarm {
169+ request .MetricAlarm = metricAlarm
147170 }
148171 if v , ok := d .GetOk ("cooldown" ); ok {
149172 request .Cooldown = helper .IntUint64 (v .(int ))
@@ -286,21 +309,43 @@ func resourceTencentCloudAsScalingPolicyUpdate(d *schema.ResourceData, meta inte
286309 request .ScalingPolicyName = helper .String (d .Get ("policy_name" ).(string ))
287310 }
288311 if d .HasChange ("adjustment_type" ) {
289- request .AdjustmentType = helper .String (d .Get ("adjustment_type" ).(string ))
312+ if v , ok := d .GetOk ("adjustment_type" ); ok {
313+ request .AdjustmentType = helper .String (v .(string ))
314+ }
290315 }
291316 if d .HasChange ("adjustment_value" ) {
292- adjustmentValue := int64 (d .Get ("adjustment_value" ).(int ))
293- request .AdjustmentValue = & adjustmentValue
294- }
295- request .MetricAlarm = & as.MetricAlarm {}
296-
297- //these two parameter must pass together
298- request .MetricAlarm .ComparisonOperator = helper .String (d .Get ("comparison_operator" ).(string ))
299- request .MetricAlarm .Threshold = helper .IntUint64 (d .Get ("threshold" ).(int ))
300- request .MetricAlarm .MetricName = helper .String (d .Get ("metric_name" ).(string ))
301- request .MetricAlarm .Period = helper .IntUint64 (d .Get ("period" ).(int ))
302- request .MetricAlarm .ContinuousTime = helper .IntUint64 (d .Get ("continuous_time" ).(int ))
303- request .MetricAlarm .Statistic = helper .String (d .Get ("statistic" ).(string ))
317+ if v , ok := d .GetOkExists ("adjustment_value" ); ok {
318+ request .AdjustmentValue = helper .IntInt64 (v .(int ))
319+ }
320+ }
321+
322+ if d .HasChange ("comparison_operator" ) || d .HasChange ("threshold" ) || d .HasChange ("metric_name" ) || d .HasChange ("period" ) || d .HasChange ("continuous_time" ) || d .HasChange ("statistic" ) {
323+ request .MetricAlarm = & as.MetricAlarm {}
324+
325+ if v , ok := d .GetOk ("comparison_operator" ); ok {
326+ request .MetricAlarm .ComparisonOperator = helper .String (v .(string ))
327+ }
328+
329+ if v , ok := d .GetOkExists ("threshold" ); ok {
330+ request .MetricAlarm .Threshold = helper .IntUint64 (v .(int ))
331+ }
332+
333+ if v , ok := d .GetOk ("metric_name" ); ok {
334+ request .MetricAlarm .MetricName = helper .String (v .(string ))
335+ }
336+
337+ if v , ok := d .GetOkExists ("period" ); ok {
338+ request .MetricAlarm .Period = helper .IntUint64 (v .(int ))
339+ }
340+
341+ if v , ok := d .GetOkExists ("continuous_time" ); ok {
342+ request .MetricAlarm .ContinuousTime = helper .IntUint64 (v .(int ))
343+ }
344+
345+ if v , ok := d .GetOk ("statistic" ); ok {
346+ request .MetricAlarm .Statistic = helper .String (v .(string ))
347+ }
348+ }
304349
305350 if d .HasChange ("cooldown" ) {
306351 request .Cooldown = helper .IntUint64 (d .Get ("cooldown" ).(int ))
0 commit comments