Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service/ecr: Refactor to use keyvaluetags library #10325

Merged
merged 1 commit into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions aws/data_source_aws_ecr_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func dataSourceAwsEcrRepository() *schema.Resource {
Expand Down Expand Up @@ -54,17 +55,22 @@ func dataSourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) er
}

repository := out.Repositories[0]

log.Printf("[DEBUG] Received ECR repository %s", out)
arn := aws.StringValue(repository.RepositoryArn)

d.SetId(aws.StringValue(repository.RepositoryName))
d.Set("arn", repository.RepositoryArn)
d.Set("arn", arn)
d.Set("registry_id", repository.RegistryId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do any of these need aws.StringValues as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d.Set("name", repository.RepositoryName)
d.Set("repository_url", repository.RepositoryUri)

if err := getTagsECR(conn, d); err != nil {
return fmt.Errorf("error getting ECR repository tags: %s", err)
tags, err := keyvaluetags.EcrListTags(conn, arn)

if err != nil {
return fmt.Errorf("error listing tags for ECR Repository (%s): %s", arn, err)
}

if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

return nil
Expand Down
25 changes: 19 additions & 6 deletions aws/resource_aws_ecr_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func resourceAwsEcrRepository() *schema.Resource {
Expand Down Expand Up @@ -65,7 +66,7 @@ func resourceAwsEcrRepositoryCreate(d *schema.ResourceData, meta interface{}) er
input := ecr.CreateRepositoryInput{
ImageTagMutability: aws.String(d.Get("image_tag_mutability").(string)),
RepositoryName: aws.String(d.Get("name").(string)),
Tags: tagsFromMapECR(d.Get("tags").(map[string]interface{})),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().EcrTags(),
}

log.Printf("[DEBUG] Creating ECR repository: %#v", input)
Expand Down Expand Up @@ -119,21 +120,29 @@ func resourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) erro
}

repository := out.Repositories[0]
arn := aws.StringValue(repository.RepositoryArn)

d.Set("arn", repository.RepositoryArn)
d.Set("arn", arn)
d.Set("name", repository.RepositoryName)
d.Set("registry_id", repository.RegistryId)
d.Set("repository_url", repository.RepositoryUri)
d.Set("image_tag_mutability", repository.ImageTagMutability)

if err := getTagsECR(conn, d); err != nil {
return fmt.Errorf("error getting ECR repository tags: %s", err)
tags, err := keyvaluetags.EcrListTags(conn, arn)

if err != nil {
return fmt.Errorf("error listing tags for ECR Repository (%s): %s", arn, err)
}

if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

return nil
}

func resourceAwsEcrRepositoryUpdate(d *schema.ResourceData, meta interface{}) error {
arn := d.Get("arn").(string)
conn := meta.(*AWSClient).ecrconn

if d.HasChange("image_tag_mutability") {
Expand All @@ -142,8 +151,12 @@ func resourceAwsEcrRepositoryUpdate(d *schema.ResourceData, meta interface{}) er
}
}

if err := setTagsECR(conn, d); err != nil {
return fmt.Errorf("error setting ECR repository tags: %s", err)
if d.HasChange("tags") {
o, n := d.GetChange("tags")

if err := keyvaluetags.EcrUpdateTags(conn, arn, o, n); err != nil {
return fmt.Errorf("error updating ECR Repository (%s) tags: %s", arn, err)
}
}

return resourceAwsEcrRepositoryRead(d, meta)
Expand Down
135 changes: 0 additions & 135 deletions aws/tagsECR.go

This file was deleted.

111 changes: 0 additions & 111 deletions aws/tagsECR_test.go

This file was deleted.