Skip to content

Commit

Permalink
add initial lifecycle hooks for autosacling groups (terraform-aws-mod…
Browse files Browse the repository at this point in the history
  • Loading branch information
barryib authored and max-rocket-internet committed Aug 20, 2019
1 parent d8ed7d0 commit d6d0975
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
- Added support for workers iam role tag in `./workers.tf` (@lucas-giaco)
- Added `required_providers` to enforce provider minimum versions (by @dpiddockcmp)
- Updated `local.spot_allocation_strategy` docstring to indicate availability of new `capacity-optimized` option. (by @sc250024)
- Added support for initial lifecycle hooks for autosacling groups (@barryib)
- Added option to recreate ASG when LT or LC changes (by @barryib)

### Changed
Expand Down
1 change: 1 addition & 0 deletions local.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ locals {
asg_max_size = "3" # Maximum worker capacity in the autoscaling group.
asg_min_size = "1" # Minimum worker capacity in the autoscaling group.
asg_force_delete = false # Enable forced deletion for the autoscaling group.
asg_initial_lifecycle_hooks = [] # Initital lifecycle hook for the autoscaling group.
asg_recreate_on_change = false # Recreate the autoscaling group when LT or LC change.
instance_type = "m4.large" # Size of the workers instances.
spot_price = "" # Cost of spot instance.
Expand Down
13 changes: 13 additions & 0 deletions workers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ resource "aws_autoscaling_group" "workers" {
local.workers_group_defaults["termination_policies"]
)

dynamic "initial_lifecycle_hook" {
for_each = lookup(var.worker_groups[count.index], "asg_initial_lifecycle_hooks", local.workers_group_defaults["asg_initial_lifecycle_hooks"])
content {
name = lookup(initial_lifecycle_hook.value, "name", null)
lifecycle_transition = lookup(initial_lifecycle_hook.value, "lifecycle_transition", null)
notification_metadata = lookup(initial_lifecycle_hook.value, "notification_metadata", null)
heartbeat_timeout = lookup(initial_lifecycle_hook.value, "heartbeat_timeout", null)
notification_target_arn = lookup(initial_lifecycle_hook.value, "notification_target_arn", null)
role_arn = lookup(initial_lifecycle_hook.value, "role_arn", null)
default_result = lookup(initial_lifecycle_hook.value, "default_result", null)
}
}

tags = concat(
[
{
Expand Down
13 changes: 13 additions & 0 deletions workers_launch_template.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ resource "aws_autoscaling_group" "workers_launch_template" {
)
}

dynamic "initial_lifecycle_hook" {
for_each = lookup(var.worker_groups_launch_template[count.index], "asg_initial_lifecycle_hooks", local.workers_group_defaults["asg_initial_lifecycle_hooks"])
content {
name = lookup(initial_lifecycle_hook.value, "name", null)
lifecycle_transition = lookup(initial_lifecycle_hook.value, "lifecycle_transition", null)
notification_metadata = lookup(initial_lifecycle_hook.value, "notification_metadata", null)
heartbeat_timeout = lookup(initial_lifecycle_hook.value, "heartbeat_timeout", null)
notification_target_arn = lookup(initial_lifecycle_hook.value, "notification_target_arn", null)
role_arn = lookup(initial_lifecycle_hook.value, "role_arn", null)
default_result = lookup(initial_lifecycle_hook.value, "default_result", null)
}
}

tags = concat(
[
{
Expand Down
13 changes: 13 additions & 0 deletions workers_launch_template_mixed.tf
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ resource "aws_autoscaling_group" "workers_launch_template_mixed" {
}
}

dynamic "initial_lifecycle_hook" {
for_each = lookup(var.worker_groups_launch_template_mixed[count.index], "asg_initial_lifecycle_hooks", local.workers_group_defaults["asg_initial_lifecycle_hooks"])
content {
name = lookup(initial_lifecycle_hook.value, "name", null)
default_result = lookup(initial_lifecycle_hook.value, "default_result", null)
heartbeat_timeout = lookup(initial_lifecycle_hook.value, "heartbeat_timeout", null)
lifecycle_transition = lookup(initial_lifecycle_hook.value, "lifecycle_transition", null)
notification_metadata = lookup(initial_lifecycle_hook.value, "notification_metadata", null)
notification_target_arn = lookup(initial_lifecycle_hook.value, "notification_target_arn", null)
role_arn = lookup(initial_lifecycle_hook.value, "role_arn", null)
}
}

tags = concat(
[
{
Expand Down

0 comments on commit d6d0975

Please sign in to comment.