@@ -39,6 +39,7 @@ import (
3939
4040 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
4141 "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
42+ sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
4243 monitor "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor/v20180724"
4344 "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
4445)
@@ -172,6 +173,9 @@ func resourceTencentCloudMonitorTmpAlertRuleCreate(d *schema.ResourceData, meta
172173 labelsList := v .([]interface {})
173174 prometheusRuleKV := make ([]* monitor.PrometheusRuleKV , 0 , len (labelsList ))
174175 for _ , labels := range labelsList {
176+ if labels == nil {
177+ return fmt .Errorf ("Invalid `labels` parameter, must not be empty" )
178+ }
175179 label := labels .(map [string ]interface {})
176180 var kv monitor.PrometheusRuleKV
177181 kv .Key = helper .String (label ["key" ].(string ))
@@ -184,6 +188,9 @@ func resourceTencentCloudMonitorTmpAlertRuleCreate(d *schema.ResourceData, meta
184188 annotationsList := v .([]interface {})
185189 prometheusRuleKV := make ([]* monitor.PrometheusRuleKV , 0 , len (annotationsList ))
186190 for _ , annotations := range annotationsList {
191+ if annotations == nil {
192+ return fmt .Errorf ("Invalid `annotation` parameter, must not be empty" )
193+ }
187194 annotation := annotations .(map [string ]interface {})
188195 var kv monitor.PrometheusRuleKV
189196 kv .Key = helper .String (annotation ["key" ].(string ))
@@ -199,6 +206,10 @@ func resourceTencentCloudMonitorTmpAlertRuleCreate(d *schema.ResourceData, meta
199206 err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
200207 result , e := meta .(* TencentCloudClient ).apiV3Conn .UseMonitorClient ().CreateAlertRule (request )
201208 if e != nil {
209+ ee , ok := e .(* sdkErrors.TencentCloudSDKError )
210+ if ok && IsContains ("FailedOperation" , ee .Code ) {
211+ return resource .NonRetryableError (ee )
212+ }
202213 return retryError (e )
203214 } else {
204215 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
@@ -279,7 +290,7 @@ func resourceTencentCloudMonitorTmpAlertRuleRead(d *schema.ResourceData, meta in
279290 _ = d .Set ("labels" , result )
280291 }
281292 if tmpAlertRule .Annotations != nil {
282- annotationsList := tmpAlertRule .Labels
293+ annotationsList := tmpAlertRule .Annotations
283294 result := make ([]map [string ]interface {}, 0 , len (annotationsList ))
284295 for _ , v := range annotationsList {
285296 mapping := map [string ]interface {}{
@@ -334,47 +345,47 @@ func resourceTencentCloudMonitorTmpAlertRuleUpdate(d *schema.ResourceData, meta
334345 request .RuleState = helper .IntInt64 (v .(int ))
335346 }
336347
337- if d .HasChange ("duration" ) {
338- if v , ok := d .GetOk ("duration" ); ok {
339- request .Duration = helper .String (v .(string ))
340- }
348+ if v , ok := d .GetOk ("duration" ); ok {
349+ request .Duration = helper .String (v .(string ))
341350 }
342- if d .HasChange ("labels" ) {
343- if v , ok := d .GetOk ("labels" ); ok {
344- labelsList := v .([]interface {})
345- prometheusRuleKV := make ([]* monitor.PrometheusRuleKV , 0 , len (labelsList ))
346- for _ , labels := range labelsList {
347- label := labels .(map [string ]interface {})
348- var kv monitor.PrometheusRuleKV
349- kv .Key = helper .String (label ["key" ].(string ))
350- kv .Value = helper .String (label ["value" ].(string ))
351- prometheusRuleKV = append (prometheusRuleKV , & kv )
352- }
353- request .Labels = prometheusRuleKV
351+
352+ if v , ok := d .GetOk ("labels" ); ok {
353+ labelsList := v .([]interface {})
354+ prometheusRuleKV := make ([]* monitor.PrometheusRuleKV , 0 , len (labelsList ))
355+ for _ , labels := range labelsList {
356+ label := labels .(map [string ]interface {})
357+ var kv monitor.PrometheusRuleKV
358+ kv .Key = helper .String (label ["key" ].(string ))
359+ kv .Value = helper .String (label ["value" ].(string ))
360+ prometheusRuleKV = append (prometheusRuleKV , & kv )
354361 }
362+ request .Labels = prometheusRuleKV
355363 }
356- if d .HasChange ("annotations" ) {
357- if v , ok := d .GetOk ("annotations" ); ok {
358- annotationsList := v .([]interface {})
359- prometheusRuleKV := make ([]* monitor.PrometheusRuleKV , 0 , len (annotationsList ))
360- for _ , annotations := range annotationsList {
361- annotation := annotations .(map [string ]interface {})
362- var kv monitor.PrometheusRuleKV
363- kv .Key = helper .String (annotation ["key" ].(string ))
364- kv .Value = helper .String (annotation ["value" ].(string ))
365- prometheusRuleKV = append (prometheusRuleKV , & kv )
366- }
367- request .Annotations = prometheusRuleKV
364+
365+ if v , ok := d .GetOk ("annotations" ); ok {
366+ annotationsList := v .([]interface {})
367+ prometheusRuleKV := make ([]* monitor.PrometheusRuleKV , 0 , len (annotationsList ))
368+ for _ , annotations := range annotationsList {
369+ annotation := annotations .(map [string ]interface {})
370+ var kv monitor.PrometheusRuleKV
371+ kv .Key = helper .String (annotation ["key" ].(string ))
372+ kv .Value = helper .String (annotation ["value" ].(string ))
373+ prometheusRuleKV = append (prometheusRuleKV , & kv )
368374 }
375+ request .Annotations = prometheusRuleKV
369376 }
370- if d .HasChange ("type" ) {
371- if v , ok := d .GetOk ("type" ); ok {
372- request .Type = helper .String (v .(string ))
373- }
377+
378+ if v , ok := d .GetOk ("type" ); ok {
379+ request .Type = helper .String (v .(string ))
374380 }
381+
375382 err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
376383 result , e := meta .(* TencentCloudClient ).apiV3Conn .UseMonitorClient ().UpdateAlertRule (request )
377384 if e != nil {
385+ ee , ok := e .(* sdkErrors.TencentCloudSDKError )
386+ if ok && IsContains ("FailedOperation" , ee .Code ) {
387+ return resource .NonRetryableError (ee )
388+ }
378389 return retryError (e )
379390 } else {
380391 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
0 commit comments