aws_lb and dynamic subnet_mapping allocation

225 views
Skip to first unread message

Danny Rehelis

unread,
Apr 23, 2018, 8:43:24 AM4/23/18
to terrafo...@googlegroups.com
Hi,

My terraform plan creates the whole underlying infrastructure which include:
vpc, subnets in different AZ etc.

During the plan, I'm heavy user of 'count' and 'elemet(var.x, count.index)' interpolation, this way I place instances in different subnets without specifying them explicitly for example.

How to achive this same with aws_lb?
In some regions I want to deploy lb in 4 previously created subnets, in other region only 3 subnets etc.
Not sure subnet_mapping allows me this flexibility.

resource "aws_lb" "example" {
  name               = "example"
  load_balancer_type = "network"

  subnet_mapping {
    subnet_id    = "${aws_subnet.example1.id}"
    allocation_id = "${aws_eip.example1.id}"
  }

  subnet_mapping {
    subnet_id    = "${aws_subnet.example2.id}"
    allocation_id = "${aws_eip.example2.id}"
  }
}

Can you suggest?

Felix Wong

unread,
Sep 12, 2018, 2:13:37 AM9/12/18
to Terraform
very much having the same issue here.

also, if i use specific eips manually passed in, the issue is worse since i have to use a data source individuall to obtain the allocation id. has anyone figured out a better to do that?
Reply all
Reply to author
Forward
0 new messages