I am trying to combine all subnets to be able to attach an ACL to them.
I have two subnets that exist which different resource names, so it’s forcing me to have two ACL blocks which I don’t want.
Right now the ACL subnet_id blocks for both ACL blocks read as:
resource "aws_network_acl" "prod_public" {
vpc_id = aws_vpc.prod.id
subnet_ids = aws_subnet.prod_public.*.id
}
resource "aws_network_acl" "prod2_public" {
vpc_id = aws_vpc.prod.id
subnet_ids = aws_subnet.prod2_public.*.id
}
this works, but I’m want something that will create a list of BOTH set of subnet_ids so I can just have be one block.
I’ve tried something like this, but didn’t work.
resource "aws_network_acl" "prods_public" {
vpc_id = aws_vpc_prod_id
subnet_ids = [aws_subnet.prod_public.*.id, aws_subnet.prod2_public.*.id]
}
I also tried using tostring and toset which didn’t work either.
>Solution :
You should use concat:
subnet_ids = concat(aws_subnet.prod_public.*.id, aws_subnet.prod2_public.*.id)