I have an AWS Auto-Scaling Group, a Launch Configuration, and an Auto-Scaling Group Policy defined in Terraform like this:
resource "aws_autoscaling_group" "default" {
name = "..."
health_check_type = "EC2"
vpc_zone_identifier = ["${...}"]
min_size = "${var.asg_capacity}"
max_size = "${var.asg_capacity * 2}"
desired_capacity = "${var.asg_capacity}"
launch_configuration = "${aws_launch_configuration.default.id}"
termination_policies = ["OldestInstance"]
}
resource "aws_autoscaling_policy" "default" {
name = "..."
autoscaling_group_name = "${aws_autoscaling_group.default.name}"
scaling_adjustment = "${var.asg_capacity}"
adjustment_type = "ChangeInCapacity"
cooldown = 300
}
resource "aws_launch_configuration" "default" {
name_prefix = "..._"
image_id = "${var.coreos_ami_id}"
instance_type = "${var.ec2_instance_type}"
iam_instance_profile = "${aws_iam_instance_profile.default.arn}"
key_name = "..."
security_groups = ["${aws_security_group.default.id}"]
user_data = "${data.template_file.cloud_init.rendered}"
lifecycle {
create_before_destroy = true
}
}
When I change my user data, a new launch configuration is created and then attached to the auto-scaling group. I would assume that this would cause the auto-scaling group to scale up by var.asg_capacity
instances, wait 300 seconds, and then tear down the old ones as per OldestInstance
.
When I have done similar things in CloudFormation, I have used the following configuration options:
ASG:
Type: AWS::AutoScaling::AutoScalingGroup
UpdatePolicy:
AutoScaleRollingUpdate:
# during a scale, 6 instances in service
MaxBatchSize: 3
MinInstancesInService: 3
PauseTime: PT5M
Properties:
...
Is there an analog for this in Terraform? I would really like my auto-scaling groups to change when I change the launch configuration.