Skip to content

Commit 4b15e17

Browse files
gitmknanonymous
andauthored
Fix/monitor doc (#1994)
* fix: modify monitor doc * fix: modify monitor doc * fix: modify monitor tke doc * fix: modify doc --------- Co-authored-by: anonymous <anonymous@mail.org>
1 parent 323d58a commit 4b15e17

File tree

37 files changed

+3434
-190
lines changed

37 files changed

+3434
-190
lines changed
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
# create tke
2+
variable "default_instance_type" {
3+
default = "SA1.MEDIUM2"
4+
}
5+
6+
variable "availability_zone_first" {
7+
default = "ap-guangzhou-3"
8+
}
9+
10+
variable "availability_zone_second" {
11+
default = "ap-guangzhou-4"
12+
}
13+
14+
variable "example_cluster_cidr" {
15+
default = "10.31.0.0/16"
16+
}
17+
18+
locals {
19+
first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id
20+
first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id
21+
second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id
22+
second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id
23+
sg_id = tencentcloud_security_group.sg.id
24+
image_id = data.tencentcloud_images.default.image_id
25+
}
26+
27+
data "tencentcloud_vpc_subnets" "vpc_one" {
28+
is_default = true
29+
availability_zone = var.availability_zone_first
30+
}
31+
32+
data "tencentcloud_vpc_subnets" "vpc_two" {
33+
is_default = true
34+
availability_zone = var.availability_zone_second
35+
}
36+
37+
resource "tencentcloud_security_group" "sg" {
38+
name = "tf-example-sg"
39+
}
40+
41+
resource "tencentcloud_security_group_lite_rule" "sg_rule" {
42+
security_group_id = tencentcloud_security_group.sg.id
43+
44+
ingress = [
45+
"ACCEPT#10.0.0.0/16#ALL#ALL",
46+
"ACCEPT#172.16.0.0/22#ALL#ALL",
47+
"DROP#0.0.0.0/0#ALL#ALL",
48+
]
49+
50+
egress = [
51+
"ACCEPT#172.16.0.0/22#ALL#ALL",
52+
]
53+
}
54+
55+
data "tencentcloud_images" "default" {
56+
image_type = ["PUBLIC_IMAGE"]
57+
image_name_regex = "Final"
58+
}
59+
60+
resource "tencentcloud_kubernetes_cluster" "example" {
61+
vpc_id = local.first_vpc_id
62+
cluster_cidr = var.example_cluster_cidr
63+
cluster_max_pod_num = 32
64+
cluster_name = "tf_example_cluster"
65+
cluster_desc = "example for tke cluster"
66+
cluster_max_service_num = 32
67+
cluster_internet = false
68+
cluster_internet_security_group = local.sg_id
69+
cluster_version = "1.22.5"
70+
cluster_deploy_type = "MANAGED_CLUSTER"
71+
72+
worker_config {
73+
count = 1
74+
availability_zone = var.availability_zone_first
75+
instance_type = var.default_instance_type
76+
system_disk_type = "CLOUD_SSD"
77+
system_disk_size = 60
78+
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
79+
internet_max_bandwidth_out = 100
80+
public_ip_assigned = true
81+
subnet_id = local.first_subnet_id
82+
img_id = local.image_id
83+
84+
data_disk {
85+
disk_type = "CLOUD_PREMIUM"
86+
disk_size = 50
87+
}
88+
89+
enhanced_security_service = false
90+
enhanced_monitor_service = false
91+
user_data = "dGVzdA=="
92+
# key_ids = ["skey-11112222"]
93+
password = "ZZXXccvv1212" // Optional, should be set if key_ids not set.
94+
}
95+
96+
worker_config {
97+
count = 1
98+
availability_zone = var.availability_zone_second
99+
instance_type = var.default_instance_type
100+
system_disk_type = "CLOUD_SSD"
101+
system_disk_size = 60
102+
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
103+
internet_max_bandwidth_out = 100
104+
public_ip_assigned = true
105+
subnet_id = local.second_subnet_id
106+
107+
data_disk {
108+
disk_type = "CLOUD_PREMIUM"
109+
disk_size = 50
110+
}
111+
112+
enhanced_security_service = false
113+
enhanced_monitor_service = false
114+
user_data = "dGVzdA=="
115+
# key_ids = ["skey-11112222"]
116+
cam_role_name = "CVM_QcsRole"
117+
password = "ZZXXccvv1212" // Optional, should be set if key_ids not set.
118+
}
119+
120+
labels = {
121+
"test1" = "test1",
122+
"test2" = "test2",
123+
}
124+
}
125+
126+
127+
# create monitor
128+
variable "zone" {
129+
default = "ap-guangzhou"
130+
}
131+
132+
variable "cluster_type" {
133+
default = "tke"
134+
}
135+
136+
resource "tencentcloud_monitor_tmp_instance" "foo" {
137+
instance_name = "tf-tmp-instance"
138+
vpc_id = local.first_vpc_id
139+
subnet_id = local.first_subnet_id
140+
data_retention_time = 30
141+
zone = var.availability_zone_second
142+
tags = {
143+
"createdBy" = "terraform"
144+
}
145+
}
146+
147+
148+
# tmp tke bind
149+
resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" {
150+
instance_id = tencentcloud_monitor_tmp_instance.foo.id
151+
152+
agents {
153+
region = var.zone
154+
cluster_type = var.cluster_type
155+
cluster_id = tencentcloud_kubernetes_cluster.example.id
156+
enable_external = false
157+
}
158+
}
159+
160+
# create monitor template
161+
resource "tencentcloud_monitor_tmp_tke_template" "foo" {
162+
template {
163+
name = "tf-template"
164+
level = "cluster"
165+
describe = "template"
166+
service_monitors {
167+
name = "tf-ServiceMonitor"
168+
config = <<-EOT
169+
apiVersion: monitoring.coreos.com/v1
170+
kind: ServiceMonitor
171+
metadata:
172+
name: example-service-monitor
173+
namespace: monitoring
174+
labels:
175+
k8s-app: example-service
176+
spec:
177+
selector:
178+
matchLabels:
179+
k8s-app: example-service
180+
namespaceSelector:
181+
matchNames:
182+
- default
183+
endpoints:
184+
- port: http-metrics
185+
interval: 30s
186+
path: /metrics
187+
scheme: http
188+
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
189+
tlsConfig:
190+
insecureSkipVerify: true
191+
EOT
192+
}
193+
194+
pod_monitors {
195+
name = "tf-PodMonitors"
196+
config = <<-EOT
197+
apiVersion: monitoring.coreos.com/v1
198+
kind: PodMonitor
199+
metadata:
200+
name: example-pod-monitor
201+
namespace: monitoring
202+
labels:
203+
k8s-app: example-pod
204+
spec:
205+
selector:
206+
matchLabels:
207+
k8s-app: example-pod
208+
namespaceSelector:
209+
matchNames:
210+
- default
211+
podMetricsEndpoints:
212+
- port: http-metrics
213+
interval: 30s
214+
path: /metrics
215+
scheme: http
216+
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
217+
tlsConfig:
218+
insecureSkipVerify: true
219+
EOT
220+
}
221+
222+
pod_monitors {
223+
name = "tf-RawJobs"
224+
config = <<-EOT
225+
scrape_configs:
226+
- job_name: 'example-job'
227+
scrape_interval: 30s
228+
static_configs:
229+
- targets: ['example-service.default.svc.cluster.local:8080']
230+
metrics_path: /metrics
231+
scheme: http
232+
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
233+
tls_config:
234+
insecure_skip_verify: true
235+
EOT
236+
}
237+
}
238+
}
239+
240+
resource "tencentcloud_monitor_tmp_tke_template_attachment" "temp_attachment" {
241+
template_id = tencentcloud_monitor_tmp_tke_template.foo.id
242+
243+
targets {
244+
cluster_type = var.cluster_type
245+
cluster_id = tencentcloud_kubernetes_cluster.example.id
246+
region = var.zone
247+
instance_id = tencentcloud_monitor_tmp_instance.foo.id
248+
}
249+
250+
depends_on = [tencentcloud_monitor_tmp_tke_cluster_agent.foo]
251+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform {
2+
required_version = ">= 0.12"
3+
}
Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
1-
data "tencentcloud_cam_groups" "groups" {
2-
//You should first create a user group with CAM
1+
variable "availability_zone" {
2+
default = "ap-guangzhou-4"
33
}
4-
data "tencentcloud_instances" "instances" {
4+
5+
resource "tencentcloud_vpc" "vpc" {
6+
cidr_block = "10.0.0.0/16"
7+
name = "tf_monitor_vpc"
58
}
69

7-
resource "tencentcloud_monitor_policy_group" "group" {
8-
group_name = "nice_group"
9-
policy_view_name = "cvm_device"
10-
remark = "this is a test policy group"
11-
conditions {
12-
metric_id = 33
13-
alarm_notify_type = 1
14-
alarm_notify_period = 600
15-
calc_type = 1
16-
calc_value = 3
17-
calc_period = 300
18-
continue_period = 2
19-
}
10+
resource "tencentcloud_subnet" "subnet" {
11+
vpc_id = tencentcloud_vpc.vpc.id
12+
availability_zone = var.availability_zone
13+
name = "tf_monitor_subnet"
14+
cidr_block = "10.0.1.0/24"
2015
}
2116

22-
#for cvm
23-
resource "tencentcloud_monitor_binding_object" "binding" {
24-
group_id = tencentcloud_monitor_policy_group.group.id
25-
dimensions {
26-
dimensions_json = "{\"unInstanceId\":\"${data.tencentcloud_instances.instances.instance_list[0].instance_id}\"}"
17+
18+
resource "tencentcloud_monitor_tmp_instance" "foo" {
19+
instance_name = "tf-tmp-instance"
20+
vpc_id = tencentcloud_vpc.vpc.id
21+
subnet_id = tencentcloud_subnet.subnet.id
22+
data_retention_time = 30
23+
zone = var.availability_zone
24+
tags = {
25+
"createdBy" = "terraform"
2726
}
2827
}
2928

30-
resource "tencentcloud_monitor_binding_receiver" "receiver" {
31-
group_id = tencentcloud_monitor_policy_group.group.id
32-
receivers {
33-
start_time = 0
34-
end_time = 86399
35-
notify_way = ["SMS"]
36-
receiver_type = "group"
37-
receiver_group_list = [data.tencentcloud_cam_groups.groups.group_list[0].group_id]
38-
receive_language = "en-US"
29+
resource "tencentcloud_monitor_grafana_instance" "foo" {
30+
instance_name = "tf-grafana"
31+
vpc_id = tencentcloud_vpc.vpc.id
32+
subnet_ids = [tencentcloud_subnet.subnet.id]
33+
grafana_init_password = "1234567890"
34+
enable_internet = false
35+
is_destroy = true
36+
37+
tags = {
38+
"createdBy" = "test"
3939
}
4040
}
41+
42+
resource "tencentcloud_monitor_tmp_manage_grafana_attachment" "foo" {
43+
grafana_id = tencentcloud_monitor_grafana_instance.foo.id
44+
instance_id = tencentcloud_monitor_tmp_instance.foo.id
45+
}

tencentcloud/resource_tc_monitor_alarm_notice.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Provides a alarm notice resource for monitor.
44
Example Usage
55
66
```hcl
7-
resource "tencentcloud_monitor_alarm_notice" "example" {
8-
name = "test_alarm_notice_1"
7+
resource "tencentcloud_monitor_alarm_notice" "foo" {
8+
name = "tf-alarm_notice"
99
notice_type = "ALL"
1010
notice_language = "zh-CN"
1111

tencentcloud/resource_tc_monitor_alarm_policy.go

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,41 @@ Example Usage
66
cvm_device alarm policy
77
88
```hcl
9-
resource "tencentcloud_monitor_alarm_policy" "group" {
10-
policy_name = "hello"
9+
resource "tencentcloud_monitor_alarm_notice" "foo" {
10+
name = "tf-alarm_notice"
11+
notice_type = "ALL"
12+
notice_language = "zh-CN"
13+
14+
user_notices {
15+
receiver_type = "USER"
16+
start_time = 0
17+
end_time = 1
18+
notice_way = ["SMS","EMAIL"]
19+
user_ids = [10001]
20+
group_ids = []
21+
phone_order = [10001]
22+
phone_circle_times = 2
23+
phone_circle_interval = 50
24+
phone_inner_interval = 60
25+
need_phone_arrive_notice = 1
26+
phone_call_type = "CIRCLE"
27+
weekday =[1,2,3,4,5,6,7]
28+
}
29+
30+
url_notices {
31+
url = "https://www.mytest.com/validate"
32+
end_time = 0
33+
start_time = 1
34+
weekday = [1,2,3,4,5,6,7]
35+
}
36+
37+
}
38+
39+
resource "tencentcloud_monitor_alarm_policy" "foo" {
40+
policy_name = "tf-policy"
1141
monitor_type = "MT_QCE"
1242
enable = 1
13-
project_id = 1244035
43+
project_id = 0
1444
namespace = "cvm_device"
1545
conditions {
1646
is_union_rule = 1
@@ -30,7 +60,7 @@ resource "tencentcloud_monitor_alarm_policy" "group" {
3060
event_conditions {
3161
metric_name = "guest_reboot"
3262
}
33-
notice_ids = ["notice-l9ziyxw6"]
63+
notice_ids = [tencentcloud_monitor_alarm_notice.foo.id]
3464
3565
trigger_tasks {
3666
type = "AS"

0 commit comments

Comments
 (0)