This template sets up an AWS Autoscaling Group and attaches a Lifecycle Hook to it. The hook triggers when an EC2 instance is launching.

Terraform Template