From d6d097545278f07e18261127d1fbc51feb43bb93 Mon Sep 17 00:00:00 2001 From: "Thierno IB. BARRY" Date: Tue, 20 Aug 2019 15:45:06 +0200 Subject: [PATCH] add initial lifecycle hooks for autosacling groups (#466) --- CHANGELOG.md | 1 + local.tf | 1 + workers.tf | 13 +++++++++++++ workers_launch_template.tf | 13 +++++++++++++ workers_launch_template_mixed.tf | 13 +++++++++++++ 5 files changed, 41 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2998cce..f211f88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/local.tf b/local.tf index 98d3909..c4cdab0 100644 --- a/local.tf +++ b/local.tf @@ -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. diff --git a/workers.tf b/workers.tf index 7446855..d924308 100644 --- a/workers.tf +++ b/workers.tf @@ -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( [ { diff --git a/workers_launch_template.tf b/workers_launch_template.tf index 46eef4c..18d09ba 100644 --- a/workers_launch_template.tf +++ b/workers_launch_template.tf @@ -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( [ { diff --git a/workers_launch_template_mixed.tf b/workers_launch_template_mixed.tf index 75489e9..5bf66c4 100644 --- a/workers_launch_template_mixed.tf +++ b/workers_launch_template_mixed.tf @@ -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( [ {