@@ -2,15 +2,199 @@ Provides a resource to create a tke kubernetes_log_config
2
2
3
3
Example Usage
4
4
5
+ Create a cls log config
6
+
5
7
``` hcl
6
- resource "tencentcloud_kubernetes_log_config" "kubernetes_log_config" {
8
+ locals {
9
+ first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id
10
+ first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id
11
+ zone_id = data.tencentcloud_availability_zones_by_product.gz.zones.0.id
12
+ }
13
+
14
+ variable "example_cluster_cidr" {
15
+ default = "10.31.0.0/16"
16
+ }
17
+
18
+ data "tencentcloud_vpc_subnets" "vpc_one" {
19
+ is_default = true
20
+ availability_zone = "ap-guangzhou-3"
7
21
}
8
- ```
9
22
10
- Import
23
+ data "tencentcloud_availability_zones_by_product" "gz" {
24
+ name = "ap-guangzhou-3"
25
+ product = "ckafka"
26
+ }
27
+
28
+ resource "tencentcloud_kubernetes_cluster" "example" {
29
+ vpc_id = local.first_vpc_id
30
+ cluster_cidr = var.example_cluster_cidr
31
+ cluster_max_pod_num = 32
32
+ cluster_name = "tf_example_cluster"
33
+ cluster_desc = "example for tke cluster"
34
+ cluster_max_service_num = 32
35
+ cluster_internet = false # (can be ignored) open it after the nodes added
36
+ cluster_version = "1.22.5"
37
+ cluster_os = "tlinux2.2(tkernel3)x86_64"
38
+ cluster_deploy_type = "MANAGED_CLUSTER"
39
+ # without any worker config
40
+ }
11
41
12
- tke kubernetes_log_config can be imported using the id, e.g.
42
+ resource "tencentcloud_cls_logset" "logset" {
43
+ logset_name = "example"
44
+ tags = {
45
+ "createdBy" = "terraform"
46
+ }
47
+ }
13
48
49
+ resource "tencentcloud_kubernetes_log_config" "kubernetes_log_config_cls" {
50
+ log_config_name = "tf-test-cls"
51
+ cluster_id = tencentcloud_kubernetes_cluster.example.id
52
+ logset_id = tencentcloud_cls_logset.logset.id
53
+ log_config = jsonencode({
54
+ "apiVersion" : "cls.cloud.tencent.com/v1",
55
+ "kind" : "LogConfig",
56
+ "metadata" : {
57
+ "name" : "tf-test-cls"
58
+ },
59
+ "spec" : {
60
+ "clsDetail" : {
61
+ "extractRule" : {
62
+ "backtracking" : "0",
63
+ "isGBK" : "false",
64
+ "jsonStandard" : "false",
65
+ "unMatchUpload" : "false"
66
+ },
67
+ "indexs" : [
68
+ {
69
+ "indexName" : "namespace"
70
+ },
71
+ {
72
+ "indexName" : "pod_name"
73
+ },
74
+ {
75
+ "indexName" : "container_name"
76
+ }
77
+ ],
78
+ "logFormat" : "default",
79
+ "logType" : "minimalist_log",
80
+ "maxSplitPartitions" : 0,
81
+ "region" : "ap-guangzhou",
82
+ "storageType" : "",
83
+ # "topicId" : "c26b66bd-617e-4923-bea0-test"
84
+ },
85
+ "inputDetail" : {
86
+ "containerStdout" : {
87
+ "metadataContainer" : [
88
+ "namespace",
89
+ "pod_name",
90
+ "pod_ip",
91
+ "pod_uid",
92
+ "container_id",
93
+ "container_name",
94
+ "image_name",
95
+ "cluster_id"
96
+ ],
97
+ "nsLabelSelector" : "",
98
+ "workloads" : [
99
+ {
100
+ "kind" : "deployment",
101
+ "name" : "testlog1",
102
+ "namespace" : "default"
103
+ }
104
+ ]
105
+ },
106
+ "type" : "container_stdout"
107
+ }
108
+ }
109
+ })
110
+ }
14
111
```
15
- terraform import tencentcloud_kubernetes_log_config.kubernetes_log_config kubernetes_log_config_id
112
+
113
+ Create a ckafka log config
114
+
115
+ ``` hcl
116
+ locals {
117
+ ckafka_topic = tencentcloud_ckafka_topic.example.topic_name
118
+ kafka_ip = tencentcloud_ckafka_instance.example.vip
119
+ kafka_port = tencentcloud_ckafka_instance.example.vport
120
+ }
121
+
122
+ resource "tencentcloud_ckafka_instance" "example" {
123
+ instance_name = "ckafka-instance-postpaid"
124
+ zone_id = local.zone_id
125
+ vpc_id = local.first_vpc_id
126
+ subnet_id = local.first_subnet_id
127
+ msg_retention_time = 1300
128
+ kafka_version = "1.1.1"
129
+ disk_size = 500
130
+ band_width = 20
131
+ disk_type = "CLOUD_BASIC"
132
+ partition = 400
133
+ charge_type = "POSTPAID_BY_HOUR"
134
+
135
+ config {
136
+ auto_create_topic_enable = true
137
+ default_num_partitions = 3
138
+ default_replication_factor = 3
139
+ }
140
+
141
+ dynamic_retention_config {
142
+ enable = 1
143
+ }
144
+ }
145
+
146
+ resource "tencentcloud_ckafka_topic" "example" {
147
+ instance_id = tencentcloud_ckafka_instance.example.id
148
+ topic_name = "tmp"
149
+ note = "topic note"
150
+ replica_num = 2
151
+ partition_num = 1
152
+ clean_up_policy = "delete"
153
+ sync_replica_min_num = 1
154
+ unclean_leader_election_enable = false
155
+ retention = 60000
156
+ }
157
+
158
+ resource "tencentcloud_kubernetes_log_config" "kubernetes_log_config_ckafka" {
159
+ log_config_name = "tf-test-ckafka"
160
+ cluster_id = tencentcloud_kubernetes_cluster.example.id
161
+ logset_id = tencentcloud_cls_logset.logset.id
162
+ log_config = jsonencode({
163
+ "apiVersion" : "cls.cloud.tencent.com/v1",
164
+ "kind" : "LogConfig",
165
+ "metadata" : {
166
+ "name" : "tf-test-ckafka"
167
+ },
168
+ "spec" : {
169
+ "inputDetail" : {
170
+ "containerStdout" : {
171
+ "allContainers" : true,
172
+ "namespace" : "default",
173
+ "nsLabelSelector" : ""
174
+ },
175
+ "type" : "container_stdout"
176
+ },
177
+ "kafkaDetail" : {
178
+ "brokers" : "${local.kafka_ip}:${local.kafka_port}",
179
+ "extractRule" : {},
180
+ "instanceId" : "",
181
+ "kafkaType" : "SelfBuildKafka",
182
+ "logType" : "minimalist_log",
183
+ "messageKey" : {
184
+ "value" : "",
185
+ "valueFrom" : {
186
+ "fieldRef" : {
187
+ "fieldPath" : ""
188
+ }
189
+ }
190
+ },
191
+ "metadata" : {},
192
+ "timestampFormat" : "double",
193
+ "timestampKey" : "",
194
+ "topic" : local.ckafka_topic
195
+ }
196
+ }
197
+ })
198
+ }
16
199
```
200
+
0 commit comments