How to recreate instances of the EC2 terraform autoscale group?

Scenario: I run the AWS autoscale group (ASG), and I changed the associated launch configuration while applying terraform. ASG remains unaffected.

How do I now recreate instances in this ASG (i.e. replace them one by one to make a rolling replacement), which is then based on a modified / new launch configuration?

What I tried: with terraform taint, you can mark the resources that need to be destroyed and recreated during the next application. However, I do not want to spoof the autoscale group (which is a resource, and individual instances are not in this case), but individual instances in it. Is there a way to trick individual instances, or am I thinking in the wrong direction?

+4
source share
2 answers

Here you usually need to use the Terraform Lifecycle Management to force it to create new resources before destroying the old ones.

:

resource "aws_launch_configuration" "as_conf" {
    name_prefix = "terraform-lc-example-"
    image_id = "${var.ami_id}"
    instance_type = "t1.micro"

    lifecycle {
      create_before_destroy = true
    }
}

resource "aws_autoscaling_group" "bar" {
    name = "terraform-asg-example-${aws_launch_configuration.as_conf.name}"
    launch_configuration = "${aws_launch_configuration.as_conf.name}"

    lifecycle {
      create_before_destroy = true
    }
}

, ami_id, AMI Terraform, , , . , LC, ASG, ASG .

create_before_destroy Terraform LC ASG , ASG ( ), ASG, LC.

ASG . , 2 ASG, 2 , , 2 . , ELB ASG, ELB, 4 , 2.

+9

Source: https://habr.com/ru/post/1653771/


All Articles