0

Struggling with the logic here, was wondering if someone could lend a hand.

I am creating instances in Terraform as follows:

    resource "aws_instance" "es-data" {
  count                   = var.nodes_per_az * length(data.aws_availability_zones.available.names)
  ami                     = var.instance_ami
  instance_type           = var.instance_size
  availability_zone       = data.aws_availability_zones.available.names[count.index]
}

Essentially, I currently have 4 nodes per availability zone, so my count equals 12. I have 3x Availability Zones. How can I calculate it so for count 1,2,3,4 it goes in to AZa, 5,6,7,8 goes to AZb and 9,10,11,12 in to AZc.

mehstg
  • 389
  • 1
  • 5
  • 15
  • 1
    Don't use `availability_zone`. Use `subnet_id` instead and refer to the relevant subnet ID. `availability_zone` is aimed at EC2 Classic accounts (before VPCs). If you do that then you'll find that https://stackoverflow.com/questions/46041396/multiple-availability-zones-with-terraform-on-aws is a duplicate. – ydaetskcoR Feb 14 '20 at 16:31
  • 1
    In particular https://stackoverflow.com/a/52762549/2291321 addresses having more instances than subnets. – ydaetskcoR Feb 14 '20 at 16:31
  • Also https://stackoverflow.com/a/51337252/2291321 – ydaetskcoR Feb 14 '20 at 16:32
  • Magic. element() was exactly what I was after. I did not realise it would wrap. – mehstg Feb 14 '20 at 23:41
  • Which answer was the most useful for you? It might be helpful to close this as a duplicate of that one so that others who land here can easily see their answer. – ydaetskcoR Feb 15 '20 at 12:17

0 Answers0