terraform aws random subnets

510 views
Skip to first unread message

SreeN

unread,
May 26, 2020, 11:11:05 AM5/26/20
to Terraform
Hi All,

I have to create 3 subnets and 9 instances, 3 instance/ subnets. I tried many methods and none is working. iIt will work if  i keep number of instance same as subnets count . Tried all these methods. Can someone please help?.




  #subnet_id		= "${var.subnets[count.index]}"
  #subnet_id     = "${tolist(data.aws_subnet_ids.example.ids)[count.index]}"
#subnet_id     = "${data.aws_subnet_ids.selected.ids[count.index]}"
#subnet_id = "${element(data.aws_subnet_ids.selected.ids, count.index)}"

Thanks
Sre

Rob Coward

unread,
May 26, 2020, 12:13:37 PM5/26/20
to terrafo...@googlegroups.com

Have you tried:

 

Subnet_id = “${element(subnet_ids, count.index)}”

 

You haven’t shared your data.aws_subnet_ids.selected resource definition, but since you are specifying your own list of subnets, the above will rotate through your list of subnets for however many counts you define.

 

Rob

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/369f977a-7447-485a-8f41-d61dbf592648%40googlegroups.com.

SreeN

unread,
May 27, 2020, 12:13:33 AM5/27/20
to Terraform
Hi Rob,

Thanks for the update

I tried this as well, but the problem is that I cannot define the subnet_ids as shown in the first post , since variable do not support another list of variables. what ever I try I  am getting either invalid index or some other error. Could you please share full sample syntax ?

Thanks
Sre

To unsubscribe from this group and stop receiving emails from it, send an email to terrafo...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages