@@ -59,7 +59,7 @@ func ResourceTencentCloudMonitorTmpAlertRule() *schema.Resource {
5959 Description : "Rule alarm duration." ,
6060 },
6161 "labels" : {
62- Type : schema .TypeList ,
62+ Type : schema .TypeSet ,
6363 Optional : true ,
6464 Description : "Rule alarm duration." ,
6565 Elem : & schema.Resource {
@@ -78,7 +78,7 @@ func ResourceTencentCloudMonitorTmpAlertRule() *schema.Resource {
7878 },
7979 },
8080 "annotations" : {
81- Type : schema .TypeList ,
81+ Type : schema .TypeSet ,
8282 Optional : true ,
8383 Description : "Rule alarm duration." ,
8484 Elem : & schema.Resource {
@@ -142,36 +142,37 @@ func resourceTencentCloudMonitorTmpAlertRuleCreate(d *schema.ResourceData, meta
142142 if v , ok := d .GetOk ("duration" ); ok {
143143 request .Duration = helper .String (v .(string ))
144144 }
145+
145146 if v , ok := d .GetOk ("labels" ); ok {
146- labelsList := v .([]interface {})
147- prometheusRuleKV := make ([]* monitor.PrometheusRuleKV , 0 , len (labelsList ))
148- for _ , labels := range labelsList {
149- if labels == nil {
150- return fmt .Errorf ("Invalid `labels` parameter, must not be empty" )
147+ for _ , item := range v .(* schema.Set ).List () {
148+ dMap := item .(map [string ]interface {})
149+ prometheusRuleKV := monitor.PrometheusRuleKV {}
150+ if v , ok := dMap ["key" ]; ok {
151+ prometheusRuleKV .Key = helper .String (v .(string ))
152+ }
153+
154+ if v , ok := dMap ["value" ]; ok {
155+ prometheusRuleKV .Value = helper .String (v .(string ))
151156 }
152- label := labels .(map [string ]interface {})
153- var kv monitor.PrometheusRuleKV
154- kv .Key = helper .String (label ["key" ].(string ))
155- kv .Value = helper .String (label ["value" ].(string ))
156- prometheusRuleKV = append (prometheusRuleKV , & kv )
157+ request .Labels = append (request .Labels , & prometheusRuleKV )
157158 }
158- request .Labels = prometheusRuleKV
159159 }
160+
160161 if v , ok := d .GetOk ("annotations" ); ok {
161- annotationsList := v .([]interface {})
162- prometheusRuleKV := make ([]* monitor.PrometheusRuleKV , 0 , len (annotationsList ))
163- for _ , annotations := range annotationsList {
164- if annotations == nil {
165- return fmt .Errorf ("Invalid `annotation` parameter, must not be empty" )
162+ for _ , item := range v .(* schema.Set ).List () {
163+ dMap := item .(map [string ]interface {})
164+ prometheusRuleKV := monitor.PrometheusRuleKV {}
165+ if v , ok := dMap ["key" ]; ok {
166+ prometheusRuleKV .Key = helper .String (v .(string ))
167+ }
168+
169+ if v , ok := dMap ["value" ]; ok {
170+ prometheusRuleKV .Value = helper .String (v .(string ))
166171 }
167- annotation := annotations .(map [string ]interface {})
168- var kv monitor.PrometheusRuleKV
169- kv .Key = helper .String (annotation ["key" ].(string ))
170- kv .Value = helper .String (annotation ["value" ].(string ))
171- prometheusRuleKV = append (prometheusRuleKV , & kv )
172+ request .Annotations = append (request .Annotations , & prometheusRuleKV )
172173 }
173- request .Annotations = prometheusRuleKV
174174 }
175+
175176 if v , ok := d .GetOk ("type" ); ok {
176177 request .Type = helper .String (v .(string ))
177178 }
@@ -323,29 +324,33 @@ func resourceTencentCloudMonitorTmpAlertRuleUpdate(d *schema.ResourceData, meta
323324 }
324325
325326 if v , ok := d .GetOk ("labels" ); ok {
326- labelsList := v .([]interface {})
327- prometheusRuleKV := make ([]* monitor.PrometheusRuleKV , 0 , len (labelsList ))
328- for _ , labels := range labelsList {
329- label := labels .(map [string ]interface {})
330- var kv monitor.PrometheusRuleKV
331- kv .Key = helper .String (label ["key" ].(string ))
332- kv .Value = helper .String (label ["value" ].(string ))
333- prometheusRuleKV = append (prometheusRuleKV , & kv )
327+ for _ , item := range v .(* schema.Set ).List () {
328+ dMap := item .(map [string ]interface {})
329+ prometheusRuleKV := monitor.PrometheusRuleKV {}
330+ if v , ok := dMap ["key" ]; ok {
331+ prometheusRuleKV .Key = helper .String (v .(string ))
332+ }
333+
334+ if v , ok := dMap ["value" ]; ok {
335+ prometheusRuleKV .Value = helper .String (v .(string ))
336+ }
337+ request .Labels = append (request .Labels , & prometheusRuleKV )
334338 }
335- request .Labels = prometheusRuleKV
336339 }
337340
338341 if v , ok := d .GetOk ("annotations" ); ok {
339- annotationsList := v .([]interface {})
340- prometheusRuleKV := make ([]* monitor.PrometheusRuleKV , 0 , len (annotationsList ))
341- for _ , annotations := range annotationsList {
342- annotation := annotations .(map [string ]interface {})
343- var kv monitor.PrometheusRuleKV
344- kv .Key = helper .String (annotation ["key" ].(string ))
345- kv .Value = helper .String (annotation ["value" ].(string ))
346- prometheusRuleKV = append (prometheusRuleKV , & kv )
342+ for _ , item := range v .(* schema.Set ).List () {
343+ dMap := item .(map [string ]interface {})
344+ prometheusRuleKV := monitor.PrometheusRuleKV {}
345+ if v , ok := dMap ["key" ]; ok {
346+ prometheusRuleKV .Key = helper .String (v .(string ))
347+ }
348+
349+ if v , ok := dMap ["value" ]; ok {
350+ prometheusRuleKV .Value = helper .String (v .(string ))
351+ }
352+ request .Annotations = append (request .Annotations , & prometheusRuleKV )
347353 }
348- request .Annotations = prometheusRuleKV
349354 }
350355
351356 if v , ok := d .GetOk ("type" ); ok {
0 commit comments