From 7c5ab40b748d34a7001cc883396abba014cf77c8 Mon Sep 17 00:00:00 2001 From: stack72 Date: Tue, 8 Mar 2016 23:51:30 +0000 Subject: [PATCH] provider/aws: Add support for the `repository_url` to be computed for ECR --- .../providers/aws/resource_aws_ecr_repository.go | 14 ++++++++++++++ .../providers/aws/r/ecr_repository.html.markdown | 1 + 2 files changed, 15 insertions(+) diff --git a/builtin/providers/aws/resource_aws_ecr_repository.go b/builtin/providers/aws/resource_aws_ecr_repository.go index ca94bcdb3..bf94dd4bc 100644 --- a/builtin/providers/aws/resource_aws_ecr_repository.go +++ b/builtin/providers/aws/resource_aws_ecr_repository.go @@ -3,6 +3,8 @@ package aws import ( "log" + "fmt" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ecr" @@ -29,6 +31,10 @@ func resourceAwsEcrRepository() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "repository_url": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, }, } } @@ -81,9 +87,17 @@ func resourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) erro d.Set("arn", *repository.RepositoryArn) d.Set("registry_id", *repository.RegistryId) + repositoryUrl := buildRepositoryUrl(repository, meta.(*AWSClient).region) + log.Printf("[INFO] Setting the repository url to be %s", repositoryUrl) + d.Set("repository_url", repositoryUrl) + return nil } +func buildRepositoryUrl(repo *ecr.Repository, region string) string { + return fmt.Sprintf("https://%s.dkr.ecr.%s.amazonaws.com/%s", *repo.RegistryId, region, *repo.RepositoryName) +} + func resourceAwsEcrRepositoryDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ecrconn diff --git a/website/source/docs/providers/aws/r/ecr_repository.html.markdown b/website/source/docs/providers/aws/r/ecr_repository.html.markdown index e90b796da..a4c1aa610 100644 --- a/website/source/docs/providers/aws/r/ecr_repository.html.markdown +++ b/website/source/docs/providers/aws/r/ecr_repository.html.markdown @@ -37,3 +37,4 @@ The following attributes are exported: * `arn` - Full ARN of the repository. * `name` - The name of the repository. * `registry_id` - The registry ID where the repository was created. +* `repository_url` - The URL of the repository (in the form `https://aws_account_id.dkr.ecr.region.amazonaws.com/repositoryName`