Skip to content

Commit

Permalink
provider/aws: Add support for Network Loadbalancers
Browse files Browse the repository at this point in the history
Fixes: #1618

In terraform, we had the idea of an alb. In AWS this doesn't exist. ALBs
are actually Load balancers of type `application`

Therefore, the first part of this PR adds a new parameter to ALBs called
`load_balancer_type`. We default this to `application` to follow the
same idea as the current behaviour

The next part of the PR will then change the idea of an alb -> lb

In order to preserve backwards compatibility, we have added another
resource name to the same schema type. This means we effectively have an
alias of aws_alb and aws_lb. This includes updating *all* of the tests
to make sure and remove the idea of ALB and rename to LB and then we
will add a check to make sure we can still check that an ALB can be
created in the old resource
  • Loading branch information
stack72 committed Oct 4, 2017
1 parent f4b158c commit 1af53b1
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 1af53b1

Please sign in to comment.