Skip to content

Commit

Permalink
Merged in dev/can/MPC-6922-ems-warm-pool-2022-09-01 (pull request ela…
Browse files Browse the repository at this point in the history
…stic#878)

MPC-6922: Enable warm pool for ems

Approved-by: Gideon Avida
Approved-by: Hiroshi Ishii
  • Loading branch information
Can Yildiz committed Sep 2, 2022
1 parent d38d9eb commit 152f9fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
25 changes: 12 additions & 13 deletions aws/ams-cluster-v1-tf/ems.tf
Expand Up @@ -112,9 +112,11 @@ data "aws_ami" "ems" {
}

resource "aws_launch_template" "ems" {
name = "tf-${var.stack_name}-ems-lt"
for_each = var.ems_asg_config
name = "tf-${var.stack_name}-ems-${each.key}-lt"
description = "Launch template for EMS ASG"
image_id = var.ami_ids["ems"] == "" ? data.aws_ami.ems.image_id : var.ami_ids["ems"]
instance_type = each.value.instance_type
key_name = var.key_name
user_data = base64encode(templatefile("templates/user_data.tpl", { wazuh_agent_enabled = var.wazuh_agent_enabled }))
iam_instance_profile {
Expand All @@ -125,7 +127,6 @@ resource "aws_launch_template" "ems" {
security_groups = [
aws_security_group.ems_redis_clients.id,
aws_security_group.ems.id,
# TODO: add bastion for SSH access
]
}
instance_initiated_shutdown_behavior = "terminate"
Expand Down Expand Up @@ -162,7 +163,7 @@ resource "aws_launch_template" "ems" {
)
}
tags = {
Name = "tf-${var.stack_name}-ems-lt"
Name = "tf-${var.stack_name}-ems-${each.key}-lt"
}
}

Expand All @@ -177,17 +178,15 @@ resource "aws_autoscaling_group" "ems" {
default_cooldown = var.ems_asg_default_cooldown
health_check_grace_period = 60

mixed_instances_policy {
launch_template {
launch_template_specification {
launch_template_id = aws_launch_template.ems.id
version = "$Latest"
}
launch_template {
id = aws_launch_template.ems["${each.key}"].id
version = "$Latest"
}

override {
instance_type = each.value.instance_type
}
}
warm_pool {
pool_state = "Stopped"
min_size = var.ems_asg_warm_pool_min_size
max_group_prepared_capacity = var.ems_asg_warm_pool_max_size
}

health_check_type = var.ems_asg_health_check_type
Expand Down
12 changes: 12 additions & 0 deletions aws/ams-cluster-v1-tf/variables.tf
Expand Up @@ -109,6 +109,18 @@ variable "ems_asg_config" {
)
}

variable "ems_asg_warm_pool_min_size" {
description = "Minimum size for EMS autoscaling warm pool"
type = number
default = 0
}

variable "ems_asg_warm_pool_max_size" {
description = "Maximum size for EMS autoscaling warm pool"
type = number
default = 0
}

variable "ems_asg_health_check_type" {
description = "ELB or EC2 (for dev)"
type = string
Expand Down

0 comments on commit 152f9fd

Please sign in to comment.