Skip to content

Commit

Permalink
[#3618] (Uninstalling V2 Racks Issue) Remove manually Stucked ECS Ser…
Browse files Browse the repository at this point in the history
…vices before trigger the CF stack deletion

[task 625](convox/issues-private#625)
  • Loading branch information
nightfury1204 committed Dec 9, 2022
1 parent 2d10651 commit b33b4f3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Binary file removed cmd/convox/convox
Binary file not shown.
41 changes: 41 additions & 0 deletions provider/aws/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,17 @@ func (p *Provider) SystemUninstall(name string, w io.Writer, opts structs.System
}
}

asgService := autoscaling.New(s)
for _, d := range deps {
// Workaround to uninstall v2 racks:
// ecs services fails to complete the delete unless asg/instances are deleted
err := cleanAsg(cf, asgService, d)
if err != nil {
return err
}
}

// Keep the Stack Uninstalling Process
for _, d := range deps {
tres, err := cf.GetTemplate(&cloudformation.GetTemplateInput{StackName: aws.String(d)})
if err != nil {
Expand All @@ -521,6 +532,36 @@ func (p *Provider) SystemUninstall(name string, w io.Writer, opts structs.System
return nil
}

func cleanAsg(cf *cloudformation.CloudFormation, asgservice *autoscaling.AutoScaling, stackName string) error {
output, err := cf.DescribeStackResources(&cloudformation.DescribeStackResourcesInput{
StackName: aws.String(stackName),
})

if err != nil {
return err
}

var asgList []*string
for _, resource := range output.StackResources {
if *resource.ResourceType == "AWS::AutoScaling::AutoScalingGroup" {
asgList = append(asgList, resource.PhysicalResourceId)
}
}

for _, as := range asgList {
fmt.Println(*as)
_, err := asgservice.DeleteAutoScalingGroup(&autoscaling.DeleteAutoScalingGroupInput{
AutoScalingGroupName: as,
ForceDelete: aws.Bool(true),
})
if err != nil {
return err
}
}

return nil
}

func (p *Provider) Sync(name string) error {
return fmt.Errorf("not supported")
}
Expand Down

0 comments on commit b33b4f3

Please sign in to comment.