-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnode.tf
61 lines (51 loc) · 1.57 KB
/
node.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
data "template_file" "node_user_data" {
template = "${file("${path.module}/node_user_data.sh")}"
vars {
root = "${var.root}"
datadog_key = "${var.datadog_key}"
node_version = "${var.node_version}"
src_location = "${var.src_location}"
}
}
resource "aws_launch_template" "node_lt" {
image_id = "${var.ami_id}"
instance_type = "t2.micro"
key_name = "${var.key_pair_name}"
vpc_security_group_ids = ["${aws_security_group.apps.id}"]
user_data = "${base64encode("${data.template_file.node_user_data.rendered}")}"
name_prefix = "node_lt-"
lifecycle {
create_before_destroy = true
}
}
resource "aws_elb" "node_asg_elb" {
name_prefix = "node-"
availability_zones = ["${var.availability_zone}"]
security_groups = ["${aws_security_group.elb.id}"]
listener {
instance_port = 3000
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
provisioner "local-exec" {
command = "echo ${aws_elb.node_asg_elb.dns_name} > node/elb_dns"
}
}
resource "aws_autoscaling_group" "node_asg" {
name_prefix = "node_asg-"
max_size = 3
min_size = 0
desired_capacity = 1
load_balancers = ["${aws_elb.node_asg_elb.name}"]
availability_zones = ["${var.availability_zone}"]
launch_template = {
id = "${aws_launch_template.node_lt.id}"
version = "$$Latest"
}
tag {
key = "Name"
value = "tp_arqui_node_asg_instance"
propagate_at_launch = true
}
}