Aws_lb, aws_eip and private_ip

Hi all,

I’m trying to create an aws_lb (type network), but I can’t seem to get private_ip from attached EIP after the first run.

Very simplified, my code looks like this:

resource "aws_eip" "lb" {
  vpc = true
}

resource "aws_lb" "cluster" {
  name               = "MyLB"
  internal           = false
  load_balancer_type = "network"

  subnet_mapping {
    subnet_id     = var.aws_cluster_subnet_id
    allocation_id = aws_eip.lb.id
  }
}

# Add target groups, target attachments and listeners

outputs.tf:

output "load_balancer" {
  description = "Load balancer data"
  value       = {
    "private_ip" = aws_eip.lb.private_ip
    "public_ip"  = aws_eip.lb.public_ip
  }

  depends_on = [ aws_lb.cluster ]
}

After the first run, load_balancer.public_ip has a value, but load_balancer.private_ip is empty. I added depends_on to the output thinking that EIP gets a private IP assigned once it’s mapped to a subnet, but that did not help.

Applying the configuration the second time updates load_balancer.private_ip output.

Is this a bug, is there another dependency I should be targetting?

Thank you!

@apparentlymart,

Thanks for moving it to the appropriate forum :slight_smile: Does that mean this looks like a bug?

Should I report this on GitHub issues?