Skip to content

Commit

Permalink
Merge pull request #10520 from tomelliff/error-when-ecr-repo-not-foun…
Browse files Browse the repository at this point in the history
…d-by-data-source

Error when data.aws_ecr_repository cannot find repository
  • Loading branch information
anGie44 authored Jul 16, 2020
2 parents e255292 + 37613c3 commit 614a260
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions aws/data_source_aws_ecr_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,17 @@ func dataSourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) er
conn := meta.(*AWSClient).ecrconn
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

name := d.Get("name").(string)
params := &ecr.DescribeRepositoriesInput{
RepositoryNames: aws.StringSlice([]string{d.Get("name").(string)}),
RepositoryNames: aws.StringSlice([]string{name}),
}
log.Printf("[DEBUG] Reading ECR repository: %s", params)
out, err := conn.DescribeRepositories(params)
if err != nil {
if isAWSErr(err, ecr.ErrCodeRepositoryNotFoundException, "") {
log.Printf("[WARN] ECR Repository %s not found, removing from state", d.Id())
d.SetId("")
return nil
return fmt.Errorf("ECR Repository (%s) not found", name)
}
return fmt.Errorf("error reading ECR repository: %s", err)
return fmt.Errorf("error reading ECR repository: %w", err)
}

repository := out.Repositories[0]
Expand All @@ -66,11 +65,11 @@ func dataSourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) er
tags, err := keyvaluetags.EcrListTags(conn, arn)

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

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

return nil
Expand Down

0 comments on commit 614a260

Please sign in to comment.