From f49db65099009ed6a92470c48f81f15deeb89eb3 Mon Sep 17 00:00:00 2001 From: John Pignata Date: Tue, 2 Jan 2018 21:32:50 -0500 Subject: [PATCH] Don't attempt to destroy services scaled > 0 This led to an unfortunate situation where the target group was destroyed by the service was not which broke all manner of things. --- CHANGELOG.md | 5 +++-- cmd/service_destroy.go | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2676d5a..6c733aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,10 @@ - service create and task run will no longer create a repository if an image is explictly passed. - service destroy will remove all references the service's target group and - delete it + delete it. - Fix git repo detection to properly use a git sha image tag rather than a - time stamp tag ([#6][issue-6]) + time stamp tag. ([#6][issue-6]) +- Fail fast if a user attempts to destroy a service scaled above 0. ## 0.2.0 (2017-12-31) diff --git a/cmd/service_destroy.go b/cmd/service_destroy.go index 6aa7d44..f161a8a 100644 --- a/cmd/service_destroy.go +++ b/cmd/service_destroy.go @@ -38,6 +38,11 @@ func destroyService(operation *ServiceDestroyOperation) { ecs := ECS.New(sess, clusterName) service := ecs.DescribeService(operation.ServiceName) + if service.DesiredCount > 0 { + err := fmt.Errorf("%d tasks running, scale service to 0", service.DesiredCount) + console.ErrorExit(err, "Cannot destroy service %s", operation.ServiceName) + } + if service.TargetGroupArn != "" { loadBalancerArn := elbv2.GetTargetGroupLoadBalancerArn(service.TargetGroupArn) loadBalancer := elbv2.DescribeLoadBalancerByArn(loadBalancerArn)