Creating an Auto Scaling group using Terraform
So far, we have created Auto Scaling groups manually, but as we did in other chapters, we will also see how to automate the process of Auto Scaling group creation using Terraform. These are the steps that we need to follow:
- The first step is to create the launch configuration. For that purpose, we are going to use the
aws_launch_configuration
resource. This is going to specify how to configure each EC2 instance's parameters, such as the image ID (AMI), instance type, security group, and user data. - The new parameter that is defined here is the life cycle (
create_before_destroy
). This is always going to involve creating a resource before destroying it. For example, in the case of an EC2 instance, before terminating any instance, it always creates a new one, waits for it to come up, and then removes the old EC2 instance:resource "aws_launch_configuration" "my-asg-launch-config" { image_id&...