forked from eclipse-xpanse/xpanse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HuaweiCloud-Kafka-autofill.yml
444 lines (416 loc) · 18 KB
/
HuaweiCloud-Kafka-autofill.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# The version of the Xpanse description language
version: 1.0
# The category of the service.
category: middleware
# The Service provided by the ISV, the name will be shown on the console as a service.
name: Kafka-cluster
# The version of the service, the end-user can select the version they want to deploy.
serviceVersion: 1.0.0
# For the users may have more than one service, the @namespace can be used to separate the clusters.
description: This is an enhanced Kafka cluster services by ISV-A.
namespace: ISV-A
# Icon for the service.
icon: |
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAACRAQMAAAAPc4+9AAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAZQTFRF+/v7Hh8gVD0A0wAAAcVJREFUeJzNlc1twzAMhSX44KNH0CgaTd6gK3kUd4McDVTwq/hjiUyaIkV7qNA2/QCFIh+ppxB+svLNEqqBGTC0ANugBOwmCGDCFOAwIWGDOoqoODtN2BdL6wxD9NMTO9tXPa1PqL5M30W5p8lm5vNcF0t7ahSrVguqNqmMokRW4YQucVjBCBWH1Z2g3WDlW2skoYU+2x8JOtGedBF3k2iXMO0j16iUiI6gxzPdQhnU/s2G9pCO57QY2r6hvjPbKJHq7DRTRXT60avtuTRdbrFJI3mSZhNOqYjVbd99YyK1QKWzEqSWrE0k07U60uPaelflMzaaeu1KBuurHSsn572I1KWy2joX5ZBfWbS/VEt50H5P6aL4JxTuyJ/+QCNPX4PWF3Q8Xe1eF9FsLdD2VaOnaP2hWvs+zI58/7i3vH3nRFtDZpyTUNaZkON5XnBNsp8lrmDMrpvBr+b6pUl+4XbkQdndqnzYGzfuJm1JmIWimIbe6dndd/bk7gVce/cJdo3uIeLJl7+I2xTnPek67mjtDeppE7b03Ov+kSfDe3JweW53njxeGfXkaz28VeYd86+af/H8a7hgJKaebILaFzakLfxyfQLTxVB6K1K9KQAAAABJRU5ErkJggg==
# Reserved for CSP: HuaweiCloud,FlexibleEngine,OpenstackTestlab,PlusServer,RegioCloud and ...
cloudServiceProvider:
name: HuaweiCloud
regions:
- name: cn-southwest-2
area: Asia China
- name: cn-north-4
area: Asia China
billing:
# The supported mode of billing (`Fixed`, `Pay per Use`)
billingModes:
- Fixed
- Pay per Use
serviceHostingType: self
# The flavor of the service, the @category/@name/@version/@flavor can locate the specific service to be deployed.
flavors:
serviceFlavors:
- name: 1-zookeeper-with-3-worker-nodes-normal
priority: 2
# The pricing of the flavor.
pricing:
# Used to calculate charges when users select 'pay_per_use' as the billing mode.
resourceUsage:
resources:
- deployResourceKind: vm
count: 4
properties:
cloud_service_type: hws.service.type.ec2
resource_type: hws.resource.type.vm
resource_spec: s6.large.2.linux
- deployResourceKind: volume
count: 4
properties:
cloud_service_type: hws.service.type.ebs
resource_type: hws.resource.type.volume
resource_spec: SSD
resource_size: 40
size_measure_id: 17
licensePrice:
cost: 1.90
currency: CNY
period: hourly
markUpPrice:
cost: 1.60
currency: CNY
period: hourly
# Used to calculate charges when users do not select 'pay_per_use' as the billing mode.
fixedPrice:
cost: 730
currency: CNY
period: monthly
# Properties for the service, which can be used by the deployment.
properties:
worker_nodes_count: 3
flavor_id: s6.large.2
features:
- High Availability
- Maximum performance
- name: 1-zookeeper-with-3-worker-nodes-performance
priority: 1
# The pricing of the flavor.
pricing:
# Used to calculate charges when users select 'pay_per_use' as the billing mode.
resourceUsage:
resources:
- deployResourceKind: vm
count: 4
properties:
cloud_service_type: hws.service.type.ec2
resource_type: hws.resource.type.vm
resource_spec: s6.large.4.linux
- deployResourceKind: volume
count: 4
properties:
cloud_service_type: hws.service.type.ebs
resource_type: hws.resource.type.volume
resource_spec: SSD
resource_size: 40
size_measure_id: 17
licensePrice:
cost: 3.20
currency: CNY
period: hourly
markUpPrice:
cost: 2.88
currency: CNY
period: hourly
# Used to calculate charges when users do not select 'pay_per_use' as the billing mode.
fixedPrice:
cost: 980
currency: CNY
period: monthly
properties:
worker_nodes_count: 3
flavor_id: s6.large.4
features:
- High Availability
- Maximum performance
modificationImpact:
isDataLost: true
isServiceInterrupted: true
isDowngradeAllowed: true
# The contact details of the service.
serviceProviderContactDetails:
emails: [ "[email protected]" ]
configurationParameters:
- name: kafka_cfg_message_max_bytes
kind: variable
dataType: number
description: Parameters used to configure the Kafka server or client to set the maximum number of bytes for Kafka messages.
initialValue: 1048576
modificationImpact:
isDataLost: true
isServiceInterrupted: true
isReadOnly: false
- name: kafka_cfg_log_dirs
kind: variable
dataType: string
description: Parameters for the storage location of Kafka log data
initialValue: /var/lib/kafka/logs
modificationImpact:
isDataLost: true
isServiceInterrupted: true
isReadOnly: false
- name: kafka_cfg_num_io_threads
kind: variable
dataType: number
description: Parameter used to set the number of I/O threads to handle kafka network requests
initialValue: 8
modificationImpact:
isDataLost: true
isServiceInterrupted: true
isReadOnly: false
- name: kafka_log_flush_interval_messages
kind: variable
dataType: number
description: Kafka's log flush strategy, specifies the parameters that trigger a log flush operation after how many messages are written.
initialValue: 10000
modificationImpact:
isDataLost: true
isServiceInterrupted: true
isReadOnly: false
- name: kafka_offsets_topic_replication_factor
kind: variable
dataType: number
description: Replication factor configuration parameters for the dedicated topic (offsets topic) used in the Kafka cluster to consume offset information for the consumer storage group
initialValue: 3
modificationImpact:
isDataLost: true
isServiceInterrupted: true
isReadOnly: false
deployment:
# kind, Supported values are terraform, opentofu.
kind: terraform
serviceAvailabilityConfigs:
- displayName: Availability Zone
varName: availability_zone
mandatory: false
description: The availability zone to deploy the service instance. If the value is empty, the service instance will be deployed in a random availability zone.
# Context for deployment: the context including some kind of parameters for the deployment, such as fix_env, fix_variable, env, variable, env_env, env_variable.
# - fix_env: Values for variable of this type are defined by the managed service provider in the OCL template. Runtime will inject it to deployer as environment variables. This variable is not visible to the end user.
# - fix_variable: Values for variable of this type are defined by the managed service provider in the OCL template. Runtime will inject it to deployer as usual variables. This variable is not visible to the end user.
# - env: Value for a variable of this type can be provided by end user. If marked as mandatory then end user must provide value to this variable. If marked as optional and if end user does not provided it, then the fallback value to this variable is read by runtime (it can read from other sources, e.g., OS env variables). This variable is injected as a environment variable to the deployer.
# - variable: Value for a variable of this type can be provided by end user. . If marked as mandatory then end user must provide value to this variable. If marked as optional and if end user does not provided it, then the fallback value to this variable is read by runtime (it can read from other sources, e.g., OS env variables). This variable is injected as a regular variable to the deployer.
# - env_env: Value to this variable is read by runtime (it can read from other sources, e.g., OS env variables) and injected as a environment variable to the deployer. End user cannot see or change this variable.
# - env_variable: Value to this variable is read by runtime (it can read from other sources, e.g., OS env variables) and injected as a regular variable to the deployer. End user cannot see or change this variable.
# The parameters will be used to generate the API of the managed service.
variables:
- name: admin_passwd
description: The admin password of all nodes in the Kafka cluster instance. If the value is empty, will create a random password.
kind: variable
dataType: string
mandatory: false
valueSchema:
minLength: 8
maxLength: 16
pattern: ^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,16}$
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: vpc_name
description: The vpc name of all nodes in the Kafka cluster instance. If the value is empty, will use the default value to find or create VPC.
kind: variable
dataType: string
example: "kafka-vpc-default"
mandatory: false
value: "kafka-vpc-default"
autoFill:
deployResourceKind: vpc
isAllowCreate: false
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: subnet_name
description: The sub network name of all nodes in the Kafka cluster instance. If the value is empty, will use the default value to find or create subnet.
kind: variable
dataType: string
example: "kafka-subnet-default"
mandatory: false
value: "kafka-subnet-default"
autoFill:
deployResourceKind: subnet
isAllowCreate: false
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: secgroup_name
description: The security group name of all nodes in the Kafka cluster instance. If the value is empty, will use the default value to find or create security group.
kind: variable
dataType: string
example: "kafka-secgroup-default"
mandatory: false
value: "kafka-secgroup-default"
autoFill:
deployResourceKind: security_group
isAllowCreate: false
modificationImpact:
isDataLost: true
isServiceInterrupted: true
deployer: |
variable "region" {
type = string
description = "The region to deploy the Kafka cluster instance."
}
variable "availability_zone" {
type = string
default = ""
description = "The availability zone to deploy the Kafka cluster instance."
}
variable "flavor_id" {
type = string
default = "s6.large.2"
description = "The flavor_id of all nodes in the Kafka cluster instance."
}
variable "worker_nodes_count" {
type = string
default = 3
description = "The worker nodes count in the Kafka cluster instance."
}
variable "admin_passwd" {
type = string
default = ""
description = "The root password of all nodes in the Kafka cluster instance."
}
variable "vpc_name" {
type = string
default = "kafka-vpc-default"
description = "The vpc name of all nodes in the Kafka cluster instance."
}
variable "subnet_name" {
type = string
default = "kafka-subnet-default"
description = "The subnet name of all nodes in the Kafka cluster instance."
}
variable "secgroup_name" {
type = string
default = "kafka-secgroup-default"
description = "The security group name of all nodes in the Kafka cluster instance."
}
terraform {
required_providers {
huaweicloud = {
source = "huaweicloud/huaweicloud"
version = "~> 1.61.0"
}
}
}
provider "huaweicloud" {
region = var.region
}
data "huaweicloud_availability_zones" "osc-az" {}
data "huaweicloud_vpcs" "existing" {
name = var.vpc_name
}
data "huaweicloud_vpc_subnets" "existing" {
name = var.subnet_name
}
data "huaweicloud_networking_secgroups" "existing" {
name = var.secgroup_name
}
locals {
availability_zone = var.availability_zone == "" ? data.huaweicloud_availability_zones.osc-az.names[0] : var.availability_zone
admin_passwd = var.admin_passwd == "" ? random_password.password.result : var.admin_passwd
vpc_id = length(data.huaweicloud_vpcs.existing.vpcs) > 0 ? data.huaweicloud_vpcs.existing.vpcs[0].id : huaweicloud_vpc.new[0].id
subnet_id = length(data.huaweicloud_vpc_subnets.existing.subnets)> 0 ? data.huaweicloud_vpc_subnets.existing.subnets[0].id : huaweicloud_vpc_subnet.new[0].id
secgroup_id = length(data.huaweicloud_networking_secgroups.existing.security_groups) > 0 ? data.huaweicloud_networking_secgroups.existing.security_groups[0].id : huaweicloud_networking_secgroup.new[0].id
}
resource "huaweicloud_vpc" "new" {
count = length(data.huaweicloud_vpcs.existing.vpcs) == 0 ? 1 : 0
name = var.vpc_name
cidr = "192.168.0.0/16"
}
resource "huaweicloud_vpc_subnet" "new" {
count = length(data.huaweicloud_vpcs.existing.vpcs) == 0 ? 1 : 0
vpc_id = local.vpc_id
name = var.subnet_name
cidr = "192.168.10.0/24"
gateway_ip = "192.168.10.1"
}
resource "huaweicloud_networking_secgroup" "new" {
count = length(data.huaweicloud_networking_secgroups.existing.security_groups) == 0 ? 1 : 0
name = var.secgroup_name
description = "Kafka cluster security group"
}
resource "huaweicloud_networking_secgroup_rule" "secgroup_rule_0" {
count = length(data.huaweicloud_networking_secgroups.existing.security_groups) == 0 ? 1 : 0
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 22
port_range_max = 22
remote_ip_prefix = "121.37.117.211/32"
security_group_id = local.secgroup_id
}
resource "huaweicloud_networking_secgroup_rule" "secgroup_rule_1" {
count = length(data.huaweicloud_networking_secgroups.existing.security_groups) == 0 ? 1 : 0
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 2181
port_range_max = 2181
remote_ip_prefix = "121.37.117.211/32"
security_group_id = local.secgroup_id
}
resource "huaweicloud_networking_secgroup_rule" "secgroup_rule_2" {
count = length(data.huaweicloud_networking_secgroups.existing.security_groups) == 0 ? 1 : 0
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 9092
port_range_max = 9093
remote_ip_prefix = "121.37.117.211/32"
security_group_id = local.secgroup_id
}
resource "random_id" "new" {
byte_length = 4
}
resource "random_password" "password" {
length = 12
upper = true
lower = true
numeric = true
special = true
min_special = 1
override_special = "#%@"
}
resource "huaweicloud_kps_keypair" "keypair" {
name = "keypair-kafka-${random_id.new.hex}"
key_file = "keypair-kafka-${random_id.new.hex}.pem"
}
data "huaweicloud_images_image" "image" {
name = "Kafka-v3.3.2_Ubuntu-20.04"
most_recent = true
enterprise_project_id = "0"
}
resource "huaweicloud_compute_instance" "zookeeper" {
availability_zone = local.availability_zone
name = "kafka-zookeeper-${random_id.new.hex}"
flavor_id = var.flavor_id
security_group_ids = [ local.secgroup_id ]
image_id = data.huaweicloud_images_image.image.id
key_pair = huaweicloud_kps_keypair.keypair.name
network {
uuid = local.subnet_id
}
user_data = <<EOF
#!bin/bash
echo root:${local.admin_passwd} | sudo chpasswd
sudo systemctl start docker
sudo systemctl enable docker
sudo docker run -d --name zookeeper-server --privileged=true -p 2181:2181 -e ALLOW_ANONYMOUS_LOGIN=yes bitnami/zookeeper:3.8.1
EOF
}
resource "huaweicloud_compute_instance" "kafka-broker" {
count = var.worker_nodes_count
availability_zone = local.availability_zone
name = "kafka-broker-${random_id.new.hex}-${count.index}"
flavor_id = var.flavor_id
security_group_ids = [ local.secgroup_id ]
image_id = data.huaweicloud_images_image.image.id
key_pair = huaweicloud_kps_keypair.keypair.name
network {
uuid = local.subnet_id
}
user_data = <<EOF
#!bin/bash
echo root:${local.admin_passwd} | sudo chpasswd
sudo systemctl start docker
sudo systemctl enable docker
private_ip=$(ifconfig | grep -A1 "eth0" | grep 'inet' | awk -F ' ' ' {print $2}'|awk ' {print $1}')
sudo docker run -d --name kafka-server --restart always -p 9092:9092 -p 9093:9093 -e KAFKA_BROKER_ID=${count.index} -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://$private_ip:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -e ALLOW_PLAINTEXT_LISTENER=yes -e KAFKA_CFG_ZOOKEEPER_CONNECT=${huaweicloud_compute_instance.zookeeper.access_ip_v4}:2181 bitnami/kafka:3.3.2
EOF
depends_on = [
huaweicloud_compute_instance.zookeeper
]
}
output "zookeeper_server" {
value = "${huaweicloud_compute_instance.zookeeper.access_ip_v4}:2181"
}
output "admin_passwd" {
value = var.admin_passwd == "" ? nonsensitive(local.admin_passwd) : local.admin_passwd
}