diff --git a/.changelog/2653.txt b/.changelog/2653.txt new file mode 100644 index 0000000000..d3533d50ba --- /dev/null +++ b/.changelog/2653.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_cls_alarm: Support `alarm_level` params and fix import issues. +``` diff --git a/tencentcloud/services/cls/resource_tc_cls_alarm.go b/tencentcloud/services/cls/resource_tc_cls_alarm.go index 5ffcfcee66..875b8d723d 100644 --- a/tencentcloud/services/cls/resource_tc_cls_alarm.go +++ b/tencentcloud/services/cls/resource_tc_cls_alarm.go @@ -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, @@ -121,6 +128,7 @@ func ResourceTencentCloudClsAlarm() *schema.Resource { "status": { Optional: true, + Computed: true, Type: schema.TypeBool, Description: "whether to enable the alarm policy.", }, @@ -133,6 +141,7 @@ func ResourceTencentCloudClsAlarm() *schema.Resource { "call_back": { Optional: true, + Computed: true, Type: schema.TypeList, MaxItems: 1, Description: "user define callback.", @@ -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 { @@ -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) } @@ -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", } @@ -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 { diff --git a/tencentcloud/services/cls/resource_tc_cls_alarm.md b/tencentcloud/services/cls/resource_tc_cls_alarm.md index cc955f0de7..e64a1454f3 100644 --- a/tencentcloud/services/cls/resource_tc_cls_alarm.md +++ b/tencentcloud/services/cls/resource_tc_cls_alarm.md @@ -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 @@ -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 ``` \ No newline at end of file diff --git a/tencentcloud/services/cls/resource_tc_cls_alarm_test.go b/tencentcloud/services/cls/resource_tc_cls_alarm_test.go index 80210204bc..8631afb2e3 100644 --- a/tencentcloud/services/cls/resource_tc_cls_alarm_test.go +++ b/tencentcloud/services/cls/resource_tc_cls_alarm_test.go @@ -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{ @@ -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"), ), }, { @@ -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 { @@ -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 { @@ -120,5 +126,4 @@ resource "tencentcloud_cls_alarm" "alarm" { type = "Period" } } - ` diff --git a/website/docs/r/cls_alarm.html.markdown b/website/docs/r/cls_alarm.html.markdown index 6c9431ba0b..85c04a5377 100644 --- a/website/docs/r/cls_alarm.html.markdown +++ b/website/docs/r/cls_alarm.html.markdown @@ -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 = { @@ -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. @@ -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 ```