Skip to content

Commit

Permalink
Merge branch 'barrytam20-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
bflad committed Oct 5, 2018
2 parents 28790a4 + 44074aa commit 6e933b4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
4 changes: 3 additions & 1 deletion aws/resource_aws_ecs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ func resourceAwsEcsServiceRead(d *schema.ResourceData, meta interface{}) error {
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()))
log.Printf("[WARN] ECS Service %s not found, removing from state.", d.Id())
d.SetId("")
return nil
}

service := out.Services[0]
Expand Down
68 changes: 67 additions & 1 deletion aws/resource_aws_ecs_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,32 @@ func TestAccAWSEcsService_basicImport(t *testing.T) {
ImportStateId: fmt.Sprintf("%s/nonexistent", clusterName),
ImportState: true,
ImportStateVerify: false,
ExpectError: regexp.MustCompile(`No ECS service found`),
ExpectError: regexp.MustCompile(`Please verify the ID is correct`),
},
},
})
}

func TestAccAWSEcsService_disappears(t *testing.T) {
var service ecs.Service
rString := acctest.RandString(8)

clusterName := fmt.Sprintf("tf-acc-cluster-svc-w-arn-%s", rString)
tdName := fmt.Sprintf("tf-acc-td-svc-w-arn-%s", rString)
svcName := fmt.Sprintf("tf-acc-svc-w-arn-%s", rString)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEcsService(clusterName, tdName, svcName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsServiceExists("aws_ecs_service.mongo", &service),
testAccCheckAWSEcsServiceDisappears(&service),
),
ExpectNonEmptyPlan: true,
},
},
})
Expand Down Expand Up @@ -803,6 +828,47 @@ func testAccCheckAWSEcsServiceExists(name string, service *ecs.Service) resource
}
}

func testAccCheckAWSEcsServiceDisappears(service *ecs.Service) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ecsconn

input := &ecs.DeleteServiceInput{
Cluster: service.ClusterArn,
Service: service.ServiceName,
Force: aws.Bool(true),
}

_, err := conn.DeleteService(input)

if err != nil {
return err
}

// Wait until it's deleted
wait := resource.StateChangeConf{
Pending: []string{"ACTIVE", "DRAINING"},
Target: []string{"INACTIVE"},
Timeout: 10 * time.Minute,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
resp, err := conn.DescribeServices(&ecs.DescribeServicesInput{
Cluster: service.ClusterArn,
Services: []*string{service.ServiceName},
})
if err != nil {
return resp, "FAILED", err
}

return resp, aws.StringValue(resp.Services[0].Status), nil
},
}

_, err = wait.WaitForState()

return err
}
}

func testAccAWSEcsService(clusterName, tdName, svcName string) string {
return fmt.Sprintf(`
resource "aws_ecs_cluster" "default" {
Expand Down

0 comments on commit 6e933b4

Please sign in to comment.