Files
terraform-course/demo-16/autoscaling.tf
T
Edward Viaene f73082efe5 Update autoscaling.tf
added apt-get update
2017-07-08 13:07:02 +02:00

29 lines
1.1 KiB
Terraform

resource "aws_launch_configuration" "example-launchconfig" {
name_prefix = "example-launchconfig"
image_id = "${lookup(var.AMIS, var.AWS_REGION)}"
instance_type = "t2.micro"
key_name = "${aws_key_pair.mykeypair.key_name}"
security_groups = ["${aws_security_group.myinstance.id}"]
user_data = "#!/bin/bash\napt-get update\napt-get -y install nginx\nMYIP=`ifconfig | grep 'addr:10' | awk '{ print $2 }' | cut -d ':' -f2`\necho 'this is: '$MYIP > /var/www/html/index.html"
lifecycle { create_before_destroy = true }
}
resource "aws_autoscaling_group" "example-autoscaling" {
name = "example-autoscaling"
vpc_zone_identifier = ["${aws_subnet.main-public-1.id}", "${aws_subnet.main-public-2.id}"]
launch_configuration = "${aws_launch_configuration.example-launchconfig.name}"
min_size = 2
max_size = 2
health_check_grace_period = 300
health_check_type = "ELB"
load_balancers = ["${aws_elb.my-elb.name}"]
force_delete = true
tag {
key = "Name"
value = "ec2 instance"
propagate_at_launch = true
}
}