Skip to content
Merged
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
2 changes: 2 additions & 0 deletions environments/dev/alb-asg/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ module "asg" {
environment = var.environment
cost_center = var.cost_center
application = var.application
instance_warmup_time = var.instance_warmup_time
target_value = var.target_value
alb_target_group_arn = module.alb.alb_target_group_arn
iam_role = module.iam-policy.iam_role
security_group_ids = module.instance-sg.security_group_ids
Expand Down
10 changes: 10 additions & 0 deletions environments/dev/alb-asg/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,13 @@ variable "alb_create_egress_sg" {
type = bool
description = "Enable or disable CIDR block egress rules."
}

variable "instance_warmup_time" {
description = "Time required to warm up a new instance"
type = number
}

variable "target_value" {
description = "Threshold value of asg to start scaling"
type = number
}
16 changes: 16 additions & 0 deletions modules/asg/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ resource "aws_autoscaling_group" "application_asg" {

}

resource "aws_autoscaling_policy" "cpu_scaling_policy" {
name = "${var.environment}-${var.application}-cpu-scaling-policy"
policy_type = "TargetTrackingScaling"
estimated_instance_warmup = var.instance_warmup_time
autoscaling_group_name = aws_autoscaling_group.application_asg.name

target_tracking_configuration {
predefined_metric_specification {
predefined_metric_type = "ASGAverageCPUUtilization"
}

target_value = var.target_value
}
}


resource "aws_autoscaling_attachment" "application_asg_attachment" {
autoscaling_group_name = aws_autoscaling_group.application_asg.name
lb_target_group_arn = var.alb_target_group_arn
Expand Down
9 changes: 9 additions & 0 deletions modules/asg/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,12 @@ variable "alb_target_group_arn" {
type = string
}

variable "instance_warmup_time" {
description = "Time required to warm up a new instance"
type = number
}

variable "target_value" {
description = "Threshold value of asg to start scaling"
type = number
}
8 changes: 5 additions & 3 deletions vars/dev/alb-asg.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ alb_egress_sg_protocol = ["-1"]
alb_create_egress_sg = false

# instance sg
ingress_cidr_from_port = [80]
ingress_cidr_to_port = [80]
ingress_cidr_from_port = [22]
ingress_cidr_to_port = [22]
ingress_cidr_protocol = ["tcp"]
ingress_cidr_block = ["0.0.0.0/0"]
create_ingress_cidr = true
Expand Down Expand Up @@ -86,10 +86,12 @@ user_data = <<-EOF
EOF

#autoscaling_group
max_size = 1
max_size = 2
min_size = 1
desired_capacity = 1
propagate_at_launch = true
instance_warmup_time = 30
target_value = 50

#tags
owner = "techiescamp"
Expand Down