From 467a1bddb58ee9041f9e60bd31e70297f8063362 Mon Sep 17 00:00:00 2001 From: Tom Elliff Date: Wed, 16 Oct 2019 15:58:41 +0100 Subject: [PATCH 1/2] Error when data.aws_ecr_repository cannot find repository Fixes https://github.com/terraform-providers/terraform-provider-aws/issues/10071. --- aws/data_source_aws_ecr_repository.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/aws/data_source_aws_ecr_repository.go b/aws/data_source_aws_ecr_repository.go index b2f25e6f569..73cd1a8f049 100644 --- a/aws/data_source_aws_ecr_repository.go +++ b/aws/data_source_aws_ecr_repository.go @@ -45,11 +45,6 @@ func dataSourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) er 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("error reading ECR repository: %s", err) } From 37613c3841ab2cea3fb041d6088f5f1bec7c7067 Mon Sep 17 00:00:00 2001 From: Angie Pinilla Date: Thu, 16 Jul 2020 15:49:50 -0400 Subject: [PATCH 2/2] adjust error messaging --- aws/data_source_aws_ecr_repository.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/aws/data_source_aws_ecr_repository.go b/aws/data_source_aws_ecr_repository.go index 34d93ce4a4c..8e7ab3f621c 100644 --- a/aws/data_source_aws_ecr_repository.go +++ b/aws/data_source_aws_ecr_repository.go @@ -40,13 +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 { - return fmt.Errorf("error reading ECR repository: %s", err) + if isAWSErr(err, ecr.ErrCodeRepositoryNotFoundException, "") { + return fmt.Errorf("ECR Repository (%s) not found", name) + } + return fmt.Errorf("error reading ECR repository: %w", err) } repository := out.Repositories[0] @@ -61,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