-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.tf-small
287 lines (244 loc) · 7.41 KB
/
main.tf-small
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
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}
resource "aws_security_group" "security_group" {
name = "${var.security_group}"
# ssh
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# elasticsearch
ingress {
from_port = 9200
to_port = 9200
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# flume stats
ingress {
from_port = 5653
to_port = 5653
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# kibana
ingress {
from_port = 5601
to_port = 5601
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# cloudera manager
ingress {
from_port = 7180
to_port = 7180
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# cloudera director
ingress {
from_port = 7189
to_port = 7189
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# webhdfs
ingress {
from_port = 50070
to_port = 50070
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# hue
ingress {
from_port = 8888
to_port = 8888
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
self = true
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_key_pair" "key" {
key_name = "${var.key_name}"
public_key = "${var.public_key}"
}
resource "null_resource" "null_pre_deployment" {
provisioner "local-exec" {
command = <<EOF
cd puppet
bundle exec rake prep
bundle exec rake rspec:classes
cd ..
EOF
}
}
resource "aws_instance" "node_log_generator" {
depends_on = ["null_resource.null_pre_deployment", "null_resource.null_dynamic_config_flume"]
ami = "${lookup(var.amis, lookup(var.os_versions, "default"))}"
instance_type = "${lookup(var.instance_types, "log_generator_flume")}"
security_groups = ["${var.security_group}"]
key_name = "${var.key_name}"
tags = {
Name = "log_generator"
App = "${var.tag_app}"
Env = "${var.tag_env}"
Owner = "${var.tag_owner}"
}
connection {
type = "ssh"
user = "${lookup(var.users, lookup(var.amis, lookup(var.os_versions, "default")))}"
key_file = "${var.key_file}"
}
provisioner "file" {
source = "puppet"
destination = "${var.puppet_path}"
}
provisioner "remote-exec" {
inline = [
"export PUPPET_ROLE=log_generator_flume",
"sudo chmod +x ${var.puppet_path}/puppet/puppet.sh",
"${var.puppet_path}/puppet/puppet.sh"
]
}
count = 1
}
resource "null_resource" "null_dynamic_config" {
provisioner "local-exec" {
command = <<EOF
FILE_PATH=puppet/hiera/hieradata/dynamic.yaml
rm -rf $FILE_PATH
touch $FILE_PATH
printf 'profiles::cloudera_director_client::cluster_name: '\''${var.cluster_name}'\''\n' >> $FILE_PATH
printf 'profiles::cloudera_director_client::deploy_cluster: ${var.deploy_cloudera_cluster}\n' >> $FILE_PATH
printf 'profiles::common::aws_access_key: '\''${var.access_key}'\''\n' >> $FILE_PATH
printf 'profiles::common::aws_secret_key: '\''${var.secret_key}'\''\n' >> $FILE_PATH
printf 'profiles::common::aws_region: '\''${var.region}'\''\n' >> $FILE_PATH
printf 'profiles::common::aws_security_group: '\''${var.security_group}'\''\n' >> $FILE_PATH
printf 'profiles::common::aws_ssh_username: '\''${lookup(var.users, lookup(var.amis, lookup(var.os_versions, "default")))}'\''\n' >> $FILE_PATH
printf 'profiles::common::aws_ami: '\''${lookup(var.amis, lookup(var.os_versions, "default"))}'\''\n' >> $FILE_PATH
printf 'profiles::common::aws_security_group_id: '\''${aws_security_group.security_group.id}'\''\n' >> $FILE_PATH
printf 'profiles::common::aws_subnetId: '\''${var.vpc_subnet_id}'\''\n' >> $FILE_PATH
printf 'profiles::common::aws_tag_env: '\''${var.tag_env}'\''\n' >> $FILE_PATH
printf 'profiles::common::aws_tag_owner: '\''${var.tag_owner}'\''\n' >> $FILE_PATH
printf 'profiles::cloudera_director_client::private_key_path: '\''/home/ec2-user/.ssh/${var.key_name}'\''\n' >> $FILE_PATH
EOF
}
}
resource "aws_instance" "node_elasticsearch" {
depends_on = ["null_resource.null_pre_deployment", "null_resource.null_dynamic_config"]
ami = "${lookup(var.amis, lookup(var.os_versions, "default"))}"
instance_type = "${lookup(var.instance_types, "elasticsearch_kibana")}"
security_groups = ["${var.security_group}"]
key_name = "${var.key_name}"
root_block_device {
volume_size = 200
}
tags = {
Name = "elasticsearch"
App = "${var.tag_app}"
Env = "${var.tag_env}"
Owner = "${var.tag_owner}"
}
connection {
type = "ssh"
user = "${lookup(var.users, lookup(var.amis, lookup(var.os_versions, "default")))}"
key_file = "${var.key_file}"
}
provisioner "file" {
source = "puppet"
destination = "${var.puppet_path}"
}
provisioner "remote-exec" {
inline = [
"export PUPPET_ROLE=elasticsearch_kibana",
"sudo chmod +x ${var.puppet_path}/puppet/puppet.sh",
"${var.puppet_path}/puppet/puppet.sh"
]
}
count = 1
}
resource "aws_instance" "cloudera_director_client" {
depends_on = ["null_resource.null_pre_deployment", "null_resource.null_dynamic_config"]
ami = "${lookup(var.amis, lookup(var.os_versions, "default"))}"
instance_type = "${lookup(var.instance_types, "cloudera_director_client")}"
security_groups = ["${var.security_group}"]
key_name = "${var.key_name}"
tags = {
Name = "cloudera_director_client"
App = "${var.tag_app}"
Env = "${var.tag_env}"
Owner = "${var.tag_owner}"
}
connection {
type = "ssh"
user = "${lookup(var.users, lookup(var.amis, lookup(var.os_versions, "default")))}"
key_file = "${var.key_file}"
}
provisioner "file" {
source = "puppet"
destination = "${var.puppet_path}"
}
provisioner "file" {
source = "${var.key_file}"
destination = "~/.ssh/${var.key_name}"
}
provisioner "remote-exec" {
inline = [
"export PUPPET_ROLE=cloudera_director_client",
"sudo chmod +x ${var.puppet_path}/puppet/puppet.sh",
"${var.puppet_path}/puppet/puppet.sh"
]
}
count = 1
}
resource "null_resource" "null_dynamic_config_flume" {
depends_on = ["aws_instance.node_elasticsearch",
"aws_instance.cloudera_director_client"]
provisioner "local-exec" {
command = <<EOF
HADOOP_NAMENODE=$(./bootstrap_cdh.py --cluster ${var.cluster_name} --server http://${aws_instance.cloudera_director_client.public_ip}:7189 --deploy ${var.deploy_cloudera_cluster})
FILE_PATH=puppet/hiera/hieradata/dynamic.yaml
printf 'profiles::flume_collector::elasticsearch_node: '\''${element(aws_instance.node_elasticsearch.*.private_ip, 0)}'\''\n' >> $FILE_PATH
printf "profiles::flume_collector::hadoop_namenode: '$HADOOP_NAMENODE'\n" >> $FILE_PATH
cat $FILE_PATH
EOF
}
}
resource "null_resource" "null_post_deployment" {
depends_on = ["aws_instance.node_log_generator",
"aws_instance.node_elasticsearch",
"aws_instance.cloudera_director_client"]
provisioner "local-exec" {
command = <<EOF
rm -rf puppet/hiera/hieradata/dynamic.yaml
cd puppet
bundle exec rake clean
cd ..
EOF
}
}
output "public_ip_node_log_generator" {
value = "${join(",", aws_instance.node_log_generator.*.public_ip)}"
}
output "public_ip_node_elasticsearch" {
value = "${join(",", aws_instance.node_elasticsearch.*.public_ip)}"
}
output "public_ip_node_cloudera_director" {
value = "${join(",", aws_instance.cloudera_director_client.*.public_ip)}"
}