mirror of
https://github.com/farcasclaudiu/terraform-course.git
synced 2026-06-26 03:02:04 +03:00
f73082efe5
added apt-get update
29 lines
1.1 KiB
Terraform
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
|
|
}
|
|
}
|
|
|