fpco / terraform-aws-foundation

Establish a solid Foundation on AWS with these modules for Terraform
MIT License
204 stars 97 forks source link

new example: demonstrate basic ASG integration with Lifecycle Hooks #188

Closed ketzacoatl closed 5 years ago

ketzacoatl commented 5 years ago

Autoscaling Groups can be setup with one or more Lifecycle hooks, which can then be used to take specific actions as EC2 instances pass through the various states of their "lifecycle". In essence, lifecycle hooks put EC2 instances in a "paused/pending" state before going into service, and before terminating. However, implementing the full picture requires linking together several components, and there are some options for how it's all setup.

The goal of this ticket is to produce an initial example that we can use to explore specific use cases and implementation ideas when in those scenarios. Future tickets can add to this example or create additional variations on the example to cover other use cases.

We're already using user_data for init (though lifecycle hooks could still bring improvements there), so at least right now, we're primarily interested in taking actions before terminating an EC2 instance.

Specifically, we'd like build out coverage for:

We are interested in two main ways to run actions on lifecycle events:

Interacting with the AWS API is a pretty easy thing to do with lambda, but using tools like kubectl to interact with cluster management APIs is not. Due to our use of cluster management tools, running the tool/script from an EC2 instance is more useful and desirable than running from lambda. However, we would like to demonstrate how to use lambda for running actions on lifecycle events.

Requirements

Resources

ketzacoatl commented 5 years ago

Sending to @psibi for review.