While creating auto_scaling_group with terraform, error showing:
omkar@kws MINGW64 ~/repo/kiwi-infra (main)
$ terraform validate
╷
│ Error: Unsupported attribute
│
│ on main.tf line 46, in module "asg":
│ 46: tg = "${module.alb.tg}"
│ ├────────────────
│ │ module.alb is a list of object
│
│ Can't access attributes on a list of objects. Did you mean to access attribute "tg" for a specific element of the list, or across all elements of the list?
and my code goes as below:
alb module:
resource "aws_lb_target_group" "kiwi-dev-tg" {
health_check {
interval = 10
path = "/"
protocol = "HTTP"
timeout = 5
healthy_threshold = 3
unhealthy_threshold = 2
}
name = "${var.project}-dev-tg"
port = 80
protocol = "HTTP"
target_type = "instance"
vpc_id = "${var.vpc-id}"
}
asg module:
resource "aws_autoscaling_group" "asg" {
launch_configuration = "${aws_launch_configuration.launch-conf.name}"
vpc_zone_identifier = ["${var.sn1}","${var.sn2 }"]
target_group_arns = "${var.tg}"
health_check_type = "ELB"
asg variables:
variable "tg" {}
alb output file:
output "tg" {
value = aws_lb_target_group.kiwi-dev-tg.arn
}
main.tf
module "asg" {
source = "./modules/asg"
project = "${var.project}"
app-sg = "${module.vpc.app-sg}"
sn1 = "${module.vpc.sn1}"
sn2 = "${module.vpc.sn2}"
tg = "${module.alb.tg}"
}
ALB
module "alb" {
source = "./modules/alb"
project = "${var.project}"
vpc-id = "${module.vpc.vpc-id}"
count = "${length(module.ec2.app)}"
app = "${element(module.ec2.app, count.index)}"
#app01 = "${module.ec2.app01}"
#app02 = "${module.ec2.app02}"
alb-sg = "${module.vpc.alb-sg}"
sn1 = "${module.vpc.sn1}"
sn2 = "${module.vpc.sn2}"
}