Skip to content

Commit 9783fd7

Browse files
committed
add
1 parent cb5c8cc commit 9783fd7

File tree

4 files changed

+56
-25
lines changed

4 files changed

+56
-25
lines changed

tencentcloud/services/cls/resource_tc_cls_alarm.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ func ResourceTencentCloudClsAlarm() *schema.Resource {
9898
Description: "triggering conditions.",
9999
},
100100

101+
"alarm_level": {
102+
Optional: true,
103+
Computed: true,
104+
Type: schema.TypeInt,
105+
Description: "Alarm level. 0: Warning; 1: Info; 2: Critical. Default is 0.",
106+
},
107+
101108
"trigger_count": {
102109
Required: true,
103110
Type: schema.TypeInt,
@@ -121,6 +128,7 @@ func ResourceTencentCloudClsAlarm() *schema.Resource {
121128

122129
"status": {
123130
Optional: true,
131+
Computed: true,
124132
Type: schema.TypeBool,
125133
Description: "whether to enable the alarm policy.",
126134
},
@@ -133,6 +141,7 @@ func ResourceTencentCloudClsAlarm() *schema.Resource {
133141

134142
"call_back": {
135143
Optional: true,
144+
Computed: true,
136145
Type: schema.TypeList,
137146
MaxItems: 1,
138147
Description: "user define callback.",
@@ -262,6 +271,11 @@ func resourceTencentCloudClsAlarmCreate(d *schema.ResourceData, meta interface{}
262271

263272
if v, ok := d.GetOk("condition"); ok {
264273
request.Condition = helper.String(v.(string))
274+
request.AlarmLevel = helper.IntUint64(0)
275+
}
276+
277+
if v, ok := d.GetOkExists("alarm_level"); ok {
278+
request.AlarmLevel = helper.IntUint64(v.(int))
265279
}
266280

267281
if v, ok := d.GetOkExists("trigger_count"); ok {
@@ -445,6 +459,10 @@ func resourceTencentCloudClsAlarmRead(d *schema.ResourceData, meta interface{})
445459
_ = d.Set("condition", alarm.Condition)
446460
}
447461

462+
if alarm.AlarmLevel != nil {
463+
_ = d.Set("alarm_level", alarm.AlarmLevel)
464+
}
465+
448466
if alarm.TriggerCount != nil {
449467
_ = d.Set("trigger_count", alarm.TriggerCount)
450468
}
@@ -547,7 +565,7 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
547565
request.AlarmId = &alarmId
548566

549567
mutableArgs := []string{
550-
"name", "alarm_targets", "monitor_time", "condition",
568+
"name", "alarm_targets", "monitor_time", "condition", "alarm_level",
551569
"trigger_count", "alarm_period", "alarm_notice_ids",
552570
"status", "message_template", "call_back", "analysis",
553571
}
@@ -604,6 +622,11 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
604622

605623
if v, ok := d.GetOk("condition"); ok {
606624
request.Condition = helper.String(v.(string))
625+
request.AlarmLevel = helper.IntUint64(0)
626+
}
627+
628+
if v, ok := d.GetOkExists("alarm_level"); ok {
629+
request.AlarmLevel = helper.IntUint64(v.(int))
607630
}
608631

609632
if v, ok := d.GetOkExists("trigger_count"); ok {

tencentcloud/services/cls/resource_tc_cls_alarm.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ Provides a resource to create a cls alarm
33
Example Usage
44

55
```hcl
6-
resource "tencentcloud_cls_alarm" "alarm" {
7-
name = "terraform-alarm-test"
6+
resource "tencentcloud_cls_alarm" "example" {
7+
name = "tf-example"
88
alarm_notice_ids = [
99
"notice-0850756b-245d-4bc7-bb27-2a58fffc780b",
1010
]
1111
alarm_period = 15
1212
condition = "test"
13+
alarm_level = 0
1314
message_template = "{{.Label}}"
1415
status = true
15-
tags = {
16+
tags = {
1617
"createdBy" = "terraform"
1718
}
1819
trigger_count = 1
@@ -49,5 +50,5 @@ Import
4950
cls alarm can be imported using the id, e.g.
5051

5152
```
52-
terraform import tencentcloud_cls_alarm.alarm alarm_id
53+
terraform import tencentcloud_cls_alarm.example alarm-d8529662-e10f-440c-ba80-50f3dcf215a3
5354
```

tencentcloud/services/cls/resource_tc_cls_alarm_test.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
99
)
1010

11+
// go test -i; go test -test.run TestAccTencentCloudClsAlarmResource_basic -v
1112
func TestAccTencentCloudClsAlarmResource_basic(t *testing.T) {
1213
t.Parallel()
1314
resource.Test(t, resource.TestCase{
@@ -18,12 +19,18 @@ func TestAccTencentCloudClsAlarmResource_basic(t *testing.T) {
1819
Steps: []resource.TestStep{
1920
{
2021
Config: testAccClsAlarm,
21-
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cls_alarm.alarm", "id")),
22+
Check: resource.ComposeTestCheckFunc(
23+
resource.TestCheckResourceAttrSet("tencentcloud_cls_alarm.alarm", "id"),
24+
resource.TestCheckResourceAttr("tencentcloud_cls_alarm.alarm", "name", "tf-example"),
25+
resource.TestCheckResourceAttr("tencentcloud_cls_alarm.alarm", "condition", "test"),
26+
),
2227
},
2328
{
2429
Config: testAccClsAlarmUpdate,
2530
Check: resource.ComposeTestCheckFunc(
26-
resource.TestCheckResourceAttr("tencentcloud_cls_alarm.alarm", "name", "terraform-alarm-for-test"),
31+
resource.TestCheckResourceAttrSet("tencentcloud_cls_alarm.alarm", "id"),
32+
resource.TestCheckResourceAttr("tencentcloud_cls_alarm.alarm", "name", "tf-example-update"),
33+
resource.TestCheckResourceAttr("tencentcloud_cls_alarm.alarm", "condition", "test update"),
2734
),
2835
},
2936
{
@@ -36,28 +43,28 @@ func TestAccTencentCloudClsAlarmResource_basic(t *testing.T) {
3643
}
3744

3845
const testAccClsAlarm = `
39-
4046
resource "tencentcloud_cls_alarm" "alarm" {
41-
name = "terraform-alarm-test"
47+
name = "tf-example"
4248
alarm_notice_ids = [
43-
"notice-0850756b-245d-4bc7-bb27-2a58fffc780b",
49+
"notice-d365c616-1ae2-4a77-863a-9777453ab9d5",
4450
]
4551
alarm_period = 15
4652
condition = "test"
53+
alarm_level = 0
4754
message_template = "{{.Label}}"
4855
status = true
49-
tags = {
56+
tags = {
5057
"createdBy" = "terraform"
5158
}
5259
trigger_count = 1
5360
5461
alarm_targets {
5562
end_time_offset = 0
56-
logset_id = "33aaf0ae-6163-411b-a415-9f27450f68db"
63+
logset_id = "dac3e1a9-d22c-403b-a129-f94f666a33af"
5764
number = 1
5865
query = "status:>500 | select count(*) as errorCounts"
5966
start_time_offset = -15
60-
topic_id = "88735a07-bea4-4985-8763-e9deb6da4fad"
67+
topic_id = "775c0bc2-2246-43a0-8eb2-f5bc248be183"
6168
}
6269
6370
analysis {
@@ -76,32 +83,31 @@ resource "tencentcloud_cls_alarm" "alarm" {
7683
type = "Period"
7784
}
7885
}
79-
8086
`
8187

8288
const testAccClsAlarmUpdate = `
83-
8489
resource "tencentcloud_cls_alarm" "alarm" {
85-
name = "terraform-alarm-for-test"
90+
name = "tf-example-update"
8691
alarm_notice_ids = [
87-
"notice-0850756b-245d-4bc7-bb27-2a58fffc780b",
92+
"notice-d365c616-1ae2-4a77-863a-9777453ab9d5",
8893
]
8994
alarm_period = 15
90-
condition = "test"
95+
condition = "test update"
96+
alarm_level = 1
9197
message_template = "{{.Label}}"
9298
status = true
93-
tags = {
99+
tags = {
94100
"createdBy" = "terraform"
95101
}
96102
trigger_count = 1
97103
98104
alarm_targets {
99105
end_time_offset = 0
100-
logset_id = "33aaf0ae-6163-411b-a415-9f27450f68db"
106+
logset_id = "dac3e1a9-d22c-403b-a129-f94f666a33af"
101107
number = 1
102108
query = "status:>500 | select count(*) as errorCounts"
103109
start_time_offset = -15
104-
topic_id = "88735a07-bea4-4985-8763-e9deb6da4fad"
110+
topic_id = "775c0bc2-2246-43a0-8eb2-f5bc248be183"
105111
}
106112
107113
analysis {
@@ -120,5 +126,4 @@ resource "tencentcloud_cls_alarm" "alarm" {
120126
type = "Period"
121127
}
122128
}
123-
124129
`

website/docs/r/cls_alarm.html.markdown

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ Provides a resource to create a cls alarm
1414
## Example Usage
1515

1616
```hcl
17-
resource "tencentcloud_cls_alarm" "alarm" {
18-
name = "terraform-alarm-test"
17+
resource "tencentcloud_cls_alarm" "example" {
18+
name = "tf-example"
1919
alarm_notice_ids = [
2020
"notice-0850756b-245d-4bc7-bb27-2a58fffc780b",
2121
]
2222
alarm_period = 15
2323
condition = "test"
24+
alarm_level = 0
2425
message_template = "{{.Label}}"
2526
status = true
2627
tags = {
@@ -66,6 +67,7 @@ The following arguments are supported:
6667
* `monitor_time` - (Required, List) monitor task execution time.
6768
* `name` - (Required, String) log alarm name.
6869
* `trigger_count` - (Required, Int) continuous cycle.
70+
* `alarm_level` - (Optional, Int) Alarm level. 0: Warning; 1: Info; 2: Critical. Default is 0.
6971
* `analysis` - (Optional, List) multidimensional analysis.
7072
* `call_back` - (Optional, List) user define callback.
7173
* `message_template` - (Optional, String) user define alarm notice.
@@ -116,6 +118,6 @@ In addition to all arguments above, the following attributes are exported:
116118
cls alarm can be imported using the id, e.g.
117119

118120
```
119-
terraform import tencentcloud_cls_alarm.alarm alarm_id
121+
terraform import tencentcloud_cls_alarm.example alarm-d8529662-e10f-440c-ba80-50f3dcf215a3
120122
```
121123

0 commit comments

Comments
 (0)