From e38d41b7a71a031fa213719242c0941a94730c4f Mon Sep 17 00:00:00 2001 From: James Nugent Date: Thu, 18 Aug 2016 18:54:39 +0100 Subject: [PATCH] provider/aws: Add `arn` fields to ALB resources 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". --- builtin/providers/aws/resource_aws_alb.go | 6 ++++++ builtin/providers/aws/resource_aws_alb_target_group.go | 6 ++++++ builtin/providers/aws/resource_aws_alb_target_group_test.go | 3 +++ builtin/providers/aws/resource_aws_alb_test.go | 3 +++ website/source/docs/providers/aws/r/alb.html.markdown | 3 ++- .../source/docs/providers/aws/r/alb_listener.html.markdown | 4 ++-- .../docs/providers/aws/r/alb_target_group.html.markdown | 3 ++- 7 files changed, 24 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_alb.go b/builtin/providers/aws/resource_aws_alb.go index 1823ce7a3..bf4fa7a8d 100644 --- a/builtin/providers/aws/resource_aws_alb.go +++ b/builtin/providers/aws/resource_aws_alb.go @@ -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, @@ -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)) diff --git a/builtin/providers/aws/resource_aws_alb_target_group.go b/builtin/providers/aws/resource_aws_alb_target_group.go index bad712f5b..ddf0597c3 100644 --- a/builtin/providers/aws/resource_aws_alb_target_group.go +++ b/builtin/providers/aws/resource_aws_alb_target_group.go @@ -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, @@ -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) diff --git a/builtin/providers/aws/resource_aws_alb_target_group_test.go b/builtin/providers/aws/resource_aws_alb_target_group_test.go index 5ab86dd38..446757f62 100644 --- a/builtin/providers/aws/resource_aws_alb_target_group_test.go +++ b/builtin/providers/aws/resource_aws_alb_target_group_test.go @@ -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"), @@ -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"), @@ -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"), diff --git a/builtin/providers/aws/resource_aws_alb_test.go b/builtin/providers/aws/resource_aws_alb_test.go index 929da8d77..3d6c26566 100644 --- a/builtin/providers/aws/resource_aws_alb_test.go +++ b/builtin/providers/aws/resource_aws_alb_test.go @@ -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"), ), }, }, @@ -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"), ), }, @@ -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"), ), }, }, diff --git a/website/source/docs/providers/aws/r/alb.html.markdown b/website/source/docs/providers/aws/r/alb.html.markdown index f02ae2db1..ec6779698 100644 --- a/website/source/docs/providers/aws/r/alb.html.markdown +++ b/website/source/docs/providers/aws/r/alb.html.markdown @@ -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) diff --git a/website/source/docs/providers/aws/r/alb_listener.html.markdown b/website/source/docs/providers/aws/r/alb_listener.html.markdown index 826c0c766..dd3b02b98 100644 --- a/website/source/docs/providers/aws/r/alb_listener.html.markdown +++ b/website/source/docs/providers/aws/r/alb_listener.html.markdown @@ -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" } } diff --git a/website/source/docs/providers/aws/r/alb_target_group.html.markdown b/website/source/docs/providers/aws/r/alb_target_group.html.markdown index e13a033b5..afc0be5bd 100644 --- a/website/source/docs/providers/aws/r/alb_target_group.html.markdown +++ b/website/source/docs/providers/aws/r/alb_target_group.html.markdown @@ -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