Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 251 additions & 0 deletions examples/tencentcloud-monitor-tke/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
# 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"
}

resource "tencentcloud_monitor_tmp_instance" "foo" {
instance_name = "tf-tmp-instance"
vpc_id = local.first_vpc_id
subnet_id = local.first_subnet_id
data_retention_time = 30
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 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 {
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]
}
3 changes: 3 additions & 0 deletions examples/tencentcloud-monitor-tke/version.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = ">= 0.12"
}
65 changes: 35 additions & 30 deletions examples/tencentcloud-monitor/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions tencentcloud/resource_tc_monitor_alarm_notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
38 changes: 34 additions & 4 deletions tencentcloud/resource_tc_monitor_alarm_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
Loading