From 7960eea3651f46caf17733fafeab5627f7c64c91 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Wed, 15 Nov 2017 09:23:58 -0500 Subject: [PATCH] Add arn attribute to aws_elb resource (#2272) * Add arn attribute to aws_elb resource * #2272 review: r/aws_elb: Remove Optional from arn attribute --- aws/resource_aws_elb.go | 15 +++++++++++++++ aws/resource_aws_elb_test.go | 1 + website/docs/r/elb.html.markdown | 1 + 3 files changed, 17 insertions(+) diff --git a/aws/resource_aws_elb.go b/aws/resource_aws_elb.go index 15a5d2eaebd..09f039fb350 100644 --- a/aws/resource_aws_elb.go +++ b/aws/resource_aws_elb.go @@ -10,6 +10,7 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/elb" @@ -44,6 +45,11 @@ func resourceAwsElb() *schema.Resource { ValidateFunc: validateElbNamePrefix, }, + "arn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "internal": &schema.Schema{ Type: schema.TypeBool, Optional: true, @@ -330,6 +336,15 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error { elbconn := meta.(*AWSClient).elbconn elbName := d.Id() + arn := arn.ARN{ + Partition: meta.(*AWSClient).partition, + Region: meta.(*AWSClient).region, + Service: "elasticloadbalancing", + AccountID: meta.(*AWSClient).accountid, + Resource: fmt.Sprintf("loadbalancer/%s", d.Id()), + } + d.Set("arn", arn.String()) + // Retrieve the ELB properties for updating the state describeElbOpts := &elb.DescribeLoadBalancersInput{ LoadBalancerNames: []*string{aws.String(elbName)}, diff --git a/aws/resource_aws_elb_test.go b/aws/resource_aws_elb_test.go index 85e76994247..4afd2228f70 100644 --- a/aws/resource_aws_elb_test.go +++ b/aws/resource_aws_elb_test.go @@ -31,6 +31,7 @@ func TestAccAWSELB_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSELBExists("aws_elb.bar", &conf), testAccCheckAWSELBAttributes(&conf), + resource.TestCheckResourceAttrSet("aws_elb.bar", "arn"), resource.TestCheckResourceAttr( "aws_elb.bar", "availability_zones.#", "3"), resource.TestCheckResourceAttr( diff --git a/website/docs/r/elb.html.markdown b/website/docs/r/elb.html.markdown index 472a0631ac3..7741fa32a7e 100644 --- a/website/docs/r/elb.html.markdown +++ b/website/docs/r/elb.html.markdown @@ -135,6 +135,7 @@ browser. The following attributes are exported: * `id` - The name of the ELB +* `arn` - The ARN of the ELB * `name` - The name of the ELB * `dns_name` - The DNS name of the ELB * `instances` - The list of instances in the ELB