Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added autoscaling variable #303

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .main.tf.swp
Binary file not shown.
11 changes: 7 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,11 @@ resource "aws_launch_template" "launch_template" {
user_data = base64encode(local.user_data)
depends_on = [aws_placement_group.placement_group, aws_kms_key.kms_key]
}

resource "aws_autoscaling_group" "autoscaling_group" {
count = var.enable_autoscaling ? 1 : 0 # Add this line to conditionally create the resource

name = "${var.prefix}-${var.cluster_name}-autoscaling-group"
#availability_zones = [ for z in var.availability_zones: format("%s%s", local.region,z) ]
# availability_zones = [ for z in var.availability_zones: format("%s%s", local.region, z) ]
desired_capacity = var.cluster_size
max_size = var.cluster_size * 7
min_size = var.cluster_size
Expand All @@ -242,23 +243,25 @@ resource "aws_autoscaling_group" "autoscaling_group" {
id = aws_launch_template.launch_template.id
version = aws_launch_template.launch_template.latest_version
}

tag {
key = "${var.prefix}-${var.cluster_name}-asg"
propagate_at_launch = true
value = var.cluster_name
propagate_at_launch = true
}

dynamic "tag" {
for_each = var.tags_map
content {
key = tag.key
value = tag.value
propagate_at_launch = false # already propagated by launch template
propagate_at_launch = false # Already propagated by launch template
}
}

lifecycle {
ignore_changes = [desired_capacity, min_size, max_size]
}

depends_on = [aws_launch_template.launch_template, aws_placement_group.placement_group]
}
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -842,3 +842,8 @@ variable "lambdas_custom_s3_key" {
description = "S3 key for lambdas"
default = null
}
variable "enable_autoscaling" {
description = "Enable or disable the autoscaling group"
type = bool
default = true
}
Loading