Skip to content

fix(cls): [117616412] support alarm_level params #2653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2653.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_cls_alarm: Support `alarm_level` params and fix import issues.
```
25 changes: 24 additions & 1 deletion tencentcloud/services/cls/resource_tc_cls_alarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ func ResourceTencentCloudClsAlarm() *schema.Resource {
Description: "triggering conditions.",
},

"alarm_level": {
Optional: true,
Computed: true,
Type: schema.TypeInt,
Description: "Alarm level. 0: Warning; 1: Info; 2: Critical. Default is 0.",
},

"trigger_count": {
Required: true,
Type: schema.TypeInt,
Expand All @@ -121,6 +128,7 @@ func ResourceTencentCloudClsAlarm() *schema.Resource {

"status": {
Optional: true,
Computed: true,
Type: schema.TypeBool,
Description: "whether to enable the alarm policy.",
},
Expand All @@ -133,6 +141,7 @@ func ResourceTencentCloudClsAlarm() *schema.Resource {

"call_back": {
Optional: true,
Computed: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "user define callback.",
Expand Down Expand Up @@ -262,6 +271,11 @@ func resourceTencentCloudClsAlarmCreate(d *schema.ResourceData, meta interface{}

if v, ok := d.GetOk("condition"); ok {
request.Condition = helper.String(v.(string))
request.AlarmLevel = helper.IntUint64(0)
}

if v, ok := d.GetOkExists("alarm_level"); ok {
request.AlarmLevel = helper.IntUint64(v.(int))
}

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

if alarm.AlarmLevel != nil {
_ = d.Set("alarm_level", alarm.AlarmLevel)
}

if alarm.TriggerCount != nil {
_ = d.Set("trigger_count", alarm.TriggerCount)
}
Expand Down Expand Up @@ -547,7 +565,7 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
request.AlarmId = &alarmId

mutableArgs := []string{
"name", "alarm_targets", "monitor_time", "condition",
"name", "alarm_targets", "monitor_time", "condition", "alarm_level",
"trigger_count", "alarm_period", "alarm_notice_ids",
"status", "message_template", "call_back", "analysis",
}
Expand Down Expand Up @@ -604,6 +622,11 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}

if v, ok := d.GetOk("condition"); ok {
request.Condition = helper.String(v.(string))
request.AlarmLevel = helper.IntUint64(0)
}

if v, ok := d.GetOkExists("alarm_level"); ok {
request.AlarmLevel = helper.IntUint64(v.(int))
}

if v, ok := d.GetOkExists("trigger_count"); ok {
Expand Down
9 changes: 5 additions & 4 deletions tencentcloud/services/cls/resource_tc_cls_alarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ Provides a resource to create a cls alarm
Example Usage

```hcl
resource "tencentcloud_cls_alarm" "alarm" {
name = "terraform-alarm-test"
resource "tencentcloud_cls_alarm" "example" {
name = "tf-example"
alarm_notice_ids = [
"notice-0850756b-245d-4bc7-bb27-2a58fffc780b",
]
alarm_period = 15
condition = "test"
alarm_level = 0
message_template = "{{.Label}}"
status = true
tags = {
tags = {
"createdBy" = "terraform"
}
trigger_count = 1
Expand Down Expand Up @@ -49,5 +50,5 @@ Import
cls alarm can be imported using the id, e.g.

```
terraform import tencentcloud_cls_alarm.alarm alarm_id
terraform import tencentcloud_cls_alarm.example alarm-d8529662-e10f-440c-ba80-50f3dcf215a3
```
39 changes: 22 additions & 17 deletions tencentcloud/services/cls/resource_tc_cls_alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// go test -i; go test -test.run TestAccTencentCloudClsAlarmResource_basic -v
func TestAccTencentCloudClsAlarmResource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
Expand All @@ -18,12 +19,18 @@ func TestAccTencentCloudClsAlarmResource_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccClsAlarm,
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cls_alarm.alarm", "id")),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("tencentcloud_cls_alarm.alarm", "id"),
resource.TestCheckResourceAttr("tencentcloud_cls_alarm.alarm", "name", "tf-example"),
resource.TestCheckResourceAttr("tencentcloud_cls_alarm.alarm", "condition", "test"),
),
},
{
Config: testAccClsAlarmUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("tencentcloud_cls_alarm.alarm", "name", "terraform-alarm-for-test"),
resource.TestCheckResourceAttrSet("tencentcloud_cls_alarm.alarm", "id"),
resource.TestCheckResourceAttr("tencentcloud_cls_alarm.alarm", "name", "tf-example-update"),
resource.TestCheckResourceAttr("tencentcloud_cls_alarm.alarm", "condition", "test update"),
),
},
{
Expand All @@ -36,28 +43,28 @@ func TestAccTencentCloudClsAlarmResource_basic(t *testing.T) {
}

const testAccClsAlarm = `

resource "tencentcloud_cls_alarm" "alarm" {
name = "terraform-alarm-test"
name = "tf-example"
alarm_notice_ids = [
"notice-0850756b-245d-4bc7-bb27-2a58fffc780b",
"notice-d365c616-1ae2-4a77-863a-9777453ab9d5",
]
alarm_period = 15
condition = "test"
alarm_level = 0
message_template = "{{.Label}}"
status = true
tags = {
tags = {
"createdBy" = "terraform"
}
trigger_count = 1

alarm_targets {
end_time_offset = 0
logset_id = "33aaf0ae-6163-411b-a415-9f27450f68db"
logset_id = "dac3e1a9-d22c-403b-a129-f94f666a33af"
number = 1
query = "status:>500 | select count(*) as errorCounts"
start_time_offset = -15
topic_id = "88735a07-bea4-4985-8763-e9deb6da4fad"
topic_id = "775c0bc2-2246-43a0-8eb2-f5bc248be183"
}

analysis {
Expand All @@ -76,32 +83,31 @@ resource "tencentcloud_cls_alarm" "alarm" {
type = "Period"
}
}

`

const testAccClsAlarmUpdate = `

resource "tencentcloud_cls_alarm" "alarm" {
name = "terraform-alarm-for-test"
name = "tf-example-update"
alarm_notice_ids = [
"notice-0850756b-245d-4bc7-bb27-2a58fffc780b",
"notice-d365c616-1ae2-4a77-863a-9777453ab9d5",
]
alarm_period = 15
condition = "test"
condition = "test update"
alarm_level = 1
message_template = "{{.Label}}"
status = true
tags = {
tags = {
"createdBy" = "terraform"
}
trigger_count = 1

alarm_targets {
end_time_offset = 0
logset_id = "33aaf0ae-6163-411b-a415-9f27450f68db"
logset_id = "dac3e1a9-d22c-403b-a129-f94f666a33af"
number = 1
query = "status:>500 | select count(*) as errorCounts"
start_time_offset = -15
topic_id = "88735a07-bea4-4985-8763-e9deb6da4fad"
topic_id = "775c0bc2-2246-43a0-8eb2-f5bc248be183"
}

analysis {
Expand All @@ -120,5 +126,4 @@ resource "tencentcloud_cls_alarm" "alarm" {
type = "Period"
}
}

`
8 changes: 5 additions & 3 deletions website/docs/r/cls_alarm.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ Provides a resource to create a cls alarm
## Example Usage

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

```
terraform import tencentcloud_cls_alarm.alarm alarm_id
terraform import tencentcloud_cls_alarm.example alarm-d8529662-e10f-440c-ba80-50f3dcf215a3
```

Loading