From 186c88a34babd7d9ad491f5493059d292cfeb14c Mon Sep 17 00:00:00 2001 From: "Thierno IB. BARRY" Date: Thu, 26 Sep 2019 19:40:41 +0200 Subject: [PATCH] Add option to enable lifecycle hooks creation (#532) * add option to enable lifecycle hooks creation * update changelog --- CHANGELOG.md | 2 +- README.md | 1 + variables.tf | 6 ++++++ workers.tf | 6 +++--- workers_launch_template.tf | 6 +++--- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8222332..6cd22ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Changed - - Write your awesome change here (by @you) + - Add option to enable lifecycle hooks creation (by @barryib) # History diff --git a/README.md b/README.md index 1c338fe..c79b595 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a | worker\_additional\_security\_group\_ids | A list of additional security group ids to attach to worker instances | list(string) | `[]` | no | | worker\_ami\_name\_filter | Additional name filter for AWS EKS worker AMI. Default behaviour will get latest for the cluster_version but could be set to a release from amazon-eks-ami, e.g. "v20190220" | string | `"v*"` | no | | worker\_ami\_name\_filter\_prefix | Name prefix filter for AWS EKS worker AMI. Default behaviour will get regular EKS-Optimized AMI but could be set to a EKS-Optimized AMI with GPU Support, e.g. "amazon-eks-gpu-node", or custom AMI | string | `"amazon-eks-node"` | no | +| worker\_create\_initial\_lifecycle\_hooks | Whether to create initial lifecycle hooks provided in worker groups. | bool | `"false"` | no | | worker\_create\_security\_group | Whether to create a security group for the workers or attach the workers to `worker_security_group_id`. | bool | `"true"` | no | | worker\_groups | A list of maps defining worker group configurations to be defined using AWS Launch Configurations. See workers_group_defaults for valid keys. | any | `[]` | no | | worker\_groups\_launch\_template | A list of maps defining worker group configurations to be defined using AWS Launch Templates. See workers_group_defaults for valid keys. | any | `[]` | no | diff --git a/variables.tf b/variables.tf index 47d49e7..13435c9 100644 --- a/variables.tf +++ b/variables.tf @@ -210,6 +210,12 @@ variable "worker_create_security_group" { default = true } +variable "worker_create_initial_lifecycle_hooks" { + description = "Whether to create initial lifecycle hooks provided in worker groups." + type = bool + default = false +} + variable "permissions_boundary" { description = "If provided, all IAM roles will be created with this permissions boundary attached." type = string diff --git a/workers.tf b/workers.tf index 45db1e4..5f5ee1d 100644 --- a/workers.tf +++ b/workers.tf @@ -75,10 +75,10 @@ resource "aws_autoscaling_group" "workers" { ) dynamic "initial_lifecycle_hook" { - for_each = lookup(var.worker_groups[count.index], "asg_initial_lifecycle_hooks", local.workers_group_defaults["asg_initial_lifecycle_hooks"]) + for_each = var.worker_create_initial_lifecycle_hooks ? 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) + name = initial_lifecycle_hook.value["name"] + lifecycle_transition = initial_lifecycle_hook.value["lifecycle_transition"] 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) diff --git a/workers_launch_template.tf b/workers_launch_template.tf index 258d536..e44a909 100644 --- a/workers_launch_template.tf +++ b/workers_launch_template.tf @@ -151,10 +151,10 @@ 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"]) + for_each = var.worker_create_initial_lifecycle_hooks ? 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) + name = initial_lifecycle_hook.value["name"] + lifecycle_transition = initial_lifecycle_hook.value["lifecycle_transition"] 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)