From 027b0f6b543bc0be7fc8228a79713015bcec1e59 Mon Sep 17 00:00:00 2001 From: "xiaowei.wang" Date: Thu, 8 Mar 2018 11:36:21 +0100 Subject: [PATCH 1/2] resource/ecs_service: fix crash when importing non-existing service --- aws/resource_aws_ecs_service.go | 7 +++++-- aws/resource_aws_ecs_service_test.go | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_ecs_service.go b/aws/resource_aws_ecs_service.go index fa72419e4a5..7d8b74aba70 100644 --- a/aws/resource_aws_ecs_service.go +++ b/aws/resource_aws_ecs_service.go @@ -357,8 +357,11 @@ func resourceAwsEcsServiceRead(d *schema.ResourceData, meta interface{}) error { return resource.NonRetryableError(err) } - if d.IsNewResource() && len(out.Services) < 1 { - return resource.RetryableError(fmt.Errorf("No ECS service found: %q", d.Id())) + if len(out.Services) < 1 { + if d.IsNewResource() { + return resource.RetryableError(fmt.Errorf("ECS service not created yet: %q", d.Id())) + } + return resource.NonRetryableError(fmt.Errorf("No ECS service found: %q", d.Id())) } service := out.Services[0] diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index 60ec6bcf6ab..0e672bfdb22 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -113,7 +113,7 @@ func TestAccAWSEcsService_withARN(t *testing.T) { }) } -func TestAccAWSEcsService_basicImport(t *testing.T) { +func TestAccAWSEcsService_importBasic(t *testing.T) { rString := acctest.RandString(8) clusterName := fmt.Sprintf("tf-acc-cluster-svc-%s", rString) From ec671c413f75f1ab21e302cdba4c31ee229e4d01 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Fri, 9 Mar 2018 11:35:44 -0500 Subject: [PATCH 2/2] test/resource/aws_ecs_service: Add test for non-existent resource import --- aws/resource_aws_ecs_service_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index 0e672bfdb22..f9d3042223f 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -131,12 +131,21 @@ func TestAccAWSEcsService_importBasic(t *testing.T) { { Config: testAccAWSEcsServiceWithFamilyAndRevision(clusterName, tdName, svcName), }, + // Test existent resource import { ResourceName: resourceName, ImportStateId: importInput, ImportState: true, ImportStateVerify: true, }, + // Test non-existent resource import + { + ResourceName: resourceName, + ImportStateId: fmt.Sprintf("%s/nonexistent", clusterName), + ImportState: true, + ImportStateVerify: false, + ExpectError: regexp.MustCompile(`No ECS service found`), + }, }, }) }