Skip to content

Commit 1af53b1

Browse files
committed
provider/aws: Add support for Network Loadbalancers
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
1 parent f4b158c commit 1af53b1

35 files changed

+2980
-1819
lines changed

aws/data_source_aws_alb_target_group_test.go

Lines changed: 0 additions & 172 deletions
This file was deleted.

aws/data_source_aws_alb_test.go

Lines changed: 0 additions & 124 deletions
This file was deleted.

aws/data_source_aws_alb.go renamed to aws/data_source_aws_lb.go

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"github.com/hashicorp/terraform/helper/schema"
1010
)
1111

12-
func dataSourceAwsAlb() *schema.Resource {
12+
func dataSourceAwsLb() *schema.Resource {
1313
return &schema.Resource{
14-
Read: dataSourceAwsAlbRead,
14+
Read: dataSourceAwsLbRead,
1515
Schema: map[string]*schema.Schema{
1616
"arn": {
1717
Type: schema.TypeString,
@@ -35,6 +35,11 @@ func dataSourceAwsAlb() *schema.Resource {
3535
Computed: true,
3636
},
3737

38+
"load_balancer_type": {
39+
Type: schema.TypeString,
40+
Computed: true,
41+
},
42+
3843
"security_groups": {
3944
Type: schema.TypeSet,
4045
Elem: &schema.Schema{Type: schema.TypeString},
@@ -49,6 +54,23 @@ func dataSourceAwsAlb() *schema.Resource {
4954
Set: schema.HashString,
5055
},
5156

57+
"subnet_mapping": {
58+
Type: schema.TypeSet,
59+
Computed: true,
60+
Elem: &schema.Resource{
61+
Schema: map[string]*schema.Schema{
62+
"subnet_id": {
63+
Type: schema.TypeString,
64+
Required: true,
65+
},
66+
"allocation_id": {
67+
Type: schema.TypeString,
68+
Optional: true,
69+
},
70+
},
71+
},
72+
},
73+
5274
"access_logs": {
5375
Type: schema.TypeList,
5476
Computed: true,
@@ -101,27 +123,27 @@ func dataSourceAwsAlb() *schema.Resource {
101123
}
102124
}
103125

104-
func dataSourceAwsAlbRead(d *schema.ResourceData, meta interface{}) error {
126+
func dataSourceAwsLbRead(d *schema.ResourceData, meta interface{}) error {
105127
elbconn := meta.(*AWSClient).elbv2conn
106-
albArn := d.Get("arn").(string)
107-
albName := d.Get("name").(string)
128+
lbArn := d.Get("arn").(string)
129+
lbName := d.Get("name").(string)
108130

109-
describeAlbOpts := &elbv2.DescribeLoadBalancersInput{}
131+
describeLbOpts := &elbv2.DescribeLoadBalancersInput{}
110132
switch {
111-
case albArn != "":
112-
describeAlbOpts.LoadBalancerArns = []*string{aws.String(albArn)}
113-
case albName != "":
114-
describeAlbOpts.Names = []*string{aws.String(albName)}
133+
case lbArn != "":
134+
describeLbOpts.LoadBalancerArns = []*string{aws.String(lbArn)}
135+
case lbName != "":
136+
describeLbOpts.Names = []*string{aws.String(lbName)}
115137
}
116138

117-
describeResp, err := elbconn.DescribeLoadBalancers(describeAlbOpts)
139+
describeResp, err := elbconn.DescribeLoadBalancers(describeLbOpts)
118140
if err != nil {
119-
return errwrap.Wrapf("Error retrieving ALB: {{err}}", err)
141+
return errwrap.Wrapf("Error retrieving LB: {{err}}", err)
120142
}
121143
if len(describeResp.LoadBalancers) != 1 {
122144
return fmt.Errorf("Search returned %d results, please revise so only one is returned", len(describeResp.LoadBalancers))
123145
}
124146
d.SetId(*describeResp.LoadBalancers[0].LoadBalancerArn)
125147

126-
return flattenAwsAlbResource(d, meta, describeResp.LoadBalancers[0])
148+
return flattenAwsLbResource(d, meta, describeResp.LoadBalancers[0])
127149
}

0 commit comments

Comments
 (0)