-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathdelete.go
57 lines (48 loc) · 1.22 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package ecspresso
import (
"context"
"fmt"
"github.com/Songmu/prompter"
"github.com/aws/aws-sdk-go-v2/service/ecs"
)
type DeleteOption struct {
DryRun bool `help:"dry-run" default:"false"`
Force bool `help:"delete without confirmation" default:"false"`
Terminate bool `help:"delete with terminate tasks" default:"false"`
}
func (opt DeleteOption) DryRunString() string {
if opt.DryRun {
return dryRunStr
}
return ""
}
func (d *App) Delete(ctx context.Context, opt DeleteOption) error {
ctx, cancel := d.Start(ctx)
defer cancel()
d.Log("Deleting service %s", opt.DryRunString())
sv, err := d.DescribeServiceStatus(ctx, 3)
if err != nil {
return err
}
if opt.DryRun {
d.Log("DRY RUN OK")
return nil
}
if !opt.Force {
service := prompter.Prompt(`Enter the service name to DELETE`, "")
if service != *sv.ServiceName {
d.Log("Aborted")
return fmt.Errorf("confirmation failed")
}
}
dsi := &ecs.DeleteServiceInput{
Cluster: &d.config.Cluster,
Service: sv.ServiceName,
Force: &opt.Terminate, // == aws ecs delete-service --force
}
if _, err := d.ecs.DeleteService(ctx, dsi); err != nil {
return fmt.Errorf("failed to delete service: %w", err)
}
d.Log("Service is deleted")
return nil
}