Skip to content

Commit

Permalink
provider/aws: Add arn fields to ALB resources
Browse files Browse the repository at this point in the history
This commit adds an `arn` field to `aws_alb` and `aws_alb_target_group`
resources, in order to present a more coherant user experience to people
using resource variables in fields suffixed "arn".
  • Loading branch information
jen20 committed Aug 18, 2016
1 parent 59f66ec commit e38d41b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions builtin/providers/aws/resource_aws_alb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func resourceAwsAlb() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},

"name": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -164,6 +169,7 @@ func resourceAwsAlbRead(d *schema.ResourceData, meta interface{}) error {

alb := describeResp.LoadBalancers[0]

d.Set("arn", alb.LoadBalancerArn)
d.Set("name", alb.LoadBalancerName)
d.Set("internal", (alb.Scheme != nil && *alb.Scheme == "internal"))
d.Set("security_groups", flattenStringList(alb.SecurityGroups))
Expand Down
6 changes: 6 additions & 0 deletions builtin/providers/aws/resource_aws_alb_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func resourceAwsAlbTargetGroup() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},

"name": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -206,6 +211,7 @@ func resourceAwsAlbTargetGroupRead(d *schema.ResourceData, meta interface{}) err

targetGroup := resp.TargetGroups[0]

d.Set("arn", targetGroup.TargetGroupArn)
d.Set("name", targetGroup.TargetGroupName)
d.Set("port", targetGroup.Port)
d.Set("protocol", targetGroup.Protocol)
Expand Down
3 changes: 3 additions & 0 deletions builtin/providers/aws/resource_aws_alb_target_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestAccAWSALBTargetGroup_basic(t *testing.T) {
Config: testAccAWSALBTargetGroupConfig_basic(targetGroupName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
resource.TestCheckResourceAttrSet("aws_alb_target_group.test", "arn"),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "name", targetGroupName),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "port", "443"),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"),
Expand Down Expand Up @@ -64,6 +65,7 @@ func TestAccAWSALBTargetGroup_updateHealthCheck(t *testing.T) {
Config: testAccAWSALBTargetGroupConfig_basic(targetGroupName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
resource.TestCheckResourceAttrSet("aws_alb_target_group.test", "arn"),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "name", targetGroupName),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "port", "443"),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"),
Expand All @@ -87,6 +89,7 @@ func TestAccAWSALBTargetGroup_updateHealthCheck(t *testing.T) {
Config: testAccAWSALBTargetGroupConfig_updateHealthCheck(targetGroupName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
resource.TestCheckResourceAttrSet("aws_alb_target_group.test", "arn"),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "name", targetGroupName),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "port", "443"),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"),
Expand Down
3 changes: 3 additions & 0 deletions builtin/providers/aws/resource_aws_alb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestAccAWSALB_basic(t *testing.T) {
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "vpc_id"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "zone_id"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "dns_name"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "arn"),
),
},
},
Expand Down Expand Up @@ -70,6 +71,7 @@ func TestAccAWSALB_accesslogs(t *testing.T) {
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "vpc_id"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "zone_id"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "dns_name"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "arn"),
),
},

Expand All @@ -91,6 +93,7 @@ func TestAccAWSALB_accesslogs(t *testing.T) {
resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.#", "1"),
resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.0.bucket", bucketName),
resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.0.prefix", "testAccAWSALBConfig_accessLogs"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "arn"),
),
},
},
Expand Down
3 changes: 2 additions & 1 deletion website/source/docs/providers/aws/r/alb.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Access Logs (`access_logs`) support the following:

The following attributes are exported in addition to the arguments listed above:

* `id` - The ARN of the load balancer
* `id` - The ARN of the load balancer (matches `arn`)
* `arn` - The ARN of the load balancer (matches `id`)
* `dns_name` - The DNS name of the load balancer
* `canonical_hosted_zone_id` - The canonical hosted zone ID of the load balancer.
* `zone_id` - The canonical hosted zone ID of the load balancer (to be used in a Route 53 Alias record)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ resource "aws_alb_target_group" "front_end" {
}
resource "aws_alb_listener" "front_end" {
load_balancer_arn = "${aws_alb.front_end.id}"
load_balancer_arn = "${aws_alb.front_end.arn}"
port = "443"
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-2015-05"
certificate_arn = "arn:aws:iam::187416307283:server-certificate/test_cert_rab3wuqwgja25ct3n4jdj2tzu4"
default_action {
target_group_arn = "${aws_alb_target_group.front_end.id}"
target_group_arn = "${aws_alb_target_group.front_end.arn}"
type = "forward"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ Health Check Blocks (`health_check`) support the following:

The following attributes are exported in addition to the arguments listed above:

* `id` - The ARN of the target group.
* `id` - The ARN of the Target Group (matches `arn`)
* `arn` - The ARN of the Target Group (matches `id`)

## Import

Expand Down

0 comments on commit e38d41b

Please sign in to comment.