summaryrefslogtreecommitdiffstats
path: root/asg.tf
diff options
context:
space:
mode:
authorSpike <avlampson+git@gmail.com>2019-04-07 22:03:31 +0100
committerSpike <avlampson+git@gmail.com>2019-04-07 22:03:31 +0100
commitbb81085619769aca861ab5d5bbff86f71c9435d2 (patch)
tree80b45de34d9f0647c10e6d6fae5b408c21c190c5 /asg.tf
downloadfundapp_demo-master.zip
fundapp_demo-master.tar.gz
fundapp_demo-master.tar.bz2
Autoscaling Group, and associated controls and configsHEADmaster
Diffstat (limited to 'asg.tf')
-rw-r--r--asg.tf67
1 files changed, 67 insertions, 0 deletions
diff --git a/asg.tf b/asg.tf
new file mode 100644
index 0000000..46c3616
--- /dev/null
+++ b/asg.tf
@@ -0,0 +1,67 @@
+resource "aws_launch_configuration" "fundapp_demo" {
+ name_prefix = "${var.vpc_name}_app"
+ image_id = "${var.image_id}"
+ instance_type = "t2.nano"
+ iam_instance_profile = "${aws_iam_instance_profile.app_profile.id}"
+ key_name = "${aws_key_pair.server_keypair.key_name}"
+
+ security_groups = [
+ "${aws_security_group.app_sg.id}",
+ "${aws_security_group.external_ssh_accept_sg.id}",
+ ]
+
+ user_date = "${data.template_file.app_user_data.rendered}"
+
+ root_block_device {
+ volume_type = "gp2"
+ volume_size = "30"
+ }
+
+ lifecycle {
+ create_before_destroy = true
+ }
+}
+
+resource "aws_autoscaling_group" "app_asg" {
+ name = "${var.vpc_name}_app_asg"
+ launch_configuration = "${aws_launch_configuration.fundapp_demo.name}"
+
+ availability_zones = [
+ "${var.aws_az_1}",
+ "${var.aws_az_2}",
+ "${var.aws_az_3}",
+ ]
+
+ vpc_zone_identifier = [
+ "${aws_subnet.public_1.id}",
+ "${aws_subnet.public_2.id}",
+ "${aws_subnet.public_3.id}",
+ ]
+
+ min_size = 1
+ max_size = 3
+ desired_capacity = 2
+ health_check_grace_period = 300
+
+ enabled_metrics = [
+ "GroupMinSize",
+ "GroupMazSize",
+ "GroupDesiredCapacity",
+ "GroupInServiceInstances",
+ "GroupPendingInstances",
+ "GroupStandbyInstances",
+ "GroupTerminatingInstances",
+ "GroupTotalInstances",
+ ]
+
+ load_balancers = ["${aws_elb.app_elb.name}"]
+ health_check_type = "EC2"
+
+ lifecycle {
+ create_before_destroy = true
+ }
+}
+
+data "template_file" "app_user_data" {
+ template = "${file("${path.module}/files/app_data.tpl")}"
+}