Skip to content

Commit

Permalink
Merge pull request #1806 from stack72/f-aws-nlb
Browse files Browse the repository at this point in the history
provider/aws: Add support for Network Loadbalancers
  • Loading branch information
radeksimko authored Oct 4, 2017
2 parents f4b158c + 1af53b1 commit 337d94c
Show file tree
Hide file tree
Showing 35 changed files with 2,980 additions and 1,819 deletions.
172 changes: 0 additions & 172 deletions aws/data_source_aws_alb_target_group_test.go

This file was deleted.

124 changes: 0 additions & 124 deletions aws/data_source_aws_alb_test.go

This file was deleted.

48 changes: 35 additions & 13 deletions aws/data_source_aws_alb.go → aws/data_source_aws_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/hashicorp/terraform/helper/schema"
)

func dataSourceAwsAlb() *schema.Resource {
func dataSourceAwsLb() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsAlbRead,
Read: dataSourceAwsLbRead,
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand All @@ -35,6 +35,11 @@ func dataSourceAwsAlb() *schema.Resource {
Computed: true,
},

"load_balancer_type": {
Type: schema.TypeString,
Computed: true,
},

"security_groups": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Expand All @@ -49,6 +54,23 @@ func dataSourceAwsAlb() *schema.Resource {
Set: schema.HashString,
},

"subnet_mapping": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"subnet_id": {
Type: schema.TypeString,
Required: true,
},
"allocation_id": {
Type: schema.TypeString,
Optional: true,
},
},
},
},

"access_logs": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -101,27 +123,27 @@ func dataSourceAwsAlb() *schema.Resource {
}
}

func dataSourceAwsAlbRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceAwsLbRead(d *schema.ResourceData, meta interface{}) error {
elbconn := meta.(*AWSClient).elbv2conn
albArn := d.Get("arn").(string)
albName := d.Get("name").(string)
lbArn := d.Get("arn").(string)
lbName := d.Get("name").(string)

describeAlbOpts := &elbv2.DescribeLoadBalancersInput{}
describeLbOpts := &elbv2.DescribeLoadBalancersInput{}
switch {
case albArn != "":
describeAlbOpts.LoadBalancerArns = []*string{aws.String(albArn)}
case albName != "":
describeAlbOpts.Names = []*string{aws.String(albName)}
case lbArn != "":
describeLbOpts.LoadBalancerArns = []*string{aws.String(lbArn)}
case lbName != "":
describeLbOpts.Names = []*string{aws.String(lbName)}
}

describeResp, err := elbconn.DescribeLoadBalancers(describeAlbOpts)
describeResp, err := elbconn.DescribeLoadBalancers(describeLbOpts)
if err != nil {
return errwrap.Wrapf("Error retrieving ALB: {{err}}", err)
return errwrap.Wrapf("Error retrieving LB: {{err}}", err)
}
if len(describeResp.LoadBalancers) != 1 {
return fmt.Errorf("Search returned %d results, please revise so only one is returned", len(describeResp.LoadBalancers))
}
d.SetId(*describeResp.LoadBalancers[0].LoadBalancerArn)

return flattenAwsAlbResource(d, meta, describeResp.LoadBalancers[0])
return flattenAwsLbResource(d, meta, describeResp.LoadBalancers[0])
}
Loading

0 comments on commit 337d94c

Please sign in to comment.