Skip to content

Commit f4d8fa4

Browse files
committed
examples: improve the examples
1 parent fcf3990 commit f4d8fa4

File tree

5 files changed

+20
-26
lines changed

5 files changed

+20
-26
lines changed

examples/complete/main.tf

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
data "alicloud_cs_managed_kubernetes_clusters" "default" {
1+
resource "random_integer" "default" {
2+
min = 100000
3+
max = 999999
4+
}
5+
6+
resource "alicloud_arms_prometheus" "default" {
7+
cluster_type = "remote-write"
8+
cluster_name = "tf-example-${random_integer.default.result}"
9+
grafana_instance_id = "free"
210
}
311

412
resource "alicloud_arms_alert_contact" "default" {
@@ -16,7 +24,7 @@ module "example" {
1624
contact_ids = [alicloud_arms_alert_contact.default.id]
1725

1826
#alicloud_arms_dispatch_rule
19-
dispatch_rule_name = var.dispatch_rule_name
27+
dispatch_rule_name = "${var.dispatch_rule_name}-${random_integer.default.result}"
2028
dispatch_type = var.dispatch_type
2129
group_wait_time = var.group_wait_time
2230
group_interval = var.group_interval
@@ -34,12 +42,11 @@ module "example" {
3442
notify_channels = var.notify_channels
3543

3644
#alicloud_arms_prometheus_alert_rule
37-
alert_name = "tf-testacc-alert"
38-
cluster_id = data.alicloud_cs_managed_kubernetes_clusters.default.clusters.0.id
45+
alert_name = "tf-testacc-alert-${random_integer.default.result}"
46+
cluster_id = alicloud_arms_prometheus.default.cluster_id
3947
alert_expression = "node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 10"
4048
alert_message = "node available memory is less than 10%"
4149
alert_duration = "1"
4250
alert_notify_type = var.alert_notify_type
4351
prometheus_type = "alert"
44-
45-
}
52+
}

examples/complete/variables.tf

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ variable "group_interval" {
4646
variable "repeat_interval" {
4747
description = "The repeat interval time of arms contract group."
4848
type = number
49-
default = 10
49+
default = 61
5050
}
5151

5252
variable "grouping_fields" {
@@ -55,22 +55,6 @@ variable "grouping_fields" {
5555
default = ["CreateDispatchRuleValue"]
5656
}
5757

58-
variable "match_expressions" {
59-
description = "The lable of match expresoins."
60-
type = list(object({
61-
key = string
62-
value = string
63-
operator = string
64-
}))
65-
default = [
66-
{
67-
key = "_aliyun_arms_alert_name",
68-
value = "tf-testacc-app",
69-
operator = "eq"
70-
}
71-
]
72-
}
73-
7458
variable "notify_type" {
7559
description = "The type of the alert contact. Valid values: ARMS_CONTACT: contact. ARMS_CONTACT_GROUP: contact group."
7660
type = string

examples/complete/versions.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform {
2+
required_version = ">= 0.13"
3+
}

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ resource "alicloud_arms_dispatch_rule" "arms_dispatch_rule" {
2828
}
2929
notify_rules {
3030
notify_objects {
31-
notify_object_id = alicloud_arms_alert_contact_group.arms_alert_contact_group.0.id
31+
notify_object_id = alicloud_arms_alert_contact_group.arms_alert_contact_group[0].id
3232
notify_type = var.notify_type
3333
name = var.notification_name
3434
}
@@ -44,6 +44,6 @@ resource "alicloud_arms_prometheus_alert_rule" "arms_prometheus_alert_rule" {
4444
message = var.alert_message
4545
duration = var.alert_duration
4646
notify_type = var.alert_notify_type
47-
dispatch_rule_id = alicloud_arms_dispatch_rule.arms_dispatch_rule.0.id
47+
dispatch_rule_id = alicloud_arms_dispatch_rule.arms_dispatch_rule[0].id
4848
type = var.prometheus_type
4949
}

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
output "this_prometheus_alert_rule" {
22
description = "The alert rule ID of prometheus."
3-
value = concat(alicloud_arms_prometheus_alert_rule.arms_prometheus_alert_rule.*.id, [""])[0]
3+
value = concat(alicloud_arms_prometheus_alert_rule.arms_prometheus_alert_rule[*].id, [""])[0]
44
}

0 commit comments

Comments
 (0)