diff --git a/aws/resource_aws_lb.go b/aws/resource_aws_lb.go index 1bce33b2966..bb8ebbcf066 100644 --- a/aws/resource_aws_lb.go +++ b/aws/resource_aws_lb.go @@ -76,6 +76,13 @@ func resourceAwsLb() *schema.Resource { Default: "application", }, + "private_ips": { + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + Computed: true, + Set: schema.HashString, + }, + "security_groups": { Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, @@ -657,6 +664,7 @@ func lbSuffixFromARN(arn *string) string { // flattenAwsLbResource takes a *elbv2.LoadBalancer and populates all respective resource fields. func flattenAwsLbResource(d *schema.ResourceData, meta interface{}, lb *elbv2.LoadBalancer) error { + ec2conn := meta.(*AWSClient).ec2conn elbconn := meta.(*AWSClient).elbv2conn d.Set("arn", lb.LoadBalancerArn) @@ -678,6 +686,22 @@ func flattenAwsLbResource(d *schema.ResourceData, meta interface{}, lb *elbv2.Lo return fmt.Errorf("error setting subnet_mapping: %s", err) } + privateIps := make([]string, 0) + networkInterfacesResp, err := ec2conn.DescribeNetworkInterfaces(&ec2.DescribeNetworkInterfacesInput{ + Filters: buildEC2AttributeFilterList( + map[string]string{ + "description": fmt.Sprintf("ELB %s", lbSuffixFromARN(lb.LoadBalancerArn)), + }, + ), + }) + if err != nil { + return err + } + for _, eni := range networkInterfacesResp.NetworkInterfaces { + privateIps = append(privateIps, *eni.PrivateIpAddress) + } + d.Set("private_ips", privateIps) + respTags, err := elbconn.DescribeTags(&elbv2.DescribeTagsInput{ ResourceArns: []*string{lb.LoadBalancerArn}, }) diff --git a/aws/resource_aws_lb_test.go b/aws/resource_aws_lb_test.go index cce107395a8..4a8f599be3f 100644 --- a/aws/resource_aws_lb_test.go +++ b/aws/resource_aws_lb_test.go @@ -120,6 +120,7 @@ func TestAccAWSLB_basic(t *testing.T) { resource.TestCheckResourceAttrSet("aws_lb.lb_test", "zone_id"), resource.TestCheckResourceAttrSet("aws_lb.lb_test", "dns_name"), resource.TestCheckResourceAttrSet("aws_lb.lb_test", "arn"), + resource.TestCheckResourceAttr("aws_lb.lb_test", "private_ips.#", "1"), ), }, }, @@ -150,6 +151,7 @@ func TestAccAWSLB_networkLoadbalancerBasic(t *testing.T) { resource.TestCheckResourceAttrSet("aws_lb.lb_test", "dns_name"), resource.TestCheckResourceAttrSet("aws_lb.lb_test", "arn"), resource.TestCheckResourceAttr("aws_lb.lb_test", "load_balancer_type", "network"), + resource.TestCheckResourceAttr("aws_lb.lb_test", "private_ips.#", "1"), ), }, }, @@ -178,6 +180,7 @@ func TestAccAWSLB_networkLoadbalancerEIP(t *testing.T) { resource.TestCheckResourceAttr("aws_lb.lb_test", "load_balancer_type", "network"), resource.TestCheckResourceAttr("aws_lb.lb_test", "enable_deletion_protection", "false"), resource.TestCheckResourceAttr("aws_lb.lb_test", "subnet_mapping.#", "2"), + resource.TestCheckResourceAttr("aws_lb.test", "private_ips.#", "2"), ), }, }, diff --git a/website/docs/r/lb.html.markdown b/website/docs/r/lb.html.markdown index fb5760c8f28..3668ca50894 100644 --- a/website/docs/r/lb.html.markdown +++ b/website/docs/r/lb.html.markdown @@ -121,6 +121,7 @@ The following attributes are exported in addition to the arguments listed above: * `arn_suffix` - The ARN suffix for use with CloudWatch Metrics. * `dns_name` - The DNS name of the load balancer. * `zone_id` - The canonical hosted zone ID of the load balancer (to be used in a Route 53 Alias record). +* `private_ips` - Private IP addresses of the network interfaces attached to the load balancer. ## Timeouts