Reputation: 1543
I'm trying to set up an Application Load Balancer that points to an autoscaling group maintaining a group of webseevers using terraform like so:
##################################################################
# Application Load Balancer
##################################################################
module "lb" {
source = "terraform-aws-modules/alb/aws"
version = "~> 5.0"
name = "server-load-balancer"
internal = false
load_balancer_type = "application"
vpc_id = module.vpc.vpc_id
security_groups = [module.lb-security-group.this_security_group_id]
subnets = module.vpc.public_subnets
// # See notes in README (ref: https://github.com/terraform-providers/terraform-provider-aws/issues/7987)
// access_logs = {
// bucket = module.log_bucket.this_s3_bucket_id
// }
http_tcp_listeners = [
# Forward action is default, either when defined or undefined
{
port = 80
protocol = "HTTP"
target_group_index = 0
# action_type = "forward"
},
]
target_groups = [
{
# name = "server-alb"
backend_protocol = "HTTP"
backend_port = 8080
target_type = "instance"
deregistration_delay = 10
vpc_id = module.vpc.vpc_id
health_check = {
enabled = true
interval = 30
path = "/"
port = "8080"
healthy_threshold = 3
unhealthy_threshold = 3
timeout = 6
protocol = "HTTP"
matcher = "200-299"
}
tags = {
InstanceTargetGroupTag = "webservers"
}
},
]
tags = {
Name = "Load Balancer"
}
}
##################################################################
# Security Groups
##################################################################
module "lb-security-group" {
source = "terraform-aws-modules/security-group/aws"
name = "load-balancer-security-group"
description = "Security group for the Application Load Balancer on the public subnet."
vpc_id = module.vpc.vpc_id
ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["ssh-tcp", "http-80-tcp", "https-443-tcp"]
egress_rules = ["all-all"]
tags = {
Name = "Security Group"
Environment = var.environment_tag
}
}
module "autoscaler-security-group" {
source = "terraform-aws-modules/security-group/aws"
name = "autoscaler-security-group"
description = "Security group for the autoscaler on the private subnet."
vpc_id = module.vpc.vpc_id
ingress_cidr_blocks = var.private_subnet_cidrs
ingress_rules = ["http-8080-tcp", "ssh-tcp", "http-80-tcp", "https-443-tcp"]
egress_rules = ["all-all"]
tags = {
Name = "Security Group"
Environment = var.environment_tag
}
}
##################################################################
# Launch configurations and autoscaling group
##################################################################
module "autoscaler" {
source = "terraform-aws-modules/autoscaling/aws"
version = "~> 3.0"
name = "server-autoscaler"
enable_monitoring = true
# Launch configuration
#
# launch_configuration = "my-existing-launch-configuration" # Use the existing launch configuration
# create_lc = false # disables creation of launch configuration
lc_name = "server-lc"
image_id = data.aws_ami.server.id
instance_type = var.instance_type
security_groups = [module.autoscaler-security-group.this_security_group_id]
target_group_arns = module.lb.target_group_arns
associate_public_ip_address = false
recreate_asg_when_lc_changes = true
force_delete = false
user_data = data.template_file.init.rendered
root_block_device = [
{
volume_size = "5"
volume_type = "gp2"
},
]
# Auto scaling group
asg_name = "server-asg"
vpc_zone_identifier = module.vpc.private_subnets
health_check_type = "EC2"
# Time in Millisec
health_check_grace_period = 300
min_size = 1
max_size = 2
desired_capacity = 1
min_elb_capacity = 1
wait_for_capacity_timeout = 0
# service_linked_role_arn = aws_iam_service_linked_role.autoscaling.arn
tags = [
{
key = "Environment"
value = var.environment_tag
propagate_at_launch = true
},
{
key = "Project"
value = var.project
propagate_at_launch = true
},
]
}
As you can see I specify:
# Auto scaling group
asg_name = "server-asg"
vpc_zone_identifier = module.vpc.private_subnets
health_check_type = "EC2"
# Time in Millisec
health_check_grace_period = 300
min_size = 1
max_size = 2
desired_capacity = 1
min_elb_capacity = 1
wait_for_capacity_timeout = 0
in the autoscaling group, which I thought meant that there would be at least 1 instance launched and maintained and that terraform would wait for the instance to be up and healthy before moving on. However I find that terraform completes successfully but no instances are ever launched in the autoscaling group so when I go to the URL I get a 503 error.
I see in the AWS console I can register targets but I want to do everything with terraform. I looked at the example on the github here and I don't really see anything that they are doing differently.
Why aren't any instances being launched in my autoscaling group? Any help would be appreciated.
Upvotes: 2
Views: 1103
Reputation: 238111
I tried to launched your code in my sandbox environment.
I noticed that the instances are not launched due to small volume size that you are using. I was getting error in the ASG console:
Launching a new EC2 instance. Status Reason: Volume of size 5GB is smaller than snapshot 'snap-028531a83139c57d1', expect size >= 8GB. Launching EC2 instance failed.
Using 8GB was sufficient to make the instance launch in an ASG:
root_block_device = [
{
volume_size = "8"
volume_type = "gp2"
},
]
Upvotes: 2