Skip to content

Commit 977466a

Browse files
MrWolongxiaozhu36
authored andcommitted
Improves the module examples/complete
1 parent dc4bd44 commit 977466a

File tree

11 files changed

+261
-114
lines changed

11 files changed

+261
-114
lines changed

.gitignore

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
# Local .terraform directories
2-
**/.terraform/*
3-
4-
# .tfstate files
1+
# Compiled files
52
*.tfstate
6-
*.tfstate.*
3+
*.tfstate.backup
4+
*.terraform.*
75

8-
# Crash log files
9-
crash.log
6+
# Module directory
7+
.terraform/
108

11-
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
12-
# .tfvars files are managed as part of configuration and so should be included in
13-
# version control.
14-
#
15-
# example.tfvars
9+
# terraform log
10+
*.log
1611

17-
# Ignore override files as they are usually used to override resources locally and so
18-
# are not checked in
19-
override.tf
20-
override.tf.json
21-
*_override.tf
22-
*_override.tf.json
12+
# auto-generated key pair file
13+
*.pem
2314

24-
# Include override files you do wish to add to version control using negated pattern
25-
#
26-
# !example_override.tf
15+
# tools files
16+
.DS_Store
17+
.idea
2718

28-
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
29-
# example: *tfplan*
19+
# others
20+
*.bak
21+
*.bk
22+
**/.terraform/*
23+
.terraform.lock.hcl
24+
.terraform.tfstate.lock.info

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ terraform-alicloud-prometheus
55

66
English | [简体中文](https://github.com/terraform-alicloud-modules/terraform-alicloud-prometheus/blob/master/README-CN.md)
77

8-
Terraform module which creates Mybase and its account on Alibaba Cloud.
8+
Terraform module which creates monitor of Prometheus on Alibaba Cloud.
99

1010
These types of resources are supported:
1111

examples/complete/.terraform.lock.hcl

Lines changed: 0 additions & 22 deletions
This file was deleted.

examples/complete/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ $ terraform apply
1414

1515
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
1616

17+
This example provides the tf variables file in the folder `tfvars`. If you want to create or update this example,
18+
you can run this example as the following commands:
19+
```bash
20+
$ terraform plan -var-file=tfvars/01-update.tfvars
21+
$ terraform apply -var-file=tfvars/01-update.tfvars
22+
```
23+
24+
Also, you can add more variables files in the folder `tfvars`.
25+
1726
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
1827
## Requirements
1928

examples/complete/main.tf

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
1-
resource "alicloud_arms_alert_contact" "default" {
2-
alert_contact_name = "example_value"
3-
1+
data "alicloud_cs_managed_kubernetes_clusters" "default" {
42
}
53

6-
data "alicloud_cs_managed_kubernetes_clusters" "default" {
7-
name_regex = "tf_Acc"
4+
resource "alicloud_arms_alert_contact" "default" {
5+
alert_contact_name = var.alert_contact_name
6+
email = var.email
87
}
98

109
module "example" {
11-
source = "../.."
12-
create = true
13-
alert_name = "tf_prometheus_alert_name"
14-
alert_expression = "node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 10"
15-
alert_message = "node available memory is less than 10%"
16-
prometheus_type = "Kubernetes component alert"
17-
alert_contact_group_name = "tf-arms-contract-group-name"
18-
dispatch_rule_name = "tf-dispatch-rule-name"
19-
group_wait_time = 5
20-
group_interval = 15
21-
repeat_interval = 100
22-
notification_name = "tf-arms-notification"
10+
source = "../.."
11+
12+
#alicloud_arms_alert_contact_group
13+
create = true
14+
15+
alert_contact_group_name = var.alert_contact_group_name
2316
contact_ids = [alicloud_arms_alert_contact.default.id]
24-
cluster_id = data.alicloud_cs_managed_kubernetes_clusters.default.id
25-
match_expressions = [{ key = "aliyun_arms_involvedObject_kind", value = "app", operator = "eq" }]
17+
18+
#alicloud_arms_dispatch_rule
19+
dispatch_rule_name = var.dispatch_rule_name
20+
dispatch_type = var.dispatch_type
21+
group_wait_time = var.group_wait_time
22+
group_interval = var.group_interval
23+
repeat_interval = var.repeat_interval
24+
grouping_fields = var.grouping_fields
25+
match_expressions = [
26+
{
27+
key = "_aliyun_arms_alert_name",
28+
value = "tf-testacc-app",
29+
operator = "eq"
30+
}
31+
]
32+
notify_type = var.notify_type
33+
notification_name = var.notification_name
34+
notify_channels = var.notify_channels
35+
36+
#alicloud_arms_prometheus_alert_rule
37+
alert_name = "tf-testacc-alert"
38+
cluster_id = data.alicloud_cs_managed_kubernetes_clusters.default.clusters.0.id
39+
alert_expression = "node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 10"
40+
alert_message = "node available memory is less than 10%"
41+
alert_duration = "1"
42+
alert_notify_type = var.alert_notify_type
43+
prometheus_type = "alert"
44+
2645
}

examples/complete/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "this_prometheus_alert_rule" {
2+
description = "The alert rule ID of prometheus."
3+
value = module.example.this_prometheus_alert_rule
4+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#alicloud_arms_alert_contact
2+
alert_contact_name = "update-tf-testacc-user"
3+
4+
5+
#alicloud_arms_alert_contact_group
6+
alert_contact_group_name = "update-tf-testacc-group"
7+
8+
#alicloud_arms_dispatch_rule
9+
dispatch_rule_name = "update-tf-testacc-rule"
10+
dispatch_type = "DISCARD_ALERT"
11+
group_wait_time = 20
12+
group_interval = 20
13+
repeat_interval = 20
14+
grouping_fields = ["alertname"]
15+
match_expressions = [
16+
{
17+
key = "_aliyun_arms_alert_name",
18+
value = "update-tf-testacc-app",
19+
operator = "eq"
20+
}
21+
]
22+
notify_type = "ARMS_CONTACT"
23+
notification_name = "update-tf-testacc-notification"
24+
notify_channels = ["email"]
25+
26+
#alicloud_arms_prometheus_alert_rule
27+
alert_notify_type = "DISPATCH_RULE"

examples/complete/variables.tf

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#alicloud_arms_alert_contact
2+
variable "alert_contact_name" {
3+
description = "The name of the alert contact."
4+
type = string
5+
default = "tf-testacc-user"
6+
}
7+
8+
variable "email" {
9+
description = "The email address of the alert contact."
10+
type = string
11+
default = "[email protected]"
12+
}
13+
14+
#alicloud_arms_alert_contact_group
15+
variable "alert_contact_group_name" {
16+
description = "The name of arms contract group."
17+
type = string
18+
default = "tf-testacc-group"
19+
}
20+
21+
#alicloud_arms_dispatch_rule
22+
variable "dispatch_rule_name" {
23+
description = "The rule name of dispatch."
24+
type = string
25+
default = "tf-testacc-rule"
26+
}
27+
28+
variable "dispatch_type" {
29+
description = "The type of dispatch."
30+
type = string
31+
default = "CREATE_ALERT"
32+
}
33+
34+
variable "group_wait_time" {
35+
description = "The waiting time of arms contract group."
36+
type = number
37+
default = 10
38+
}
39+
40+
variable "group_interval" {
41+
description = "The interval time of arms contract group."
42+
type = number
43+
default = 10
44+
}
45+
46+
variable "repeat_interval" {
47+
description = "The repeat interval time of arms contract group."
48+
type = number
49+
default = 10
50+
}
51+
52+
variable "grouping_fields" {
53+
description = "The files of arms contract group."
54+
type = list(string)
55+
default = ["CreateDispatchRuleValue"]
56+
}
57+
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+
74+
variable "notify_type" {
75+
description = "The type of the alert contact. Valid values: ARMS_CONTACT: contact. ARMS_CONTACT_GROUP: contact group."
76+
type = string
77+
default = "ARMS_CONTACT_GROUP"
78+
}
79+
80+
variable "notification_name" {
81+
description = "The name of arms notification."
82+
type = string
83+
default = "tf-testacc-notification"
84+
}
85+
86+
variable "notify_channels" {
87+
description = "The name of arms notification."
88+
type = list(string)
89+
default = ["dingTalk"]
90+
}
91+
92+
#alicloud_arms_prometheus_alert_rule
93+
variable "alert_notify_type" {
94+
description = "The notify type of prometheus."
95+
type = string
96+
default = "ALERT_MANAGER"
97+
}

main.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ resource "alicloud_arms_dispatch_rule" "arms_dispatch_rule" {
2626
}
2727
}
2828
}
29-
3029
notify_rules {
3130
notify_objects {
3231
notify_object_id = alicloud_arms_alert_contact_group.arms_alert_contact_group.0.id
33-
notify_type = "ARMS_CONTACT_GROUP"
32+
notify_type = var.notify_type
3433
name = var.notification_name
3534
}
3635
notify_channels = var.notify_channels
@@ -43,7 +42,7 @@ resource "alicloud_arms_prometheus_alert_rule" "arms_prometheus_alert_rule" {
4342
cluster_id = var.cluster_id
4443
expression = var.alert_expression
4544
message = var.alert_message
46-
duration = 1
45+
duration = var.alert_duration
4746
notify_type = var.alert_notify_type
4847
dispatch_rule_id = alicloud_arms_dispatch_rule.arms_dispatch_rule.0.id
4948
type = var.prometheus_type

0 commit comments

Comments
 (0)