Deploy EC2 Autoscaling with running EC2 instances


I deploy EC2 Auto Scaling for a number of EC2 Linux instances that are already build and running.

Can I do this with Terraform or Terraform only allows to create AWS autoscaling using new EC2 instances?

Hi @acami26,

I don’t think the AWS provider supports attaching existing instances. The AWS provider codebase does not seem to include any calls to the autoscaling:AttachInstances action, which seems to be the AWS API action that would allow attaching an existing instance to an autoscaling group.

The typical way to use autoscaling groups in Terraform is for Terraform to only directly match the autoscaling group and then let the autoscaling system be responsible for the instances. If you would be satisfied by that arrangement then you could potentially declare and create the autoscaling group with Terraform and then use the AWS CLI to attach the instances. Terraform would then continue to manage the autoscaling group, but the instances would become the responsibility of autoscaling and not be managed by Terraform.

1 Like