From 2653bb5d1f9795bc19c3b97516563c5386fc2d87 Mon Sep 17 00:00:00 2001 From: 115100 <115100@users.noreply.github.com> Date: Wed, 18 Dec 2019 14:08:47 +0000 Subject: [PATCH] data-source/aws_elb: Export arn attribute The documentation says that data source for aws_elb shall return the same attributes as the resource type. This commit exports arn on the data source to match the documented behaviour. --- aws/data_source_aws_elb.go | 15 +++++++++++++++ aws/data_source_aws_elb_test.go | 1 + 2 files changed, 16 insertions(+) diff --git a/aws/data_source_aws_elb.go b/aws/data_source_aws_elb.go index 1d159bbfbc7..b81d48f902b 100644 --- a/aws/data_source_aws_elb.go +++ b/aws/data_source_aws_elb.go @@ -5,6 +5,7 @@ import ( "log" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/elb" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) @@ -18,6 +19,11 @@ func dataSourceAwsElb() *schema.Resource { Required: true, }, + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "access_logs": { Type: schema.TypeList, Computed: true, @@ -208,5 +214,14 @@ func dataSourceAwsElbRead(d *schema.ResourceData, meta interface{}) error { } d.SetId(*resp.LoadBalancerDescriptions[0].LoadBalancerName) + arn := arn.ARN{ + Partition: meta.(*AWSClient).partition, + Region: meta.(*AWSClient).region, + Service: "elasticloadbalancing", + AccountID: meta.(*AWSClient).accountid, + Resource: fmt.Sprintf("loadbalancer/%s", *resp.LoadBalancerDescriptions[0].LoadBalancerName), + } + d.Set("arn", arn.String()) + return flattenAwsELbResource(d, meta.(*AWSClient).ec2conn, elbconn, resp.LoadBalancerDescriptions[0]) } diff --git a/aws/data_source_aws_elb_test.go b/aws/data_source_aws_elb_test.go index 3dda875c551..5adcf47bec7 100644 --- a/aws/data_source_aws_elb_test.go +++ b/aws/data_source_aws_elb_test.go @@ -29,6 +29,7 @@ func TestAccDataSourceAWSELB_basic(t *testing.T) { resource.TestCheckResourceAttr("data.aws_elb.elb_test", "tags.TestName", t.Name()), resource.TestCheckResourceAttrSet("data.aws_elb.elb_test", "dns_name"), resource.TestCheckResourceAttrSet("data.aws_elb.elb_test", "zone_id"), + resource.TestCheckResourceAttrPair("data.aws_elb.elb_test", "arn", "aws_elb.elb_test", "arn"), ), }, },