Skip to content
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.283
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.291
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.306
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.330
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.199
Expand All @@ -40,7 +40,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.291
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.329
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.306
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.290
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.199
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.264 h1:USf7
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.264/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.306 h1:wQe/QkYMFu41adzjalR4Un3z7g1g7pmc2aixjqxIyP0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.306/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.330 h1:yPUoeUIxqrrYoKhwYRNIDKpnZ5VIMK3qNwuuB55DZtY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.330/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.199 h1:ajgJogYSIQ5u1PIbiV5nsvr5K0fYpm1/T7Dy+mxEM6U=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.199/go.mod h1:AqyM/ZZMD7q5mHBqNY9YImbSpEpoEe7E/vrTbUWX+po=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.199 h1:L0twFkJMOZzLkX08w8S14nX6oanD8YxMQDIaYXVim6A=
Expand All @@ -500,6 +502,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.0.199 h1:2js
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.0.199/go.mod h1:f5GhbJyuYQBzRaDHGe3I4U9utb0Pmx2NlI+XcqSQRp0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.291 h1:EIUXql9I6+B9OH3ieDwA2SO/+qO35UrqA5TTToQ5Kc4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.291/go.mod h1:aMwrB/fRSIS8IFabcF0hfRC89y76DptUknUjAf1jlHE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.329 h1:T4k3VMXsjYSvXr9SlfZj5tYfpuOOtjMqGoiZhj5i1Sk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.329/go.mod h1:aMwrB/fRSIS8IFabcF0hfRC89y76DptUknUjAf1jlHE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.199 h1:Opze570l6JbOc+/nYftYmheyCU9omz+emNJpDUBYYFQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.199/go.mod h1:Rh/4NXBd0aqmaRGDYcW4gL2Zi8JShGZiB23zrfVaS90=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.306 h1:R/nD8qAexHLwcKhWOTmr9rzIrvnH1C4sEudpS4qUBWY=
Expand Down
153 changes: 151 additions & 2 deletions tencentcloud/resource_tc_monitor_alarm_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,87 @@ resource "tencentcloud_monitor_alarm_policy" "policy" {
}
```

cvm_device alarm policy binding cvm by tag
```
resource "tencentcloud_monitor_alarm_policy" "policy" {
enable = 1
monitor_type = "MT_QCE"
namespace = "cvm_device"
notice_ids = [
"notice-l9ziyxw6",
]
policy_name = "policy"
project_id = 0

conditions {
is_union_rule = 0

rules {
continue_period = 5
description = "CPUUtilization"
is_power_notice = 0
metric_name = "CpuUsage"
notice_frequency = 7200
operator = "gt"
period = 60
rule_type = "STATIC"
unit = "%"
value = "95"
}
rules {
continue_period = 5
description = "PublicBandwidthUtilization"
is_power_notice = 0
metric_name = "Outratio"
notice_frequency = 7200
operator = "gt"
period = 60
rule_type = "STATIC"
unit = "%"
value = "95"
}
rules {
continue_period = 5
description = "MemoryUtilization"
is_power_notice = 0
metric_name = "MemUsage"
notice_frequency = 7200
operator = "gt"
period = 60
rule_type = "STATIC"
unit = "%"
value = "95"
}
rules {
continue_period = 5
description = "DiskUtilization"
is_power_notice = 0
metric_name = "CvmDiskUsage"
notice_frequency = 7200
operator = "gt"
period = 60
rule_type = "STATIC"
unit = "%"
value = "95"
}
}

event_conditions {
continue_period = 0
description = "DiskReadonly"
is_power_notice = 0
metric_name = "disk_readonly"
notice_frequency = 0
period = 0
}

policy_tag {
key = "test-tag"
value = "unit-test"
}
}
```

Import

Alarm policy instance can be imported, e.g.
Expand Down Expand Up @@ -349,6 +430,26 @@ func resourceTencentMonitorAlarmPolicy() *schema.Resource {
},
},
},
"policy_tag": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: "Policy tag to bind object.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Required: true,
Description: "Tag key.",
},
"value": {
Type: schema.TypeString,
Required: true,
Description: "Tag value.",
},
},
},
},
// compute
"create_time": {
Type: schema.TypeString,
Expand Down Expand Up @@ -387,8 +488,9 @@ func resourceTencentMonitorAlarmPolicyCreate(d *schema.ResourceData, meta interf
// request.Enable = helper.IntInt64(v.(int))
//}

if v, ok := d.GetOk("project_id"); ok {
request.ProjectId = helper.IntInt64(v.(int))
projectId := d.Get("project_id").(int)
if projectId != -1 {
request.ProjectId = helper.IntInt64(projectId)
}

if v, ok := d.GetOk("conditon_template_id"); ok {
Expand Down Expand Up @@ -532,6 +634,7 @@ func resourceTencentMonitorAlarmPolicyCreate(d *schema.ResourceData, meta interf
request.TriggerTasks = tasks
}

var groupId *string
var policyId *string
if err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
ratelimit.Check(request.GetAction())
Expand All @@ -545,11 +648,48 @@ func resourceTencentMonitorAlarmPolicyCreate(d *schema.ResourceData, meta interf
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

policyId = response.Response.PolicyId
groupId = response.Response.OriginId
return nil
}); err != nil {
return err
}
d.SetId(fmt.Sprintf("%s", *policyId))

// binding tag
if v, ok := d.GetOk("policy_tag"); ok {
request := monitor.NewBindingPolicyTagRequest()

request.Module = helper.String("monitor")
request.PolicyId = helper.String(*policyId)
request.ServiceType = helper.String(d.Get("namespace").(string))
request.GroupId = helper.String(*groupId)
tagSet := make([]*monitor.PolicyTag, 0, 10)
for _, item := range v.([]interface{}) {
m := item.(map[string]interface{})
tagInfo := monitor.PolicyTag{
Key: helper.String(m["key"].(string)),
Value: helper.String(m["value"].(string)),
}
tagSet = append(tagSet, &tagInfo)
}
request.Tag = tagSet[0]

if err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
ratelimit.Check(request.GetAction())
response, err := monitorService.client.UseMonitorClient().BindingPolicyTag(request)
if err != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
logId, request.GetAction(), request.ToJsonString(), err.Error())
return retryError(err, InternalError)
}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
return nil
}); err != nil {
return err
}
}

return resourceTencentMonitorAlarmPolicyRead(d, meta)
}

Expand Down Expand Up @@ -683,6 +823,15 @@ func resourceTencentMonitorAlarmPolicyRead(d *schema.ResourceData, meta interfac
}
errs = append(errs, d.Set("trigger_tasks", triggerTasks))

tagSets := make([]map[string]interface{}, 0, len(policy.TagInstances))
for _, item := range policy.TagInstances {
tagSets = append(tagSets, map[string]interface{}{
"key": item.Key,
"value": item.Value,
})
}
_ = d.Set("policy_tag", tagSets)

if len(errs) > 0 {
return errs[0]
} else {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading