title: Terraform how to get IP address of aws_lb
body: <h1>Question</h1>
  
  <p>If there a way to get the assigned IP address of an aws_lb resource at the time aws_lb is created by Terraform?</p>
  
  <p>As in <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/network/target-group-register-targets.html#target-security-groups" rel="noreferrer">AWS documentation - NLB - To find the private IP addresses to whitelist</a>, we can find out the IP address associated to ELB.</p>
  
  <ol>
  <li>Open the Amazon EC2 console at <a href="https://console.aws.amazon.com/ec2/" rel="noreferrer">https://console.aws.amazon.com/ec2/</a>.</li>
  <li>In the navigation pane, choose Network Interfaces.</li>
  <li>In the search field, type the name of your Network Load Balancer.
  There is one network interface per load balancer subnet.</li>
  <li>On the Details tab for each network interface, <strong>copy the address from
  Primary private IPv4 IP</strong>.</li>
  </ol>
  
  <h1>Background</h1>
  
  <p>To be able to setup security group to white list the ELB IP address as Network Load Balancer cannot not have Security Group as in <a href="https://forums.aws.amazon.com/thread.jspa?threadID=263245" rel="noreferrer">Network Load Balancers don't have Security Groups</a>.</p>
  
  <p>Considered <a href="https://www.terraform.io/docs/providers/aws/d/network_interface.html" rel="noreferrer">aws_network_interface</a> but it does not work with an error.</p>
  
  <blockquote>
    <p>Error: no matching network interface found</p>
  </blockquote>
  
  <p>Also I think datasource assumes the resource already exists and cannot be used for the resource to be created by Terraform.</p>