-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhiver-asg.tf
64 lines (49 loc) · 1.76 KB
/
hiver-asg.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
## Launch config and auto scaling configuration
locals {
ec2-userdata = <<USERDATA
#!/bin/bash -xe
sudo apt-get update -y
# install docker
sudo curl https://releases.rancher.com/install-docker/17.03.sh | sh
sudo usermod -a -G docker admin
# create custom index.html
sudo mkdir -p /opt/hiver
sudo chown -R admin.admin /opt/hiver
echo "Hello Hiver!" > /opt/hiver/index.html
# Run nginx container with custom html page.
sudo docker run --name hiver-nginx --restart=unless-stopped -v /opt/hiver:/usr/share/nginx/html:ro -d -p 8080:80 nginx
USERDATA
}
resource "aws_launch_configuration" "hiver-lc" {
image_id = "${var.ami}"
instance_type = "${var.instance_type}"
key_name = "${var.ssh_key_pair}"
name_prefix = "hiver-lc"
security_groups = ["${aws_security_group.hiver-instance-sg.id}"]
user_data_base64 = "${base64encode(local.ec2-userdata)}"
#user_data = ${data.template_file.init.rendered} # this can be used to load dynamic values into userdata script
associate_public_ip_address = true
root_block_device {
delete_on_termination = true
volume_size = 10
volume_type = "gp2"
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "hiver-asg" {
#depends_on = [aws_rds_cluster.aurora_cluster]
desired_capacity = 2
launch_configuration = "${aws_launch_configuration.hiver-lc.id}"
max_size = 2
min_size = 2
name = "hiver-asg"
load_balancers = ["${aws_elb.hiver-elb.name}"]
vpc_zone_identifier = ["${aws_subnet.hiver-demo.0.id}"]
tag {
key = "Name"
value = "TestInstance"
propagate_at_launch = true
}
}