Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to combine aws_subnet.prod_subnet.*.id with aws_subnet.prod2_subnet.*.id into a single list

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading