diff --git a/ecs/cmd/main/main.go b/ecs/cmd/main/main.go index cde9be3bd..ab365bd40 100644 --- a/ecs/cmd/main/main.go +++ b/ecs/cmd/main/main.go @@ -133,6 +133,7 @@ func UpCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOptions) type downOptions struct { KeepLoadBalancer bool + DeleteCluster bool } func DownCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOptions) *cobra.Command { @@ -144,9 +145,10 @@ func DownCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOption if err != nil { return err } - return client.ComposeDown(project, opts.KeepLoadBalancer) + return client.ComposeDown(project, opts.KeepLoadBalancer, opts.DeleteCluster) }), } cmd.Flags().BoolVar(&opts.KeepLoadBalancer, "keep-load-balancer", false, "Keep Load Balancer for further use") + cmd.Flags().BoolVar(&opts.DeleteCluster, "delete-cluster", false, "Delete cluster") return cmd } diff --git a/ecs/pkg/amazon/down.go b/ecs/pkg/amazon/down.go index 4976aef14..a7b44892e 100644 --- a/ecs/pkg/amazon/down.go +++ b/ecs/pkg/amazon/down.go @@ -8,7 +8,7 @@ import ( "github.com/docker/ecs-plugin/pkg/compose" ) -func (c *client) ComposeDown(project *compose.Project, keepLoadBalancer bool) error { +func (c *client) ComposeDown(project *compose.Project, keepLoadBalancer, deleteCluster bool) error { _, err := c.CF.DeleteStack(&cloudformation.DeleteStackInput{ StackName: &project.Name, }) @@ -19,7 +19,13 @@ func (c *client) ComposeDown(project *compose.Project, keepLoadBalancer bool) er if err = c.CF.WaitUntilStackDeleteComplete(&cf.DescribeStacksInput{StackName: &project.Name}); err != nil { return err } - fmt.Printf("... done.\nDelete cluster %s", c.Cluster) + fmt.Printf("... done.\n") + + if !deleteCluster { + return nil + } + + fmt.Printf("Delete cluster %s", c.Cluster) if err = c.DeleteCluster(); err != nil { return err } diff --git a/ecs/pkg/compose/api.go b/ecs/pkg/compose/api.go index 50f62ccf7..4218de767 100644 --- a/ecs/pkg/compose/api.go +++ b/ecs/pkg/compose/api.go @@ -5,5 +5,5 @@ import "github.com/awslabs/goformation/v4/cloudformation" type API interface { Convert(project *Project, loadBalancerArn *string) (*cloudformation.Template, error) ComposeUp(project *Project, loadBalancerArn *string) error - ComposeDown(project *Project, keepLoadBalancer bool) error + ComposeDown(project *Project, keepLoadBalancer, deleteCluster bool) error }