-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
108 lines (90 loc) · 3.16 KB
/
main.tf
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
resource "random_id" "id" {
byte_length = 8
}
resource "hsdp_container_host" "kafka" {
count = var.nodes
name = var.host_name == "" ? "kafka-${random_id.id.hex}-${count.index}.dev" : "kafka-${var.host_name}-${count.index}.${var.tld}"
iops = var.iops
volumes = 1
volume_size = var.volume_size
instance_type = var.instance_type
user_groups = var.user_groups
security_groups = ["analytics"]
subnet_type = var.subnet_type
lifecycle {
ignore_changes = [
volumes,
volume_size,
instance_type,
iops
]
}
bastion_host = var.bastion_host
user = var.user
private_key = var.private_key
commands = [
]
}
resource "ssh_resource" "cluster" {
count = var.nodes
triggers = {
cluster_instance_ids = join(",", hsdp_container_host.kafka.*.id)
bash = file("${path.module}/scripts/bootstrap-cluster.sh")
}
bastion_host = var.bastion_host
host = element(hsdp_container_host.kafka.*.private_ip, count.index)
user = var.user
private_key = var.private_key
file {
source = "${path.module}/scripts/bootstrap-cluster.sh"
destination = "/home/${var.user}/bootstrap-cluster.sh"
}
file {
source = "${path.module}/scripts/jmxconfig.yml.tmpl"
destination = "/home/${var.user}/jmxconfig.yml.tmpl"
}
file {
source = var.kafka_trust_store.truststore
destination = "/home/${var.user}/kafka.truststore.jks"
}
file {
source = var.kafka_key_store.keystore
destination = "/home/${var.user}/kafka.keystore.jks"
}
file {
source = var.zoo_trust_store.truststore
destination = "/home/${var.user}/zookeeper.truststore.jks"
}
file {
source = var.zoo_key_store.keystore
destination = "/home/${var.user}/zookeeper.keystore.jks"
}
dynamic "file" {
for_each = var.enable_exporters ? [var.kafka_ca_root] : []
content {
source = file.value
destination = "/home/${var.user}/ca.pem"
}
}
dynamic "file" {
for_each = var.enable_exporters ? [var.kafka_public_key] : []
content {
source = file.value
destination = "/home/${var.user}/public.pem"
}
}
dynamic "file" {
for_each = var.enable_exporters ? [var.kafka_private_key] : []
content {
source = file.value
destination = "/home/${var.user}/private.pem"
}
}
# Bootstrap script called with private_ip of each node in the cluster
commands = [
"docker volume create kafka || true",
"chmod +x /home/${var.user}/bootstrap-cluster.sh",
"chmod 755 /home/${var.user}/jmxconfig.yml.tmpl",
"/home/${var.user}/bootstrap-cluster.sh -n ${join(",", hsdp_container_host.kafka.*.private_ip)} -c ${random_id.id.hex} -d ${var.image} -i ${count.index + 1} -z ${var.zookeeper_connect} -x ${element(hsdp_container_host.kafka.*.private_ip, count.index)} -r \"${var.retention_hours}\" -p ${var.kafka_key_store.password} -t ${var.zoo_trust_store.password} -k ${var.zoo_key_store.password} -R ${var.default_replication_factor} -a ${var.auto_create_topics_enable} -e ${var.enable_exporters} -m ${var.message_max_bytes} -f ${var.max_partition_fetch_bytes}"
]
}