Skip to content

Commit

Permalink
Merge pull request #3672 from loivis/resource-ecs-service-import
Browse files Browse the repository at this point in the history
resource/ecs_service: fix crash when importing non-existing service
  • Loading branch information
bflad authored Mar 9, 2018
2 parents 26db49f + ec671c4 commit 5d19478
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions aws/resource_aws_ecs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 10 additions & 1 deletion aws/resource_aws_ecs_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -131,12 +131,21 @@ func TestAccAWSEcsService_basicImport(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`),
},
},
})
}
Expand Down

0 comments on commit 5d19478

Please sign in to comment.