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