From 541e330b4637413aec00c59f8d1aafedbebd7815 Mon Sep 17 00:00:00 2001 From: stack72 Date: Wed, 2 Mar 2016 09:52:13 +0000 Subject: [PATCH] provider/aws: Adds `arn` as an output for `aws_elb` --- builtin/providers/aws/resource_aws_elb.go | 27 +++++++++++++++++++ .../docs/providers/aws/r/elb.html.markdown | 1 + 2 files changed, 28 insertions(+) diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index 4601d83b56db..616a2e44e8bc 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -11,6 +11,7 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/elb" + "github.com/aws/aws-sdk-go/service/iam" "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -32,6 +33,11 @@ func resourceAwsElb() *schema.Resource { ValidateFunc: validateElbName, }, + "arn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "internal": &schema.Schema{ Type: schema.TypeBool, Optional: true, @@ -364,6 +370,13 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error { } } + arn, arnErr := buildElbARN(d.Id(), meta) + if arnErr != nil { + return arnErr + } else { + d.Set("arn", arn) + } + resp, err := elbconn.DescribeTags(&elb.DescribeTagsInput{ LoadBalancerNames: []*string{lb.LoadBalancerName}, }) @@ -802,3 +815,17 @@ func sourceSGIdByName(meta interface{}, sg, vpcId string) (string, error) { group := resp.SecurityGroups[0] return *group.GroupId, nil } + +func buildElbARN(identifier string, meta interface{}) (string, error) { + iamconn := meta.(*AWSClient).iamconn + region := meta.(*AWSClient).region + // An zero value GetUserInput{} defers to the currently logged in user + resp, err := iamconn.GetUser(&iam.GetUserInput{}) + if err != nil { + return "", err + } + userARN := *resp.User.Arn + accountID := strings.Split(userARN, ":")[4] + arn := fmt.Sprintf("arn:aws:elasticloadbalancing:%s:%s:loadbalancer:%s", region, accountID, identifier) + return arn, nil +} diff --git a/website/source/docs/providers/aws/r/elb.html.markdown b/website/source/docs/providers/aws/r/elb.html.markdown index 997d7274d1ef..fcc9b02446a8 100644 --- a/website/source/docs/providers/aws/r/elb.html.markdown +++ b/website/source/docs/providers/aws/r/elb.html.markdown @@ -113,6 +113,7 @@ The following attributes are exported: * `id` - The name of the ELB * `name` - The name of the ELB +* `arn` - The ARN of the ELB. * `dns_name` - The DNS name of the ELB * `instances` - The list of instances in the ELB * `source_security_group` - The name of the security group that you can use as