From d12a7962c92cd72757d8cffd098958e09bd679e8 Mon Sep 17 00:00:00 2001 From: Akhil Kanaskar Date: Fri, 10 Nov 2017 17:14:00 -0600 Subject: [PATCH] If there is changes to usedata the asg doesnt update the instances. it creates a new launch configuration but doesnt reprovision the instances with new userdata. These changes are to incorporate new instances in case of changes to userdata,instance_type etc. Also added min_size , max_size, desired_capacity, min_elb_capacity variables to asg for etcd members --- terraform/platforms/aws/README.md | 5 ++++- terraform/platforms/aws/asg.tf | 14 +++++++++----- terraform/platforms/aws/variables.tf | 16 ++++++++++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/terraform/platforms/aws/README.md b/terraform/platforms/aws/README.md index dd68fe61..0af09b33 100644 --- a/terraform/platforms/aws/README.md +++ b/terraform/platforms/aws/README.md @@ -75,7 +75,10 @@ module "eco" { source = "github.com/Quentin-M/etcd-cloud-operator//terraform/platforms/aws" name = "eco-example" - size = "3" + max_size = "7" + min_size = "3" + desired_capacity = "3" + min_elb_capacity = "3" instance_type = "t2.small" instance_disk_size = "30" diff --git a/terraform/platforms/aws/asg.tf b/terraform/platforms/aws/asg.tf index 4515138e..73e8be7c 100644 --- a/terraform/platforms/aws/asg.tf +++ b/terraform/platforms/aws/asg.tf @@ -37,11 +37,12 @@ data "aws_ami" "coreos" { } resource "aws_autoscaling_group" "main" { - name = "${var.name}" + name = "${var.name}-${aws_launch_configuration.main.name}" - max_size = "${var.size}" - min_size = "${var.size}" - desired_capacity = "${var.size}" + max_size = "${var.max_size}" + min_size = "${var.min_size}" + desired_capacity = "${var.desired_capacity}" + min_elb_capacity = "${var.min_elb_capacity}" load_balancers = ["${aws_elb.clients.name}"] health_check_grace_period = 120 @@ -50,6 +51,10 @@ resource "aws_autoscaling_group" "main" { vpc_zone_identifier = ["${var.subnets_ids}"] launch_configuration = "${aws_launch_configuration.main.name}" + lifecycle { + create_before_destroy = true + } + tags = [ { key = "Name" @@ -60,7 +65,6 @@ resource "aws_autoscaling_group" "main" { } resource "aws_launch_configuration" "main" { - name_prefix = "${var.name}" image_id = "${data.aws_ami.coreos.image_id}" instance_type = "${var.instance_type}" diff --git a/terraform/platforms/aws/variables.tf b/terraform/platforms/aws/variables.tf index 13e9548e..fc04ca42 100644 --- a/terraform/platforms/aws/variables.tf +++ b/terraform/platforms/aws/variables.tf @@ -16,8 +16,20 @@ variable "name" { description = "Name of the deployment" } -variable "size" { - description = "Number of etcd members (must be odd)" +variable "max_size" { + description = "Number of max etcd members in ASG (must be odd)" +} + +variable "min_size" { + description = "Number of min etcd members in ASG (must be odd)" +} + +variable "desired_capacity" { + description = "Number of desired etcd members in ASG (must be odd)" +} + +variable "min_elb_capacity" { + description = "Number of minimum elb capacity for ASG (must be same as min_size)" } variable "instance_type" {