@@ -59,7 +59,7 @@ func ResourceTencentCloudMonitorTmpAlertRule() *schema.Resource {
59
59
Description : "Rule alarm duration." ,
60
60
},
61
61
"labels" : {
62
- Type : schema .TypeList ,
62
+ Type : schema .TypeSet ,
63
63
Optional : true ,
64
64
Description : "Rule alarm duration." ,
65
65
Elem : & schema.Resource {
@@ -78,7 +78,7 @@ func ResourceTencentCloudMonitorTmpAlertRule() *schema.Resource {
78
78
},
79
79
},
80
80
"annotations" : {
81
- Type : schema .TypeList ,
81
+ Type : schema .TypeSet ,
82
82
Optional : true ,
83
83
Description : "Rule alarm duration." ,
84
84
Elem : & schema.Resource {
@@ -142,36 +142,37 @@ func resourceTencentCloudMonitorTmpAlertRuleCreate(d *schema.ResourceData, meta
142
142
if v , ok := d .GetOk ("duration" ); ok {
143
143
request .Duration = helper .String (v .(string ))
144
144
}
145
+
145
146
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 ))
151
156
}
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 )
157
158
}
158
- request .Labels = prometheusRuleKV
159
159
}
160
+
160
161
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 ))
166
171
}
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 )
172
173
}
173
- request .Annotations = prometheusRuleKV
174
174
}
175
+
175
176
if v , ok := d .GetOk ("type" ); ok {
176
177
request .Type = helper .String (v .(string ))
177
178
}
@@ -323,29 +324,33 @@ func resourceTencentCloudMonitorTmpAlertRuleUpdate(d *schema.ResourceData, meta
323
324
}
324
325
325
326
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 )
334
338
}
335
- request .Labels = prometheusRuleKV
336
339
}
337
340
338
341
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 )
347
353
}
348
- request .Annotations = prometheusRuleKV
349
354
}
350
355
351
356
if v , ok := d .GetOk ("type" ); ok {
0 commit comments