This module is used to create an Auto Scaling Group of ECS container instances. It works with terraform-aws-ecs-service-pipeline for deploying ECS services on top of these container instances, and terraform-aws-asg-pipeline for deploying new AMIs to these container instances.
- The Auto Scaling Group is created with terraform-aws-asg-pipeline so a pipeline can optionally be used to deploy new AMIs.
- Lifecycle hooks ensure that instances have joined the ECS cluster before they are put in service.
- Lifecycle hooks ensure that instances have been drained of tasks before they are terminated.
- CloudWatch Agent is started as a daemon service.
- Creates an auto scaling capacity provider.
- Not compatible with blue/green deployments.
- See terraform-aws-ecs-service-pipeline for an example of a compatible ECS service.
The following diagram shows how we have used this module to handle AMI deployments to ECS container instances in multiple environments. Deployments always roll out to the development environment straight away, but require approval before being promoted to the staging and production environments.
The following diagram shows at a higher level how we have used this module in conjunction with the terraform-aws-ecs-service-pipeline module to provide a complete ECS-on-EC2 solution.
- Use this module in one or more environments.
- Use the
s3-source
module from terraform-aws-asg-pipeline to create an S3 bucket for manifests of AMIs to be deployed by the pipeline.- Or create the S3 bucket yourself. You'll just need to build the simple
source_location
object to pass into thepipeline
module.
- Or create the S3 bucket yourself. You'll just need to build the simple
- Use the
pipeline
module from terraform-aws-asg-pipeline to create a pipeline.- Specify
type=ami
. - Pass in the S3 source details as the
source_location
. - Pass in the
pipeline_target
output from anywhere you used this module.
- Specify
- Not included: Write AMI manifests to the S3 bucket location to trigger the pipeline.
- Use Packer to build a custom AMI and upload a zipped manifest to the S3 bucket.
- Attach a Lambda function to Amazon ECS-optimized AMI update notifications and upload a fake Packer manifest to the S3 bucket, to roll out the new AMI automatically when AWS releases them.