Hello,
I have a variable i am passing into my autoscalegroup resource that contains a list of subnet ids:
variable "subnet_ids" {
type = list(string)
}
the variable subnet_ids would contain a list such as [subnet_001, subnet_002, subnet_003, subnet_004]
Each subnet are in a specific AWS availability zone:
subnet_001 - us-east-1a
subnet_002 - us-east-1b
subnet_003 - us-east-1c
subnet_004 - us-east-1d
I am using the subnet_ids variable in my aws_autoscaling_group resource as:
resource "aws_autoscaling_group" "my_asg" {
count = length(var.subnet_ids)
name = "${var.environment}-${var.role}-${element(var.subnet_ids, count.index)}"
max_size = var.max_size
min_size = var.min_size
desired_capacity = var.desired_capacity
health_check_grace_period = var.hc_grace_period
health_check_type = var.hc_check_type
force_delete = var.force_delete
vpc_zone_identifier = [element(var.subnet_ids, count.index)]
termination_policies = var.asg_term_policy
enabled_metrics = var.enabled_metrics
launch_template {
id = aws_launch_template.my_lt.id
version = "$Latest"
}
However I will occassionally run into an issue where the instance type is not supported in the AZ:
Error: Error creating AutoScaling Group: ValidationError: You must use a valid fully-formed launch template. Your requested instance type (c5.2xlarge) is not supported in your requested Availability Zone (us-east-1e). Please retry your request by not specifying an Availability Zone or choosing us-east-1a, us-east-1b, us-east-1c, us-east-1d, us-east-1f.
Is there a way to refactor my module so that I can exclude the unsupported subnets/AZs?
Thank you