Skip to content

Commit d3d0b1e

Browse files
authored
fix(tmp): [117224022]Fix array order issue (#2620)
* fix(tmp): [117224022]Fix array order issue * fix: modify doc * feat: add changelog
1 parent 2475ad1 commit d3d0b1e

6 files changed

+59
-56
lines changed

.changelog/2620.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_monitor_tmp_alert_rule: Fix array order issue
3+
```

tencentcloud/acctest/basic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ const (
240240
// monitor
241241
const (
242242
DefaultTmpVpcId = "vpc-axrsmmrv"
243-
DefaultTmpSubnetId = "subnet-b23ua6gk"
243+
DefaultTmpSubnetId = "subnet-j5vja918"
244244
)
245245

246246
/*

tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_rule.go

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_rule_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func TestAccTencentCloudMonitorAlertRuleResource_basic(t *testing.T) {
1919
t.Parallel()
2020
resource.Test(t, resource.TestCase{
21-
PreCheck: func() { tcacctest.AccPreCheckCommon(t, tcacctest.ACCOUNT_TYPE_COMMON) },
21+
PreCheck: func() { tcacctest.AccPreCheck(t) },
2222
Providers: tcacctest.AccProviders,
2323
CheckDestroy: testAccCheckAlertRuleDestroy,
2424
Steps: []resource.TestStep{
@@ -123,14 +123,9 @@ func testAccCheckAlertRuleExists(r string) resource.TestCheckFunc {
123123
}
124124
}
125125

126-
const testAlertRuleVar = `
127-
variable "prometheus_id" {
128-
default = "` + tcacctest.DefaultPrometheusId + `"
129-
}
130-
`
131-
const testAlertRule_basic = testAlertRuleVar + `
126+
const testAlertRule_basic = testInstance_basic + `
132127
resource "tencentcloud_monitor_tmp_alert_rule" "basic" {
133-
instance_id = var.prometheus_id
128+
instance_id = tencentcloud_monitor_tmp_instance.basic.id
134129
rule_name = "test-rule_name"
135130
receivers = ["notice-tj75hgqj"]
136131
expr = "increase(mysql_global_status_slow_queries[1m]) > 0"
@@ -146,9 +141,9 @@ resource "tencentcloud_monitor_tmp_alert_rule" "basic" {
146141
}
147142
}`
148143

149-
const testAlertRule_update = testAlertRuleVar + `
144+
const testAlertRule_update = testInstance_basic + `
150145
resource "tencentcloud_monitor_tmp_alert_rule" "basic" {
151-
instance_id = var.prometheus_id
146+
instance_id = tencentcloud_monitor_tmp_instance.basic.id
152147
rule_name = "test-rule_name_update"
153148
receivers = ["notice-tj75hgqj"]
154149
expr = "increase(mysql_global_status_slow_queries[1m]) > 1"

tencentcloud/services/tmp/resource_tc_monitor_tmp_instance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func TestAccTencentCloudMonitorInstance_basic(t *testing.T) {
1919
t.Parallel()
2020
resource.Test(t, resource.TestCase{
21-
PreCheck: func() { tcacctest.AccPreCheckCommon(t, tcacctest.ACCOUNT_TYPE_COMMON) },
21+
PreCheck: func() { tcacctest.AccPreCheck(t) },
2222
Providers: tcacctest.AccProviders,
2323
CheckDestroy: testAccCheckMonInstanceDestroy,
2424
Steps: []resource.TestStep{

website/docs/r/monitor_tmp_alert_rule.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ The following arguments are supported:
8181
* `instance_id` - (Required, String) Instance id.
8282
* `receivers` - (Required, Set: [`String`]) Alarm notification template id list.
8383
* `rule_name` - (Required, String) Rule name.
84-
* `annotations` - (Optional, List) Rule alarm duration.
84+
* `annotations` - (Optional, Set) Rule alarm duration.
8585
* `duration` - (Optional, String) Rule alarm duration.
86-
* `labels` - (Optional, List) Rule alarm duration.
86+
* `labels` - (Optional, Set) Rule alarm duration.
8787
* `rule_state` - (Optional, Int) Rule state code.
8888
* `type` - (Optional, String) Alarm Policy Template Classification.
8989

0 commit comments

Comments
 (0)