From 9d48d7aef41fa61426bbc6c22c4b64ab9874dfc1 Mon Sep 17 00:00:00 2001 From: anonymous Date: Sun, 30 Jul 2023 15:39:44 +0800 Subject: [PATCH 1/4] fix: modify monitor doc --- .../resource_tc_monitor_alarm_notice.go | 4 +- .../resource_tc_monitor_alarm_policy.go | 38 +++++++++-- .../resource_tc_monitor_tmp_alert_rule.go | 68 +++++++++++++++---- .../resource_tc_monitor_tmp_cvm_agent.go | 34 +++++++++- .../resource_tc_monitor_tmp_grafana_config.go | 49 ++++++++++--- .../resource_tc_monitor_tmp_instance.go | 27 ++++++-- ...c_monitor_tmp_manage_grafana_attachment.go | 47 ++++++++++++- .../resource_tc_monitor_tmp_recording_rule.go | 36 ++++++++-- .../resource_tc_monitor_tmp_scrape_job.go | 41 +++++++++-- .../docs/r/monitor_alarm_notice.html.markdown | 4 +- .../docs/r/monitor_alarm_policy.html.markdown | 38 +++++++++-- .../r/monitor_tmp_alert_rule.html.markdown | 61 ++++++++++++++--- .../r/monitor_tmp_cvm_agent.html.markdown | 33 ++++++++- .../monitor_tmp_grafana_config.html.markdown | 31 ++++++++- .../docs/r/monitor_tmp_instance.html.markdown | 26 +++++-- ...mp_manage_grafana_attachment.html.markdown | 46 ++++++++++++- .../monitor_tmp_recording_rule.html.markdown | 34 +++++++++- .../r/monitor_tmp_scrape_job.html.markdown | 38 ++++++++++- 18 files changed, 571 insertions(+), 84 deletions(-) diff --git a/tencentcloud/resource_tc_monitor_alarm_notice.go b/tencentcloud/resource_tc_monitor_alarm_notice.go index f726a395b5..8f680c7b67 100644 --- a/tencentcloud/resource_tc_monitor_alarm_notice.go +++ b/tencentcloud/resource_tc_monitor_alarm_notice.go @@ -4,8 +4,8 @@ Provides a alarm notice resource for monitor. Example Usage ```hcl -resource "tencentcloud_monitor_alarm_notice" "example" { - name = "test_alarm_notice_1" +resource "tencentcloud_monitor_alarm_notice" "foo" { + name = "tf-alarm_notice" notice_type = "ALL" notice_language = "zh-CN" diff --git a/tencentcloud/resource_tc_monitor_alarm_policy.go b/tencentcloud/resource_tc_monitor_alarm_policy.go index 09e93923f6..676c5db3d0 100644 --- a/tencentcloud/resource_tc_monitor_alarm_policy.go +++ b/tencentcloud/resource_tc_monitor_alarm_policy.go @@ -6,11 +6,41 @@ Example Usage cvm_device alarm policy ```hcl -resource "tencentcloud_monitor_alarm_policy" "group" { - policy_name = "hello" +resource "tencentcloud_monitor_alarm_notice" "foo" { + name = "tf-alarm_notice" + notice_type = "ALL" + notice_language = "zh-CN" + + user_notices { + receiver_type = "USER" + start_time = 0 + end_time = 1 + notice_way = ["SMS","EMAIL"] + user_ids = [10001] + group_ids = [] + phone_order = [10001] + phone_circle_times = 2 + phone_circle_interval = 50 + phone_inner_interval = 60 + need_phone_arrive_notice = 1 + phone_call_type = "CIRCLE" + weekday =[1,2,3,4,5,6,7] + } + + url_notices { + url = "https://www.mytest.com/validate" + end_time = 0 + start_time = 1 + weekday = [1,2,3,4,5,6,7] + } + +} + +resource "tencentcloud_monitor_alarm_policy" "foo" { + policy_name = "tf-policy" monitor_type = "MT_QCE" enable = 1 - project_id = 1244035 + project_id = 0 namespace = "cvm_device" conditions { is_union_rule = 1 @@ -30,7 +60,7 @@ resource "tencentcloud_monitor_alarm_policy" "group" { event_conditions { metric_name = "guest_reboot" } - notice_ids = ["notice-l9ziyxw6"] + notice_ids = [tencentcloud_monitor_alarm_notice.foo.id] trigger_tasks { type = "AS" diff --git a/tencentcloud/resource_tc_monitor_tmp_alert_rule.go b/tencentcloud/resource_tc_monitor_tmp_alert_rule.go index b7afdf0022..24c6661867 100644 --- a/tencentcloud/resource_tc_monitor_tmp_alert_rule.go +++ b/tencentcloud/resource_tc_monitor_tmp_alert_rule.go @@ -4,23 +4,63 @@ Provides a resource to create a monitor tmpAlertRule Example Usage ```hcl -resource "tencentcloud_monitor_tmp_alert_rule" "tmpAlertRule" { - instance_id = "prom-c89b3b3u" - rule_name = "test123" - expr = "up{service=\"rig-prometheus-agent\"}>0" - receivers = ["notice-l9ziyxw6"] - rule_state = 2 - duration = "4m" - labels { - key = "hello1" - value = "world1" - } - annotations { - key = "hello2" - value = "world2" +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" } } +resource "tencentcloud_monitor_tmp_cvm_agent" "foo" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + name = "tf-agent" +} + +resource "tencentcloud_monitor_tmp_alert_rule" "foo" { + duration = "2m" + expr = "avg by (instance) (mysql_global_status_threads_connected) / avg by (instance) (mysql_global_variables_max_connections) > 0.8" + instance_id = tencentcloud_monitor_tmp_instance.foo.id + receivers = ["notice-f2svbu3w"] + rule_name = "MySQL 连接数过多" + rule_state = 2 + type = "MySQL/MySQL 连接数过多" + + annotations { + key = "description" + value = "MySQL 连接数过多, 实例: {{$labels.instance}},当前值: {{ $value | humanizePercentage }}。" + } + annotations { + key = "summary" + value = "MySQL 连接数过多(>80%)" + } + + labels { + key = "severity" + value = "warning" + } +} + ``` Import diff --git a/tencentcloud/resource_tc_monitor_tmp_cvm_agent.go b/tencentcloud/resource_tc_monitor_tmp_cvm_agent.go index 6fb46d62d5..0a4d47c8b9 100644 --- a/tencentcloud/resource_tc_monitor_tmp_cvm_agent.go +++ b/tencentcloud/resource_tc_monitor_tmp_cvm_agent.go @@ -4,9 +4,37 @@ Provides a resource to create a monitor tmpCvmAgent Example Usage ```hcl -resource "tencentcloud_monitor_tmp_cvm_agent" "tmpCvmAgent" { - instance_id = "prom-dko9d0nu" - name = "agent" +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +resource "tencentcloud_monitor_tmp_cvm_agent" "foo" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + name = "tf-agent" } ``` diff --git a/tencentcloud/resource_tc_monitor_tmp_grafana_config.go b/tencentcloud/resource_tc_monitor_tmp_grafana_config.go index 46b201dc3a..8ba30397b9 100644 --- a/tencentcloud/resource_tc_monitor_tmp_grafana_config.go +++ b/tencentcloud/resource_tc_monitor_tmp_grafana_config.go @@ -4,17 +4,46 @@ Provides a resource to create a monitor tmp_grafana_config Example Usage ```hcl +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_grafana_instance" "foo" { + instance_name = "tf-grafana" + vpc_id = tencentcloud_vpc.vpc.id + subnet_ids = [tencentcloud_subnet.subnet.id] + grafana_init_password = "1234567890" + enable_internet = false + is_destroy = true + + tags = { + "createdBy" = "test" + } +} + resource "tencentcloud_monitor_tmp_grafana_config" "tmp_grafana_config" { - config = jsonencode( - { - server = { - http_port = 8080 - root_url = "https://cloud-grafana.woa.com/grafana-ffrdnrfa/" - serve_from_sub_path = true - } - } - ) - instance_id = "grafana-29phe08q" + config = jsonencode( + { + server = { + http_port = 8080 + root_url = "https://cloud-grafana.woa.com/grafana-ffrdnrfa/" + serve_from_sub_path = true + } + } + ) + instance_id = tencentcloud_monitor_grafana_instance.foo.id } ``` diff --git a/tencentcloud/resource_tc_monitor_tmp_instance.go b/tencentcloud/resource_tc_monitor_tmp_instance.go index 06e29e3188..037b3817c5 100644 --- a/tencentcloud/resource_tc_monitor_tmp_instance.go +++ b/tencentcloud/resource_tc_monitor_tmp_instance.go @@ -4,12 +4,29 @@ Provides a resource to create a monitor tmpInstance Example Usage ```hcl -resource "tencentcloud_monitor_tmp_instance" "tmpInstance" { - instance_name = "demo" - vpc_id = "vpc-2hfyray3" - subnet_id = "subnet-rdkj0agk" +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id data_retention_time = 30 - zone = "ap-guangzhou-3" + zone = var.availability_zone tags = { "createdBy" = "terraform" } diff --git a/tencentcloud/resource_tc_monitor_tmp_manage_grafana_attachment.go b/tencentcloud/resource_tc_monitor_tmp_manage_grafana_attachment.go index 38d1192f4a..73bf614599 100644 --- a/tencentcloud/resource_tc_monitor_tmp_manage_grafana_attachment.go +++ b/tencentcloud/resource_tc_monitor_tmp_manage_grafana_attachment.go @@ -4,9 +4,50 @@ Provides a resource to create a monitor tmp_manage_grafana_attachment Example Usage ```hcl -resource "tencentcloud_monitor_tmp_manage_grafana_attachment" "manage_grafana_attachment" { - grafana_id = "grafana-xxxxxx" - instance_id = "prom-xxxxxxxx" +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +resource "tencentcloud_monitor_grafana_instance" "foo" { + instance_name = "tf-grafana" + vpc_id = tencentcloud_vpc.vpc.id + subnet_ids = [tencentcloud_subnet.subnet.id] + grafana_init_password = "1234567890" + enable_internet = false + is_destroy = true + + tags = { + "createdBy" = "test" + } +} + +resource "tencentcloud_monitor_tmp_manage_grafana_attachment" "foo" { + grafana_id = tencentcloud_monitor_grafana_instance.foo.id + instance_id = tencentcloud_monitor_tmp_instance.foo.id } ``` diff --git a/tencentcloud/resource_tc_monitor_tmp_recording_rule.go b/tencentcloud/resource_tc_monitor_tmp_recording_rule.go index 7497579e16..7ae11fe334 100644 --- a/tencentcloud/resource_tc_monitor_tmp_recording_rule.go +++ b/tencentcloud/resource_tc_monitor_tmp_recording_rule.go @@ -4,17 +4,45 @@ Provides a resource to create a monitor tmp recordingRule Example Usage ```hcl +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + resource "tencentcloud_monitor_tmp_recording_rule" "recordingRule" { - name = "dasdasdsadasd" - group = <0" - receivers = ["notice-l9ziyxw6"] +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +resource "tencentcloud_monitor_tmp_cvm_agent" "foo" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + name = "tf-agent" +} + +resource "tencentcloud_monitor_tmp_alert_rule" "foo" { + duration = "2m" + expr = "avg by (instance) (mysql_global_status_threads_connected) / avg by (instance) (mysql_global_variables_max_connections) > 0.8" + instance_id = tencentcloud_monitor_tmp_instance.foo.id + receivers = ["notice-f2svbu3w"] + rule_name = "MySQL 连接数过多" rule_state = 2 - duration = "4m" - labels { - key = "hello1" - value = "world1" + type = "MySQL/MySQL 连接数过多" + + annotations { + key = "description" + value = "MySQL 连接数过多, 实例: {{$labels.instance}},当前值: {{ $value | humanizePercentage }}。" } annotations { - key = "hello2" - value = "world2" + key = "summary" + value = "MySQL 连接数过多(>80%)" + } + + labels { + key = "severity" + value = "warning" } } ``` diff --git a/website/docs/r/monitor_tmp_cvm_agent.html.markdown b/website/docs/r/monitor_tmp_cvm_agent.html.markdown index 8cb679f72c..0450010868 100644 --- a/website/docs/r/monitor_tmp_cvm_agent.html.markdown +++ b/website/docs/r/monitor_tmp_cvm_agent.html.markdown @@ -14,9 +14,36 @@ Provides a resource to create a monitor tmpCvmAgent ## Example Usage ```hcl -resource "tencentcloud_monitor_tmp_cvm_agent" "tmpCvmAgent" { - instance_id = "prom-dko9d0nu" - name = "agent" +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +resource "tencentcloud_monitor_tmp_cvm_agent" "foo" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + name = "tf-agent" } ``` diff --git a/website/docs/r/monitor_tmp_grafana_config.html.markdown b/website/docs/r/monitor_tmp_grafana_config.html.markdown index 38a2138919..2cb3a03b38 100644 --- a/website/docs/r/monitor_tmp_grafana_config.html.markdown +++ b/website/docs/r/monitor_tmp_grafana_config.html.markdown @@ -14,6 +14,35 @@ Provides a resource to create a monitor tmp_grafana_config ## Example Usage ```hcl +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_grafana_instance" "foo" { + instance_name = "tf-grafana" + vpc_id = tencentcloud_vpc.vpc.id + subnet_ids = [tencentcloud_subnet.subnet.id] + grafana_init_password = "1234567890" + enable_internet = false + is_destroy = true + + tags = { + "createdBy" = "test" + } +} + resource "tencentcloud_monitor_tmp_grafana_config" "tmp_grafana_config" { config = jsonencode( { @@ -24,7 +53,7 @@ resource "tencentcloud_monitor_tmp_grafana_config" "tmp_grafana_config" { } } ) - instance_id = "grafana-29phe08q" + instance_id = tencentcloud_monitor_grafana_instance.foo.id } ``` diff --git a/website/docs/r/monitor_tmp_instance.html.markdown b/website/docs/r/monitor_tmp_instance.html.markdown index d61d502748..24f32a4f28 100644 --- a/website/docs/r/monitor_tmp_instance.html.markdown +++ b/website/docs/r/monitor_tmp_instance.html.markdown @@ -14,12 +14,28 @@ Provides a resource to create a monitor tmpInstance ## Example Usage ```hcl -resource "tencentcloud_monitor_tmp_instance" "tmpInstance" { - instance_name = "demo" - vpc_id = "vpc-2hfyray3" - subnet_id = "subnet-rdkj0agk" +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id data_retention_time = 30 - zone = "ap-guangzhou-3" + zone = var.availability_zone tags = { "createdBy" = "terraform" } diff --git a/website/docs/r/monitor_tmp_manage_grafana_attachment.html.markdown b/website/docs/r/monitor_tmp_manage_grafana_attachment.html.markdown index 4c941621ad..4feb89c570 100644 --- a/website/docs/r/monitor_tmp_manage_grafana_attachment.html.markdown +++ b/website/docs/r/monitor_tmp_manage_grafana_attachment.html.markdown @@ -14,9 +14,49 @@ Provides a resource to create a monitor tmp_manage_grafana_attachment ## Example Usage ```hcl -resource "tencentcloud_monitor_tmp_manage_grafana_attachment" "manage_grafana_attachment" { - grafana_id = "grafana-xxxxxx" - instance_id = "prom-xxxxxxxx" +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +resource "tencentcloud_monitor_grafana_instance" "foo" { + instance_name = "tf-grafana" + vpc_id = tencentcloud_vpc.vpc.id + subnet_ids = [tencentcloud_subnet.subnet.id] + grafana_init_password = "1234567890" + enable_internet = false + is_destroy = true + + tags = { + "createdBy" = "test" + } +} + +resource "tencentcloud_monitor_tmp_manage_grafana_attachment" "foo" { + grafana_id = tencentcloud_monitor_grafana_instance.foo.id + instance_id = tencentcloud_monitor_tmp_instance.foo.id } ``` diff --git a/website/docs/r/monitor_tmp_recording_rule.html.markdown b/website/docs/r/monitor_tmp_recording_rule.html.markdown index 5cbb68d5d3..c40f9ceeae 100644 --- a/website/docs/r/monitor_tmp_recording_rule.html.markdown +++ b/website/docs/r/monitor_tmp_recording_rule.html.markdown @@ -14,8 +14,37 @@ Provides a resource to create a monitor tmp recordingRule ## Example Usage ```hcl +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + resource "tencentcloud_monitor_tmp_recording_rule" "recordingRule" { - name = "dasdasdsadasd" + instance_id = tencentcloud_monitor_tmp_instance.foo.id + rule_state = 2 + name = "tf-recording-rule" group = < Date: Sun, 30 Jul 2023 15:44:12 +0800 Subject: [PATCH 2/4] fix: modify monitor doc --- examples/tencentcloud-monitor/main.tf | 65 ++++++++++--------- .../resource_tc_monitor_tmp_grafana_config.go | 2 +- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/examples/tencentcloud-monitor/main.tf b/examples/tencentcloud-monitor/main.tf index a4de0bf827..d7687c167b 100644 --- a/examples/tencentcloud-monitor/main.tf +++ b/examples/tencentcloud-monitor/main.tf @@ -1,40 +1,45 @@ -data "tencentcloud_cam_groups" "groups" { - //You should first create a user group with CAM +variable "availability_zone" { + default = "ap-guangzhou-4" } -data "tencentcloud_instances" "instances" { + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" } -resource "tencentcloud_monitor_policy_group" "group" { - group_name = "nice_group" - policy_view_name = "cvm_device" - remark = "this is a test policy group" - conditions { - metric_id = 33 - alarm_notify_type = 1 - alarm_notify_period = 600 - calc_type = 1 - calc_value = 3 - calc_period = 300 - continue_period = 2 - } +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" } -#for cvm -resource "tencentcloud_monitor_binding_object" "binding" { - group_id = tencentcloud_monitor_policy_group.group.id - dimensions { - dimensions_json = "{\"unInstanceId\":\"${data.tencentcloud_instances.instances.instance_list[0].instance_id}\"}" + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" } } -resource "tencentcloud_monitor_binding_receiver" "receiver" { - group_id = tencentcloud_monitor_policy_group.group.id - receivers { - start_time = 0 - end_time = 86399 - notify_way = ["SMS"] - receiver_type = "group" - receiver_group_list = [data.tencentcloud_cam_groups.groups.group_list[0].group_id] - receive_language = "en-US" +resource "tencentcloud_monitor_grafana_instance" "foo" { + instance_name = "tf-grafana" + vpc_id = tencentcloud_vpc.vpc.id + subnet_ids = [tencentcloud_subnet.subnet.id] + grafana_init_password = "1234567890" + enable_internet = false + is_destroy = true + + tags = { + "createdBy" = "test" } } + +resource "tencentcloud_monitor_tmp_manage_grafana_attachment" "foo" { + grafana_id = tencentcloud_monitor_grafana_instance.foo.id + instance_id = tencentcloud_monitor_tmp_instance.foo.id +} \ No newline at end of file diff --git a/tencentcloud/resource_tc_monitor_tmp_grafana_config.go b/tencentcloud/resource_tc_monitor_tmp_grafana_config.go index 8ba30397b9..b901057ed1 100644 --- a/tencentcloud/resource_tc_monitor_tmp_grafana_config.go +++ b/tencentcloud/resource_tc_monitor_tmp_grafana_config.go @@ -33,7 +33,7 @@ resource "tencentcloud_monitor_grafana_instance" "foo" { } } -resource "tencentcloud_monitor_tmp_grafana_config" "tmp_grafana_config" { +resource "tencentcloud_monitor_tmp_grafana_config" "foo" { config = jsonencode( { server = { From 4da5e06349a374f870725605062da8911faf3483 Mon Sep 17 00:00:00 2001 From: anonymous Date: Sun, 30 Jul 2023 19:13:15 +0800 Subject: [PATCH 3/4] fix: modify monitor tke doc --- examples/tencentcloud-monitor-tke/main.tf | 286 ++++++++++++++++++ examples/tencentcloud-monitor-tke/version.tf | 3 + ...esource_tc_monitor_tmp_tke_alert_policy.go | 47 ++- ...esource_tc_monitor_tmp_tke_basic_config.go | 182 ++++++++++- ...source_tc_monitor_tmp_tke_cluster_agent.go | 176 ++++++++++- .../resource_tc_monitor_tmp_tke_config.go | 182 ++++++++++- ..._tc_monitor_tmp_tke_global_notification.go | 36 ++- ...rce_tc_monitor_tmp_tke_record_rule_yaml.go | 35 ++- .../resource_tc_monitor_tmp_tke_template.go | 82 ++++- ..._tc_monitor_tmp_tke_template_attachment.go | 262 +++++++++++++++- .../monitor_tmp_grafana_config.html.markdown | 2 +- ...monitor_tmp_tke_alert_policy.html.markdown | 35 ++- ...monitor_tmp_tke_basic_config.html.markdown | 179 ++++++++++- ...onitor_tmp_tke_cluster_agent.html.markdown | 166 +++++++++- .../r/monitor_tmp_tke_config.html.markdown | 179 ++++++++++- ..._tmp_tke_global_notification.html.markdown | 35 ++- ...tor_tmp_tke_record_rule_yaml.html.markdown | 35 ++- .../r/monitor_tmp_tke_template.html.markdown | 75 ++++- ..._tmp_tke_template_attachment.html.markdown | 259 +++++++++++++++- 19 files changed, 2204 insertions(+), 52 deletions(-) create mode 100644 examples/tencentcloud-monitor-tke/main.tf create mode 100644 examples/tencentcloud-monitor-tke/version.tf diff --git a/examples/tencentcloud-monitor-tke/main.tf b/examples/tencentcloud-monitor-tke/main.tf new file mode 100644 index 0000000000..397879eb2b --- /dev/null +++ b/examples/tencentcloud-monitor-tke/main.tf @@ -0,0 +1,286 @@ +# create tke +variable "default_instance_type" { + default = "SA1.MEDIUM2" +} + +variable "availability_zone_first" { + default = "ap-guangzhou-3" +} + +variable "availability_zone_second" { + default = "ap-guangzhou-4" +} + +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "cluster_type" { + default = "tke" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + + +# tmp tke bind +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + +resource "tencentcloud_monitor_tmp_tke_config" "foo" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + + raw_jobs { + name = "raw_jobs_001" + config = "your config for raw_jobs_001\n" + } + + service_monitors { + name = "kube-system/service-monitor-001" # name with default namespace kube-system + config = "apiVersion: monitoring.coreos.com/v1\nkind: ServiceMonitor\nmetadata:\n name: service-monitor-001\n namespace: kube-system\n" + } + + pod_monitors { + name = "mynamespace/pod-monitor-001" # name with the specified namespace + config = "apiVersion: monitoring.coreos.com/v1\nkind: PodMonitor\nmetadata:\n name: pod-monitor-001\n namespace: mynamespace\n" + } +} + + +# create monitor template +resource "tencentcloud_monitor_tmp_tke_template" "foo" { + template { + name = "tf-template" + level = "cluster" + describe = "template" + service_monitors { + name = "tf-ServiceMonitor" + config = <<-EOT +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: example-service-monitor + namespace: monitoring + labels: + k8s-app: example-service +spec: + selector: + matchLabels: + k8s-app: example-service + namespaceSelector: + matchNames: + - default + endpoints: + - port: http-metrics + interval: 30s + path: /metrics + scheme: http + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + insecureSkipVerify: true + EOT + } + + pod_monitors { + name = "tf-PodMonitors" + config = <<-EOT +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: example-pod-monitor + namespace: monitoring + labels: + k8s-app: example-pod +spec: + selector: + matchLabels: + k8s-app: example-pod + namespaceSelector: + matchNames: + - default + podMetricsEndpoints: + - port: http-metrics + interval: 30s + path: /metrics + scheme: http + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + insecureSkipVerify: true +EOT + } + + pod_monitors { + name = "tf-RawJobs" + config = <<-EOT +scrape_configs: + - job_name: 'example-job' + scrape_interval: 30s + static_configs: + - targets: ['example-service.default.svc.cluster.local:8080'] + metrics_path: /metrics + scheme: http + bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token + tls_config: + insecure_skip_verify: true +EOT + } + } +} + +resource "tencentcloud_monitor_tmp_tke_template_attachment" "temp_attachment" { + template_id = tencentcloud_monitor_tmp_tke_template.foo.id + + targets { + region = var.zone + instance_id = tencentcloud_monitor_tmp_instance.foo.id + } +} \ No newline at end of file diff --git a/examples/tencentcloud-monitor-tke/version.tf b/examples/tencentcloud-monitor-tke/version.tf new file mode 100644 index 0000000000..133d0d73e7 --- /dev/null +++ b/examples/tencentcloud-monitor-tke/version.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.12" +} \ No newline at end of file diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy.go b/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy.go index a5841a159a..fa18ccbef5 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy.go @@ -4,27 +4,60 @@ Provides a resource to create a tke tmpAlertPolicy Example Usage ```hcl +# create monitor +variable "cluster_type" { + default = "tke" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} +# create record rule resource "tencentcloud_monitor_tmp_tke_alert_policy" "basic" { - instance_id = "prom-xxxxxx" + instance_id = tencentcloud_monitor_tmp_instance.foo.id alert_rule { name = "alert_rule-test" rules { - name = "rules-test" - rule = "(count(kube_node_status_allocatable_cpu_cores) by (cluster) -1) / count(kube_node_status_allocatable_cpu_cores) by (cluster)" + name = "rules-test" + rule = "(count(kube_node_status_allocatable_cpu_cores) by (cluster) -1) / count(kube_node_status_allocatable_cpu_cores) by (cluster)" template = "The CPU requested by the Pod in the cluster {{ $labels.cluster }} is overloaded, and the current CPU application ratio is {{ $value | humanizePercentage }}" - for = "5m" + for = "5m" labels { name = "severity" value = "warning" } } notification { - type = "amp" + type = "amp" enabled = true alert_manager { - url = "xxx" - } + url = "xxx" + } } } } diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_basic_config.go b/tencentcloud/resource_tc_monitor_tmp_tke_basic_config.go index 720870a688..ff433ed091 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_basic_config.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_basic_config.go @@ -4,10 +4,186 @@ Provides a resource to create a monitor tmp_tke_basic_config Example Usage ```hcl +# create tke +variable "default_instance_type" { + default = "SA1.MEDIUM2" +} + +variable "availability_zone_first" { + default = "ap-guangzhou-3" +} + +variable "availability_zone_second" { + default = "ap-guangzhou-4" +} + +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + + +# tmp tke bind +variable "cluster_type" { + default = "tke" +} + +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + resource "tencentcloud_monitor_tmp_tke_basic_config" "tmp_tke_basic_config" { - instance_id = "prom-xxxxxx" - cluster_type = "eks" - cluster_id = "cls-xxxxxx" + instance_id = tencentcloud_monitor_tmp_instance.foo.id + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id name = "kube-system/kube-state-metrics" metrics_name = ["kube_job_status_succeeded"] } diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_cluster_agent.go b/tencentcloud/resource_tc_monitor_tmp_tke_cluster_agent.go index cc6a1cca95..8ad7a6561b 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_cluster_agent.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_cluster_agent.go @@ -4,14 +4,174 @@ Provides a resource to create a tmp tke cluster agent Example Usage ```hcl +# create tke +variable "default_instance_type" { + default = "SA1.MEDIUM2" +} + +variable "availability_zone_first" { + default = "ap-guangzhou-3" +} + +variable "availability_zone_second" { + default = "ap-guangzhou-4" +} + +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + + +# tmp tke bind resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { - instance_id = "prom-xxx" + instance_id = tencentcloud_monitor_tmp_instance.foo.id agents { - region = "ap-xxx" - cluster_type = "eks" - cluster_id = "cls-xxx" + region = var.zone + cluster_type = "tke" + cluster_id = tencentcloud_kubernetes_cluster.example.id enable_external = false } } @@ -286,7 +446,7 @@ func resourceTencentCloudMonitorTmpTkeClusterAgentCreate(d *schema.ResourceData, service := MonitorService{client: meta.(*TencentCloudClient).apiV3Conn} ctx := context.WithValue(context.TODO(), logIdKey, logId) - err = resource.Retry(2*readRetryTimeout, func() *resource.RetryError { + err = resource.Retry(10*readRetryTimeout, func() *resource.RetryError { clusterAgent, errRet := service.DescribeTmpTkeClusterAgentsById(ctx, instanceId, clusterId, clusterType) if errRet != nil { return retryError(errRet, InternalError) @@ -294,9 +454,9 @@ func resourceTencentCloudMonitorTmpTkeClusterAgentCreate(d *schema.ResourceData, if *clusterAgent.Status == "normal" { return nil } - if *clusterAgent.Status == "abnormal" { - return resource.NonRetryableError(fmt.Errorf("cluster agent status is %v, operate failed.", *clusterAgent.Status)) - } + // if *clusterAgent.Status == "abnormal" { + // return resource.NonRetryableError(fmt.Errorf("cluster agent status is %v, operate failed.", *clusterAgent.Status)) + // } return resource.RetryableError(fmt.Errorf("cluster agent status is %v, retry...", *clusterAgent.Status)) }) if err != nil { diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_config.go b/tencentcloud/resource_tc_monitor_tmp_tke_config.go index 8e9a29738f..cba5e75c41 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_config.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_config.go @@ -5,10 +5,186 @@ Example Usage ```hcl +# create tke +variable "default_instance_type" { + default = "SA1.MEDIUM2" +} + +variable "availability_zone_first" { + default = "ap-guangzhou-3" +} + +variable "availability_zone_second" { + default = "ap-guangzhou-4" +} + +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + + +# tmp tke bind +variable "cluster_type" { + default = "tke" +} + +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + resource "tencentcloud_monitor_tmp_tke_config" "foo" { - instance_id = "xxx" - cluster_type = "xxx" - cluster_id = "xxx" + instance_id = tencentcloud_monitor_tmp_instance.foo.id + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id raw_jobs { name = "raw_jobs_001" diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go b/tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go index 4f08e5c533..29d9b70cfa 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go @@ -4,8 +4,42 @@ Provides a resource to create a tmp tke global notification Example Usage ```hcl +# create monitor +variable "cluster_type" { + default = "tke" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +# create record rule resource "tencentcloud_monitor_tmp_tke_global_notification" "basic" { - instance_id = "prom-xxxxxx" + instance_id = tencentcloud_monitor_tmp_instance.foo.id notification { enabled = true type = "webhook" diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_record_rule_yaml.go b/tencentcloud/resource_tc_monitor_tmp_tke_record_rule_yaml.go index 65956515bb..09020b1e8c 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_record_rule_yaml.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_record_rule_yaml.go @@ -4,9 +4,42 @@ Provides a resource to create a tke tmpRecordRule Example Usage ```hcl +# create monitor +variable "cluster_type" { + default = "tke" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} +# create record rule resource "tencentcloud_monitor_tmp_tke_record_rule_yaml" "foo" { - instance_id = "" + instance_id = tencentcloud_monitor_tmp_instance.foo.id content = <<-EOT apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_template.go b/tencentcloud/resource_tc_monitor_tmp_tke_template.go index acc0ce535c..278759c60a 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_template.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_template.go @@ -4,14 +4,81 @@ Provides a resource to create a tmp tke template Example Usage ```hcl -resource "tencentcloud_monitor_tmp_tke_template" "template" { +resource "tencentcloud_monitor_tmp_tke_template" "foo" { template { - name = "test" - level = "cluster" + name = "tf-template" + level = "cluster" describe = "template" service_monitors { - name = "test" - config = "xxxxx" + name = "tf-ServiceMonitor" + config = <<-EOT +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: example-service-monitor + namespace: monitoring + labels: + k8s-app: example-service +spec: + selector: + matchLabels: + k8s-app: example-service + namespaceSelector: + matchNames: + - default + endpoints: + - port: http-metrics + interval: 30s + path: /metrics + scheme: http + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + insecureSkipVerify: true + EOT + } + + pod_monitors { + name = "tf-PodMonitors" + config = <<-EOT +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: example-pod-monitor + namespace: monitoring + labels: + k8s-app: example-pod +spec: + selector: + matchLabels: + k8s-app: example-pod + namespaceSelector: + matchNames: + - default + podMetricsEndpoints: + - port: http-metrics + interval: 30s + path: /metrics + scheme: http + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + insecureSkipVerify: true +EOT + } + + pod_monitors { + name = "tf-RawJobs" + config = <<-EOT +scrape_configs: + - job_name: 'example-job' + scrape_interval: 30s + static_configs: + - targets: ['example-service.default.svc.cluster.local:8080'] + metrics_path: /metrics + scheme: http + bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token + tls_config: + insecure_skip_verify: true +EOT } } } @@ -60,11 +127,13 @@ func resourceTencentCloudMonitorTmpTkeTemplate() *schema.Resource { "describe": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "Template description.", }, "record_rules": { Type: schema.TypeList, Optional: true, + Computed: true, Description: "Effective when Level is instance, A list of aggregation rules in the template.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -89,6 +158,7 @@ func resourceTencentCloudMonitorTmpTkeTemplate() *schema.Resource { "service_monitors": { Type: schema.TypeList, Optional: true, + Computed: true, Description: "Effective when Level is a cluster, A list of ServiceMonitor rules in the template.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -113,6 +183,7 @@ func resourceTencentCloudMonitorTmpTkeTemplate() *schema.Resource { "pod_monitors": { Type: schema.TypeList, Optional: true, + Computed: true, Description: "Effective when Level is a cluster, A list of PodMonitors rules in the template.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -137,6 +208,7 @@ func resourceTencentCloudMonitorTmpTkeTemplate() *schema.Resource { "raw_jobs": { Type: schema.TypeList, Optional: true, + Computed: true, Description: "Effective when Level is a cluster, A list of RawJobs rules in the template.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_template_attachment.go b/tencentcloud/resource_tc_monitor_tmp_tke_template_attachment.go index c2f1dc4765..63d1ee2732 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_template_attachment.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_template_attachment.go @@ -5,12 +5,268 @@ Example Usage ```hcl +# create tke +variable "default_instance_type" { + default = "SA1.MEDIUM2" +} + +variable "availability_zone_first" { + default = "ap-guangzhou-3" +} + +variable "availability_zone_second" { + default = "ap-guangzhou-4" +} + +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "cluster_type" { + default = "tke" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + + +# tmp tke bind +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + +# create monitor template +resource "tencentcloud_monitor_tmp_tke_template" "foo" { + template { + name = "tf-template" + level = "cluster" + describe = "template" + service_monitors { + name = "tf-ServiceMonitor" + config = <<-EOT +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: example-service-monitor + namespace: monitoring + labels: + k8s-app: example-service +spec: + selector: + matchLabels: + k8s-app: example-service + namespaceSelector: + matchNames: + - default + endpoints: + - port: http-metrics + interval: 30s + path: /metrics + scheme: http + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + insecureSkipVerify: true + EOT + } + + pod_monitors { + name = "tf-PodMonitors" + config = <<-EOT +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: example-pod-monitor + namespace: monitoring + labels: + k8s-app: example-pod +spec: + selector: + matchLabels: + k8s-app: example-pod + namespaceSelector: + matchNames: + - default + podMetricsEndpoints: + - port: http-metrics + interval: 30s + path: /metrics + scheme: http + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + insecureSkipVerify: true +EOT + } + + pod_monitors { + name = "tf-RawJobs" + config = <<-EOT +scrape_configs: + - job_name: 'example-job' + scrape_interval: 30s + static_configs: + - targets: ['example-service.default.svc.cluster.local:8080'] + metrics_path: /metrics + scheme: http + bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token + tls_config: + insecure_skip_verify: true +EOT + } + } +} + resource "tencentcloud_monitor_tmp_tke_template_attachment" "temp_attachment" { - template_id = "temp-xxx" + template_id = tencentcloud_monitor_tmp_tke_template.foo.id targets { - region = "ap-xxx" - instance_id = "prom-xxx" + region = var.zone + instance_id = tencentcloud_monitor_tmp_instance.foo.id } } ``` diff --git a/website/docs/r/monitor_tmp_grafana_config.html.markdown b/website/docs/r/monitor_tmp_grafana_config.html.markdown index 2cb3a03b38..6308b77a1b 100644 --- a/website/docs/r/monitor_tmp_grafana_config.html.markdown +++ b/website/docs/r/monitor_tmp_grafana_config.html.markdown @@ -43,7 +43,7 @@ resource "tencentcloud_monitor_grafana_instance" "foo" { } } -resource "tencentcloud_monitor_tmp_grafana_config" "tmp_grafana_config" { +resource "tencentcloud_monitor_tmp_grafana_config" "foo" { config = jsonencode( { server = { diff --git a/website/docs/r/monitor_tmp_tke_alert_policy.html.markdown b/website/docs/r/monitor_tmp_tke_alert_policy.html.markdown index 63f2446723..eeff3f4a84 100644 --- a/website/docs/r/monitor_tmp_tke_alert_policy.html.markdown +++ b/website/docs/r/monitor_tmp_tke_alert_policy.html.markdown @@ -14,8 +14,41 @@ Provides a resource to create a tke tmpAlertPolicy ## Example Usage ```hcl +# create monitor +variable "cluster_type" { + default = "tke" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +# create record rule resource "tencentcloud_monitor_tmp_tke_alert_policy" "basic" { - instance_id = "prom-xxxxxx" + instance_id = tencentcloud_monitor_tmp_instance.foo.id alert_rule { name = "alert_rule-test" rules { diff --git a/website/docs/r/monitor_tmp_tke_basic_config.html.markdown b/website/docs/r/monitor_tmp_tke_basic_config.html.markdown index 7b6047336e..882b02c72c 100644 --- a/website/docs/r/monitor_tmp_tke_basic_config.html.markdown +++ b/website/docs/r/monitor_tmp_tke_basic_config.html.markdown @@ -14,10 +14,183 @@ Provides a resource to create a monitor tmp_tke_basic_config ## Example Usage ```hcl +# create tke +variable "default_instance_type" { + default = "SA1.MEDIUM2" +} + +variable "availability_zone_first" { + default = "ap-guangzhou-3" +} + +variable "availability_zone_second" { + default = "ap-guangzhou-4" +} + +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +# tmp tke bind +variable "cluster_type" { + default = "tke" +} + +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + resource "tencentcloud_monitor_tmp_tke_basic_config" "tmp_tke_basic_config" { - instance_id = "prom-xxxxxx" - cluster_type = "eks" - cluster_id = "cls-xxxxxx" + instance_id = tencentcloud_monitor_tmp_instance.foo.id + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id name = "kube-system/kube-state-metrics" metrics_name = ["kube_job_status_succeeded"] } diff --git a/website/docs/r/monitor_tmp_tke_cluster_agent.html.markdown b/website/docs/r/monitor_tmp_tke_cluster_agent.html.markdown index 189f80eea8..4dd3f3c0c2 100644 --- a/website/docs/r/monitor_tmp_tke_cluster_agent.html.markdown +++ b/website/docs/r/monitor_tmp_tke_cluster_agent.html.markdown @@ -14,13 +14,171 @@ Provides a resource to create a tmp tke cluster agent ## Example Usage ```hcl +# create tke +variable "default_instance_type" { + default = "SA1.MEDIUM2" +} + +variable "availability_zone_first" { + default = "ap-guangzhou-3" +} + +variable "availability_zone_second" { + default = "ap-guangzhou-4" +} + +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +# tmp tke bind resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { - instance_id = "prom-xxx" + instance_id = tencentcloud_monitor_tmp_instance.foo.id agents { - region = "ap-xxx" - cluster_type = "eks" - cluster_id = "cls-xxx" + region = var.zone + cluster_type = "tke" + cluster_id = tencentcloud_kubernetes_cluster.example.id enable_external = false } } diff --git a/website/docs/r/monitor_tmp_tke_config.html.markdown b/website/docs/r/monitor_tmp_tke_config.html.markdown index ea6e1f3ca0..d78b3f638a 100644 --- a/website/docs/r/monitor_tmp_tke_config.html.markdown +++ b/website/docs/r/monitor_tmp_tke_config.html.markdown @@ -14,10 +14,183 @@ Provides a resource to create a tke tmpPrometheusConfig ## Example Usage ```hcl +# create tke +variable "default_instance_type" { + default = "SA1.MEDIUM2" +} + +variable "availability_zone_first" { + default = "ap-guangzhou-3" +} + +variable "availability_zone_second" { + default = "ap-guangzhou-4" +} + +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +# tmp tke bind +variable "cluster_type" { + default = "tke" +} + +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + resource "tencentcloud_monitor_tmp_tke_config" "foo" { - instance_id = "xxx" - cluster_type = "xxx" - cluster_id = "xxx" + instance_id = tencentcloud_monitor_tmp_instance.foo.id + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id raw_jobs { name = "raw_jobs_001" diff --git a/website/docs/r/monitor_tmp_tke_global_notification.html.markdown b/website/docs/r/monitor_tmp_tke_global_notification.html.markdown index cda22a58aa..ac5bb7bc23 100644 --- a/website/docs/r/monitor_tmp_tke_global_notification.html.markdown +++ b/website/docs/r/monitor_tmp_tke_global_notification.html.markdown @@ -14,8 +14,41 @@ Provides a resource to create a tmp tke global notification ## Example Usage ```hcl +# create monitor +variable "cluster_type" { + default = "tke" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +# create record rule resource "tencentcloud_monitor_tmp_tke_global_notification" "basic" { - instance_id = "prom-xxxxxx" + instance_id = tencentcloud_monitor_tmp_instance.foo.id notification { enabled = true type = "webhook" diff --git a/website/docs/r/monitor_tmp_tke_record_rule_yaml.html.markdown b/website/docs/r/monitor_tmp_tke_record_rule_yaml.html.markdown index 9efae75c85..8cf71156ca 100644 --- a/website/docs/r/monitor_tmp_tke_record_rule_yaml.html.markdown +++ b/website/docs/r/monitor_tmp_tke_record_rule_yaml.html.markdown @@ -14,8 +14,41 @@ Provides a resource to create a tke tmpRecordRule ## Example Usage ```hcl +# create monitor +variable "cluster_type" { + default = "tke" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +# create record rule resource "tencentcloud_monitor_tmp_tke_record_rule_yaml" "foo" { - instance_id = "" + instance_id = tencentcloud_monitor_tmp_instance.foo.id content = <<-EOT apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule diff --git a/website/docs/r/monitor_tmp_tke_template.html.markdown b/website/docs/r/monitor_tmp_tke_template.html.markdown index f4bb1ac84a..e31769adbe 100644 --- a/website/docs/r/monitor_tmp_tke_template.html.markdown +++ b/website/docs/r/monitor_tmp_tke_template.html.markdown @@ -14,14 +14,81 @@ Provides a resource to create a tmp tke template ## Example Usage ```hcl -resource "tencentcloud_monitor_tmp_tke_template" "template" { +resource "tencentcloud_monitor_tmp_tke_template" "foo" { template { - name = "test" + name = "tf-template" level = "cluster" describe = "template" service_monitors { - name = "test" - config = "xxxxx" + name = "tf-ServiceMonitor" + config = <<-EOT +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: example-service-monitor + namespace: monitoring + labels: + k8s-app: example-service +spec: + selector: + matchLabels: + k8s-app: example-service + namespaceSelector: + matchNames: + - default + endpoints: + - port: http-metrics + interval: 30s + path: /metrics + scheme: http + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + insecureSkipVerify: true + EOT + } + + pod_monitors { + name = "tf-PodMonitors" + config = <<-EOT +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: example-pod-monitor + namespace: monitoring + labels: + k8s-app: example-pod +spec: + selector: + matchLabels: + k8s-app: example-pod + namespaceSelector: + matchNames: + - default + podMetricsEndpoints: + - port: http-metrics + interval: 30s + path: /metrics + scheme: http + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + insecureSkipVerify: true +EOT + } + + pod_monitors { + name = "tf-RawJobs" + config = <<-EOT +scrape_configs: + - job_name: 'example-job' + scrape_interval: 30s + static_configs: + - targets: ['example-service.default.svc.cluster.local:8080'] + metrics_path: /metrics + scheme: http + bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token + tls_config: + insecure_skip_verify: true +EOT } } } diff --git a/website/docs/r/monitor_tmp_tke_template_attachment.html.markdown b/website/docs/r/monitor_tmp_tke_template_attachment.html.markdown index 873d22ebc8..c946cdb2c4 100644 --- a/website/docs/r/monitor_tmp_tke_template_attachment.html.markdown +++ b/website/docs/r/monitor_tmp_tke_template_attachment.html.markdown @@ -14,12 +14,265 @@ Provides a resource to create a tmp tke template attachment ## Example Usage ```hcl +# create tke +variable "default_instance_type" { + default = "SA1.MEDIUM2" +} + +variable "availability_zone_first" { + default = "ap-guangzhou-3" +} + +variable "availability_zone_second" { + default = "ap-guangzhou-4" +} + +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "cluster_type" { + default = "tke" +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "tf_monitor_vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = var.availability_zone + name = "tf_monitor_subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_monitor_tmp_instance" "foo" { + instance_name = "tf-tmp-instance" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 30 + zone = var.availability_zone + tags = { + "createdBy" = "terraform" + } +} + +# tmp tke bind +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + +# create monitor template +resource "tencentcloud_monitor_tmp_tke_template" "foo" { + template { + name = "tf-template" + level = "cluster" + describe = "template" + service_monitors { + name = "tf-ServiceMonitor" + config = <<-EOT +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: example-service-monitor + namespace: monitoring + labels: + k8s-app: example-service +spec: + selector: + matchLabels: + k8s-app: example-service + namespaceSelector: + matchNames: + - default + endpoints: + - port: http-metrics + interval: 30s + path: /metrics + scheme: http + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + insecureSkipVerify: true + EOT + } + + pod_monitors { + name = "tf-PodMonitors" + config = <<-EOT +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: example-pod-monitor + namespace: monitoring + labels: + k8s-app: example-pod +spec: + selector: + matchLabels: + k8s-app: example-pod + namespaceSelector: + matchNames: + - default + podMetricsEndpoints: + - port: http-metrics + interval: 30s + path: /metrics + scheme: http + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + insecureSkipVerify: true +EOT + } + + pod_monitors { + name = "tf-RawJobs" + config = <<-EOT +scrape_configs: + - job_name: 'example-job' + scrape_interval: 30s + static_configs: + - targets: ['example-service.default.svc.cluster.local:8080'] + metrics_path: /metrics + scheme: http + bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token + tls_config: + insecure_skip_verify: true +EOT + } + } +} + resource "tencentcloud_monitor_tmp_tke_template_attachment" "temp_attachment" { - template_id = "temp-xxx" + template_id = tencentcloud_monitor_tmp_tke_template.foo.id targets { - region = "ap-xxx" - instance_id = "prom-xxx" + region = var.zone + instance_id = tencentcloud_monitor_tmp_instance.foo.id } } ``` From 86750203304a6a0535d1e81088e9a969bdb6102f Mon Sep 17 00:00:00 2001 From: anonymous Date: Mon, 31 Jul 2023 17:08:03 +0800 Subject: [PATCH 4/4] fix: modify doc --- examples/tencentcloud-monitor-tke/main.tf | 61 ++---- ...esource_tc_monitor_tmp_tke_alert_policy.go | 156 ++++++++++++-- ...esource_tc_monitor_tmp_tke_basic_config.go | 37 +--- ...source_tc_monitor_tmp_tke_cluster_agent.go | 33 +-- .../resource_tc_monitor_tmp_tke_config.go | 36 +--- ..._tc_monitor_tmp_tke_global_notification.go | 199 ++++++++++++++---- ...rce_tc_monitor_tmp_tke_record_rule_yaml.go | 161 ++++++++++++-- ..._tc_monitor_tmp_tke_template_attachment.go | 40 ++-- ...monitor_tmp_tke_alert_policy.html.markdown | 156 ++++++++++++-- ...monitor_tmp_tke_basic_config.html.markdown | 31 +-- ...onitor_tmp_tke_cluster_agent.html.markdown | 27 +-- .../r/monitor_tmp_tke_config.html.markdown | 29 +-- ..._tmp_tke_global_notification.html.markdown | 156 ++++++++++++-- ...tor_tmp_tke_record_rule_yaml.html.markdown | 156 ++++++++++++-- ..._tmp_tke_template_attachment.html.markdown | 32 +-- 15 files changed, 955 insertions(+), 355 deletions(-) diff --git a/examples/tencentcloud-monitor-tke/main.tf b/examples/tencentcloud-monitor-tke/main.tf index 397879eb2b..f4ef565f79 100644 --- a/examples/tencentcloud-monitor-tke/main.tf +++ b/examples/tencentcloud-monitor-tke/main.tf @@ -113,8 +113,8 @@ resource "tencentcloud_kubernetes_cluster" "example" { enhanced_monitor_service = false user_data = "dGVzdA==" # key_ids = ["skey-11112222"] - cam_role_name = "CVM_QcsRole" - password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. } labels = { @@ -133,29 +133,12 @@ variable "cluster_type" { default = "tke" } -variable "availability_zone" { - default = "ap-guangzhou-4" -} - -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" -} - -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" -} - - resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } @@ -163,7 +146,7 @@ resource "tencentcloud_monitor_tmp_instance" "foo" { # tmp tke bind -resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { instance_id = tencentcloud_monitor_tmp_instance.foo.id agents { @@ -174,28 +157,6 @@ resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { } } -resource "tencentcloud_monitor_tmp_tke_config" "foo" { - instance_id = tencentcloud_monitor_tmp_instance.foo.id - cluster_type = var.cluster_type - cluster_id = tencentcloud_kubernetes_cluster.example.id - - raw_jobs { - name = "raw_jobs_001" - config = "your config for raw_jobs_001\n" - } - - service_monitors { - name = "kube-system/service-monitor-001" # name with default namespace kube-system - config = "apiVersion: monitoring.coreos.com/v1\nkind: ServiceMonitor\nmetadata:\n name: service-monitor-001\n namespace: kube-system\n" - } - - pod_monitors { - name = "mynamespace/pod-monitor-001" # name with the specified namespace - config = "apiVersion: monitoring.coreos.com/v1\nkind: PodMonitor\nmetadata:\n name: pod-monitor-001\n namespace: mynamespace\n" - } -} - - # create monitor template resource "tencentcloud_monitor_tmp_tke_template" "foo" { template { @@ -277,10 +238,14 @@ EOT } resource "tencentcloud_monitor_tmp_tke_template_attachment" "temp_attachment" { - template_id = tencentcloud_monitor_tmp_tke_template.foo.id + template_id = tencentcloud_monitor_tmp_tke_template.foo.id targets { - region = var.zone - instance_id = tencentcloud_monitor_tmp_instance.foo.id + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + region = var.zone + instance_id = tencentcloud_monitor_tmp_instance.foo.id } + + depends_on = [tencentcloud_monitor_tmp_tke_cluster_agent.foo] } \ No newline at end of file diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy.go b/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy.go index fa18ccbef5..496ae513dc 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy.go @@ -4,39 +4,163 @@ Provides a resource to create a tke tmpAlertPolicy Example Usage ```hcl -# create monitor -variable "cluster_type" { - default = "tke" +variable "default_instance_type" { + default = "SA1.MEDIUM2" } -variable "availability_zone" { +variable "availability_zone_first" { + default = "ap-guangzhou-3" +} + +variable "availability_zone_second" { default = "ap-guangzhou-4" } -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second } -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" } +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "cluster_type" { + default = "tke" +} resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } +# tmp tke bind +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + # create record rule resource "tencentcloud_monitor_tmp_tke_alert_policy" "basic" { instance_id = tencentcloud_monitor_tmp_instance.foo.id @@ -60,6 +184,8 @@ resource "tencentcloud_monitor_tmp_tke_alert_policy" "basic" { } } } + + depends_on = [tencentcloud_monitor_tmp_tke_cluster_agent.foo] } ``` */ diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_basic_config.go b/tencentcloud/resource_tc_monitor_tmp_tke_basic_config.go index ff433ed091..69b8bcbc35 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_basic_config.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_basic_config.go @@ -4,7 +4,6 @@ Provides a resource to create a monitor tmp_tke_basic_config Example Usage ```hcl -# create tke variable "default_instance_type" { default = "SA1.MEDIUM2" } @@ -119,8 +118,8 @@ resource "tencentcloud_kubernetes_cluster" "example" { enhanced_monitor_service = false user_data = "dGVzdA==" # key_ids = ["skey-11112222"] - cam_role_name = "CVM_QcsRole" - password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. } labels = { @@ -135,41 +134,23 @@ variable "zone" { default = "ap-guangzhou" } -variable "availability_zone" { - default = "ap-guangzhou-4" -} - -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" -} - -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" +variable "cluster_type" { + default = "tke" } - resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } - # tmp tke bind -variable "cluster_type" { - default = "tke" -} - -resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { instance_id = tencentcloud_monitor_tmp_instance.foo.id agents { @@ -186,6 +167,8 @@ resource "tencentcloud_monitor_tmp_tke_basic_config" "tmp_tke_basic_config" { cluster_id = tencentcloud_kubernetes_cluster.example.id name = "kube-system/kube-state-metrics" metrics_name = ["kube_job_status_succeeded"] + + depends_on = [tencentcloud_monitor_tmp_tke_cluster_agent.foo] } ``` diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_cluster_agent.go b/tencentcloud/resource_tc_monitor_tmp_tke_cluster_agent.go index 8ad7a6561b..3047af357d 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_cluster_agent.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_cluster_agent.go @@ -4,7 +4,6 @@ Provides a resource to create a tmp tke cluster agent Example Usage ```hcl -# create tke variable "default_instance_type" { default = "SA1.MEDIUM2" } @@ -119,8 +118,8 @@ resource "tencentcloud_kubernetes_cluster" "example" { enhanced_monitor_service = false user_data = "dGVzdA==" # key_ids = ["skey-11112222"] - cam_role_name = "CVM_QcsRole" - password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. } labels = { @@ -135,42 +134,28 @@ variable "zone" { default = "ap-guangzhou" } -variable "availability_zone" { - default = "ap-guangzhou-4" -} - -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" +variable "cluster_type" { + default = "tke" } -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" -} - - resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } - # tmp tke bind -resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { instance_id = tencentcloud_monitor_tmp_instance.foo.id agents { region = var.zone - cluster_type = "tke" + cluster_type = var.cluster_type cluster_id = tencentcloud_kubernetes_cluster.example.id enable_external = false } diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_config.go b/tencentcloud/resource_tc_monitor_tmp_tke_config.go index cba5e75c41..01160badd9 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_config.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_config.go @@ -4,8 +4,6 @@ Provides a resource to create a tke tmpPrometheusConfig Example Usage ```hcl - -# create tke variable "default_instance_type" { default = "SA1.MEDIUM2" } @@ -120,8 +118,8 @@ resource "tencentcloud_kubernetes_cluster" "example" { enhanced_monitor_service = false user_data = "dGVzdA==" # key_ids = ["skey-11112222"] - cam_role_name = "CVM_QcsRole" - password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. } labels = { @@ -136,41 +134,23 @@ variable "zone" { default = "ap-guangzhou" } -variable "availability_zone" { - default = "ap-guangzhou-4" -} - -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" -} - -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" +variable "cluster_type" { + default = "tke" } - resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } - # tmp tke bind -variable "cluster_type" { - default = "tke" -} - -resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { instance_id = tencentcloud_monitor_tmp_instance.foo.id agents { diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go b/tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go index 29d9b70cfa..959788c068 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go @@ -4,62 +4,189 @@ Provides a resource to create a tmp tke global notification Example Usage ```hcl -# create monitor -variable "cluster_type" { - default = "tke" +variable "default_instance_type" { + default = "SA1.MEDIUM2" +} + +variable "availability_zone_first" { + default = "ap-guangzhou-3" } -variable "availability_zone" { +variable "availability_zone_second" { default = "ap-guangzhou-4" } -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] } -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" } +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "cluster_type" { + default = "tke" +} resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } + +# tmp tke bind +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + # create record rule resource "tencentcloud_monitor_tmp_tke_global_notification" "basic" { - instance_id = tencentcloud_monitor_tmp_instance.foo.id - notification { - enabled = true - type = "webhook" - alert_manager { - cluster_id = "" - cluster_type = "" - url = "" - } - web_hook = "" - repeat_interval = "5m" - time_range_start = "00:00:00" - time_range_end = "23:59:59" - notify_way = ["SMS", "EMAIL"] - receiver_groups = [] - phone_notify_order = [] - phone_circle_times = 0 - phone_inner_interval = 0 - phone_circle_interval = 0 - phone_arrive_notice = false - } + instance_id = tencentcloud_monitor_tmp_instance.foo.id + notification { + enabled = true + type = "webhook" + alert_manager { + cluster_id = "" + cluster_type = "" + url = "" + } + web_hook = "" + repeat_interval = "5m" + time_range_start = "00:00:00" + time_range_end = "23:59:59" + notify_way = ["SMS", "EMAIL"] + receiver_groups = [] + phone_notify_order = [] + phone_circle_times = 0 + phone_inner_interval = 0 + phone_circle_interval = 0 + phone_arrive_notice = false + } + + depends_on = [tencentcloud_monitor_tmp_tke_cluster_agent.foo] } ``` */ diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_record_rule_yaml.go b/tencentcloud/resource_tc_monitor_tmp_tke_record_rule_yaml.go index 09020b1e8c..a6affbe59b 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_record_rule_yaml.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_record_rule_yaml.go @@ -4,43 +4,168 @@ Provides a resource to create a tke tmpRecordRule Example Usage ```hcl -# create monitor -variable "cluster_type" { - default = "tke" +variable "default_instance_type" { + default = "SA1.MEDIUM2" +} + +variable "availability_zone_first" { + default = "ap-guangzhou-3" } -variable "availability_zone" { +variable "availability_zone_second" { default = "ap-guangzhou-4" } -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" +variable "example_cluster_cidr" { + default = "10.31.0.0/16" } -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id } +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "cluster_type" { + default = "tke" +} resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } + +# tmp tke bind +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + # create record rule resource "tencentcloud_monitor_tmp_tke_record_rule_yaml" "foo" { - instance_id = tencentcloud_monitor_tmp_instance.foo.id - content = <<-EOT + instance_id = tencentcloud_monitor_tmp_instance.foo.id + content = <<-EOT apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule metadata: @@ -54,6 +179,8 @@ resource "tencentcloud_monitor_tmp_tke_record_rule_yaml" "foo" { verb: read record: 'apiserver_request:burnrate1d' EOT + + depends_on = [tencentcloud_monitor_tmp_tke_cluster_agent.foo] } ``` */ diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_template_attachment.go b/tencentcloud/resource_tc_monitor_tmp_tke_template_attachment.go index 63d1ee2732..29c8e8192f 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_template_attachment.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_template_attachment.go @@ -4,7 +4,6 @@ Provides a resource to create a tmp tke template attachment Example Usage ```hcl - # create tke variable "default_instance_type" { default = "SA1.MEDIUM2" @@ -120,8 +119,8 @@ resource "tencentcloud_kubernetes_cluster" "example" { enhanced_monitor_service = false user_data = "dGVzdA==" # key_ids = ["skey-11112222"] - cam_role_name = "CVM_QcsRole" - password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. } labels = { @@ -140,29 +139,12 @@ variable "cluster_type" { default = "tke" } -variable "availability_zone" { - default = "ap-guangzhou-4" -} - -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" -} - -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" -} - - resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } @@ -170,7 +152,7 @@ resource "tencentcloud_monitor_tmp_instance" "foo" { # tmp tke bind -resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { instance_id = tencentcloud_monitor_tmp_instance.foo.id agents { @@ -262,12 +244,16 @@ EOT } resource "tencentcloud_monitor_tmp_tke_template_attachment" "temp_attachment" { - template_id = tencentcloud_monitor_tmp_tke_template.foo.id + template_id = tencentcloud_monitor_tmp_tke_template.foo.id targets { - region = var.zone - instance_id = tencentcloud_monitor_tmp_instance.foo.id + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + region = var.zone + instance_id = tencentcloud_monitor_tmp_instance.foo.id } + + depends_on = [tencentcloud_monitor_tmp_tke_cluster_agent.foo] } ``` */ diff --git a/website/docs/r/monitor_tmp_tke_alert_policy.html.markdown b/website/docs/r/monitor_tmp_tke_alert_policy.html.markdown index eeff3f4a84..013833b89a 100644 --- a/website/docs/r/monitor_tmp_tke_alert_policy.html.markdown +++ b/website/docs/r/monitor_tmp_tke_alert_policy.html.markdown @@ -14,38 +14,162 @@ Provides a resource to create a tke tmpAlertPolicy ## Example Usage ```hcl -# create monitor -variable "cluster_type" { - default = "tke" +variable "default_instance_type" { + default = "SA1.MEDIUM2" } -variable "availability_zone" { +variable "availability_zone_first" { + default = "ap-guangzhou-3" +} + +variable "availability_zone_second" { default = "ap-guangzhou-4" } -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + +# create monitor +variable "zone" { + default = "ap-guangzhou" } -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" +variable "cluster_type" { + default = "tke" } resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } +# tmp tke bind +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + # create record rule resource "tencentcloud_monitor_tmp_tke_alert_policy" "basic" { instance_id = tencentcloud_monitor_tmp_instance.foo.id @@ -69,6 +193,8 @@ resource "tencentcloud_monitor_tmp_tke_alert_policy" "basic" { } } } + + depends_on = [tencentcloud_monitor_tmp_tke_cluster_agent.foo] } ``` diff --git a/website/docs/r/monitor_tmp_tke_basic_config.html.markdown b/website/docs/r/monitor_tmp_tke_basic_config.html.markdown index 882b02c72c..fd8a1b5a26 100644 --- a/website/docs/r/monitor_tmp_tke_basic_config.html.markdown +++ b/website/docs/r/monitor_tmp_tke_basic_config.html.markdown @@ -14,7 +14,6 @@ Provides a resource to create a monitor tmp_tke_basic_config ## Example Usage ```hcl -# create tke variable "default_instance_type" { default = "SA1.MEDIUM2" } @@ -144,39 +143,23 @@ variable "zone" { default = "ap-guangzhou" } -variable "availability_zone" { - default = "ap-guangzhou-4" -} - -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" -} - -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" +variable "cluster_type" { + default = "tke" } resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } # tmp tke bind -variable "cluster_type" { - default = "tke" -} - -resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { instance_id = tencentcloud_monitor_tmp_instance.foo.id agents { @@ -193,6 +176,8 @@ resource "tencentcloud_monitor_tmp_tke_basic_config" "tmp_tke_basic_config" { cluster_id = tencentcloud_kubernetes_cluster.example.id name = "kube-system/kube-state-metrics" metrics_name = ["kube_job_status_succeeded"] + + depends_on = [tencentcloud_monitor_tmp_tke_cluster_agent.foo] } ``` diff --git a/website/docs/r/monitor_tmp_tke_cluster_agent.html.markdown b/website/docs/r/monitor_tmp_tke_cluster_agent.html.markdown index 4dd3f3c0c2..629a2250b7 100644 --- a/website/docs/r/monitor_tmp_tke_cluster_agent.html.markdown +++ b/website/docs/r/monitor_tmp_tke_cluster_agent.html.markdown @@ -14,7 +14,6 @@ Provides a resource to create a tmp tke cluster agent ## Example Usage ```hcl -# create tke variable "default_instance_type" { default = "SA1.MEDIUM2" } @@ -144,40 +143,28 @@ variable "zone" { default = "ap-guangzhou" } -variable "availability_zone" { - default = "ap-guangzhou-4" -} - -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" -} - -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" +variable "cluster_type" { + default = "tke" } resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } # tmp tke bind -resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { instance_id = tencentcloud_monitor_tmp_instance.foo.id agents { region = var.zone - cluster_type = "tke" + cluster_type = var.cluster_type cluster_id = tencentcloud_kubernetes_cluster.example.id enable_external = false } diff --git a/website/docs/r/monitor_tmp_tke_config.html.markdown b/website/docs/r/monitor_tmp_tke_config.html.markdown index d78b3f638a..840f69b321 100644 --- a/website/docs/r/monitor_tmp_tke_config.html.markdown +++ b/website/docs/r/monitor_tmp_tke_config.html.markdown @@ -14,7 +14,6 @@ Provides a resource to create a tke tmpPrometheusConfig ## Example Usage ```hcl -# create tke variable "default_instance_type" { default = "SA1.MEDIUM2" } @@ -144,39 +143,23 @@ variable "zone" { default = "ap-guangzhou" } -variable "availability_zone" { - default = "ap-guangzhou-4" -} - -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" -} - -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" +variable "cluster_type" { + default = "tke" } resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } # tmp tke bind -variable "cluster_type" { - default = "tke" -} - -resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { instance_id = tencentcloud_monitor_tmp_instance.foo.id agents { diff --git a/website/docs/r/monitor_tmp_tke_global_notification.html.markdown b/website/docs/r/monitor_tmp_tke_global_notification.html.markdown index ac5bb7bc23..2308092fce 100644 --- a/website/docs/r/monitor_tmp_tke_global_notification.html.markdown +++ b/website/docs/r/monitor_tmp_tke_global_notification.html.markdown @@ -14,38 +14,162 @@ Provides a resource to create a tmp tke global notification ## Example Usage ```hcl -# create monitor -variable "cluster_type" { - default = "tke" +variable "default_instance_type" { + default = "SA1.MEDIUM2" } -variable "availability_zone" { +variable "availability_zone_first" { + default = "ap-guangzhou-3" +} + +variable "availability_zone_second" { default = "ap-guangzhou-4" } -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" +variable "example_cluster_cidr" { + default = "10.31.0.0/16" +} + +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second } -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "cluster_type" { + default = "tke" } resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } +# tmp tke bind +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + # create record rule resource "tencentcloud_monitor_tmp_tke_global_notification" "basic" { instance_id = tencentcloud_monitor_tmp_instance.foo.id @@ -69,6 +193,8 @@ resource "tencentcloud_monitor_tmp_tke_global_notification" "basic" { phone_circle_interval = 0 phone_arrive_notice = false } + + depends_on = [tencentcloud_monitor_tmp_tke_cluster_agent.foo] } ``` diff --git a/website/docs/r/monitor_tmp_tke_record_rule_yaml.html.markdown b/website/docs/r/monitor_tmp_tke_record_rule_yaml.html.markdown index 8cf71156ca..661d83ed28 100644 --- a/website/docs/r/monitor_tmp_tke_record_rule_yaml.html.markdown +++ b/website/docs/r/monitor_tmp_tke_record_rule_yaml.html.markdown @@ -14,38 +14,162 @@ Provides a resource to create a tke tmpRecordRule ## Example Usage ```hcl -# create monitor -variable "cluster_type" { - default = "tke" +variable "default_instance_type" { + default = "SA1.MEDIUM2" +} + +variable "availability_zone_first" { + default = "ap-guangzhou-3" } -variable "availability_zone" { +variable "availability_zone_second" { default = "ap-guangzhou-4" } -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" +variable "example_cluster_cidr" { + default = "10.31.0.0/16" } -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" +locals { + first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id + first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id + second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id + second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id + sg_id = tencentcloud_security_group.sg.id + image_id = data.tencentcloud_images.default.image_id +} + +data "tencentcloud_vpc_subnets" "vpc_one" { + is_default = true + availability_zone = var.availability_zone_first +} + +data "tencentcloud_vpc_subnets" "vpc_two" { + is_default = true + availability_zone = var.availability_zone_second +} + +resource "tencentcloud_security_group" "sg" { + name = "tf-example-sg" +} + +resource "tencentcloud_security_group_lite_rule" "sg_rule" { + security_group_id = tencentcloud_security_group.sg.id + + ingress = [ + "ACCEPT#10.0.0.0/16#ALL#ALL", + "ACCEPT#172.16.0.0/22#ALL#ALL", + "DROP#0.0.0.0/0#ALL#ALL", + ] + + egress = [ + "ACCEPT#172.16.0.0/22#ALL#ALL", + ] +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.first_vpc_id + cluster_cidr = var.example_cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false + cluster_internet_security_group = local.sg_id + cluster_version = "1.22.5" + cluster_deploy_type = "MANAGED_CLUSTER" + + worker_config { + count = 1 + availability_zone = var.availability_zone_first + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.first_subnet_id + img_id = local.image_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + worker_config { + count = 1 + availability_zone = var.availability_zone_second + instance_type = var.default_instance_type + system_disk_type = "CLOUD_SSD" + system_disk_size = 60 + internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" + internet_max_bandwidth_out = 100 + public_ip_assigned = true + subnet_id = local.second_subnet_id + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + # key_ids = ["skey-11112222"] + cam_role_name = "CVM_QcsRole" + password = "ZZXXccvv1212" // Optional, should be set if key_ids not set. + } + + labels = { + "test1" = "test1", + "test2" = "test2", + } +} + +# create monitor +variable "zone" { + default = "ap-guangzhou" +} + +variable "cluster_type" { + default = "tke" } resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } +# tmp tke bind +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { + instance_id = tencentcloud_monitor_tmp_instance.foo.id + + agents { + region = var.zone + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + enable_external = false + } +} + # create record rule resource "tencentcloud_monitor_tmp_tke_record_rule_yaml" "foo" { instance_id = tencentcloud_monitor_tmp_instance.foo.id @@ -63,6 +187,8 @@ resource "tencentcloud_monitor_tmp_tke_record_rule_yaml" "foo" { verb: read record: 'apiserver_request:burnrate1d' EOT + + depends_on = [tencentcloud_monitor_tmp_tke_cluster_agent.foo] } ``` diff --git a/website/docs/r/monitor_tmp_tke_template_attachment.html.markdown b/website/docs/r/monitor_tmp_tke_template_attachment.html.markdown index c946cdb2c4..c859296cd5 100644 --- a/website/docs/r/monitor_tmp_tke_template_attachment.html.markdown +++ b/website/docs/r/monitor_tmp_tke_template_attachment.html.markdown @@ -148,35 +148,19 @@ variable "cluster_type" { default = "tke" } -variable "availability_zone" { - default = "ap-guangzhou-4" -} - -resource "tencentcloud_vpc" "vpc" { - cidr_block = "10.0.0.0/16" - name = "tf_monitor_vpc" -} - -resource "tencentcloud_subnet" "subnet" { - vpc_id = tencentcloud_vpc.vpc.id - availability_zone = var.availability_zone - name = "tf_monitor_subnet" - cidr_block = "10.0.1.0/24" -} - resource "tencentcloud_monitor_tmp_instance" "foo" { instance_name = "tf-tmp-instance" - vpc_id = tencentcloud_vpc.vpc.id - subnet_id = tencentcloud_subnet.subnet.id + vpc_id = local.first_vpc_id + subnet_id = local.first_subnet_id data_retention_time = 30 - zone = var.availability_zone + zone = var.availability_zone_second tags = { "createdBy" = "terraform" } } # tmp tke bind -resource "tencentcloud_monitor_tmp_tke_cluster_agent" "tmpClusterAgent" { +resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" { instance_id = tencentcloud_monitor_tmp_instance.foo.id agents { @@ -271,9 +255,13 @@ resource "tencentcloud_monitor_tmp_tke_template_attachment" "temp_attachment" { template_id = tencentcloud_monitor_tmp_tke_template.foo.id targets { - region = var.zone - instance_id = tencentcloud_monitor_tmp_instance.foo.id + cluster_type = var.cluster_type + cluster_id = tencentcloud_kubernetes_cluster.example.id + region = var.zone + instance_id = tencentcloud_monitor_tmp_instance.foo.id } + + depends_on = [tencentcloud_monitor_tmp_tke_cluster_agent.foo] } ```