Skip to content

Commit

Permalink
Merge pull request #37 from meltwater/readme-improvements
Browse files Browse the repository at this point in the history
[docs] README Improvements
  • Loading branch information
hikerspath authored Jul 17, 2021
2 parents 5e133e1 + 1cd2ccf commit c08fb91
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

## Purpose

This Terraform module sets up everything necessary for dynamically setting hostnames following a certain pattern on instances spawned by AWS Auto Scaling Groups (ASGs).
This Terraform module sets up everything necessary for dynamically setting hostnames following a certain pattern on instances spawned by AWS Auto Scaling Groups (ASGs).

Learn more about our motivation to build this module in [this blog post](https://underthehood.meltwater.com/blog/2020/02/07/dynamic-route53-records-for-aws-auto-scaling-groups-with-terraform/).
Learn more about our motivation to build this module in our blog post [Dynamic Route53 records for AWS Auto Scaling Groups with Terraform](https://underthehood.meltwater.com/blog/2020/02/07/dynamic-route53-records-for-aws-auto-scaling-groups-with-terraform/).

# Requirements
## Requirements

- [Terraform](https://www.terraform.io/downloads.html) 0.12+
- [Terraform AWS provider](https://github.com/terraform-providers/terraform-provider-aws) 2.0+
Expand All @@ -30,7 +30,7 @@ tag {
propagate_at_launch = true
}
```

Once you have your ASG set up, you can just invoke this module and point to it:
```hcl
module "clever_name_autoscale_dns" {
Expand All @@ -45,26 +45,26 @@ module "clever_name_autoscale_dns" {

## How does it work?

The module sets up the following
The module sets up these things:

- A SNS topic
- A Lambda function
- A topic subscription sending SNS events to the Lambda function
1. A SNS topic
2. A Lambda function
3. A topic subscription sending SNS events to the Lambda function

The Lambda function then does the following:

- Fetch the `asg:hostname_pattern` tag value from the ASG, and parse out the hostname and Route53 zone ID from it.
- If it's a instance being created
- If it's an instance being **created**
- Fetch internal IP from EC2 API
- Create a Route53 record pointing the hostname to the IP
- Set the Name tag of the instance to the initial part of the generated hostname
- If it's an instance being deleted
- If it's an instance being **deleted**
- Fetch the internal IP from the existing record from the Route53 API
- Delete the record

## Setup

Add `initial_lifecycle_hook` definitions to your `aws_autoscaling_group resource` , like so:
Add `initial_lifecycle_hook` definitions to your `aws_autoscaling_group` resource , like so:

```hcl
resource "aws_autoscaling_group" "my_asg" {
Expand Down Expand Up @@ -113,7 +113,7 @@ resource "aws_autoscaling_group" "my_asg" {
module "autoscale_dns" {
source = "meltwater/asg-dns-handler/aws"
version = "x.y.z"
autoscale_handler_unique_identifier = "my_asg_handler"
autoscale_route53zone_arn = var.internal_zone_id
vpc_name = var.vpc_name
Expand All @@ -122,17 +122,13 @@ module "autoscale_dns" {

## Difference between Lifecycle action

Lifecycle_hook can have `CONTINUE` or `ABANDON` as default_result. By setting default_result to `ABANDON` will terminate the instance if the lambda function fails to update the DNS record as required. `Complete_lifecycle_action` in lambda function returns `LifecycleActionResult` as `CONTINUE` on success to Lifecycle_hook. But if lambda function fails, Lifecycle_hook doesn't get any response from `Complete_lifecycle_action` which results in timeout and terminates the instance.
Lifecycle_hook can have `CONTINUE` or `ABANDON` as default_result. By setting default_result to `ABANDON` will terminate the instance if the lambda function fails to update the DNS record as required. `Complete_lifecycle_action` in lambda function returns `LifecycleActionResult` as `CONTINUE` on success to Lifecycle_hook. But if lambda function fails, Lifecycle_hook doesn't get any response from `Complete_lifecycle_action` which results in timeout and terminates the instance.

At the conclusion of a lifecycle hook, the result is either ABANDON or CONTINUE.
If the instance is launching, CONTINUE indicates that your actions were successful, and that the instance can be put into service. Otherwise, ABANDON indicates that your custom actions were unsuccessful, and that the instance can be terminated.

If the instance is terminating, both ABANDON and CONTINUE allow the instance to terminate. However, ABANDON stops any remaining actions, such as other lifecycle hooks, while CONTINUE allows any other lifecycle hooks to complete.

## TODO

- Reverse lookup records?

## License and Copyright

This project was built at Meltwater. It is licensed under the [Apache License 2.0](LICENSE).

0 comments on commit c08fb91

Please sign in to comment.