Skip to content

Commit

Permalink
Fix terminate bug when there exists just single instance (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
imuqtadir authored Nov 23, 2020
1 parent fd0c406 commit 8bde183
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/question/question.go
Original file line number Diff line number Diff line change
Expand Up @@ -1030,12 +1030,17 @@ func AskInstanceIds(h *ec2helper.EC2Helper, addedInstanceIds []string) (*string,
data, indexedOptions, finalCounter := table.AppendInstances(data, indexedOptions, instances,
addedInstanceIds)

// If no instance is available, simply don't ask
if len(data) <= 0 {
// There are no instances available for termination in selected region
if len(data) <= 0 && len(addedInstanceIds) == 0 {
return nil, errors.New("No instance available in selected region for termination")
}

// Since no more instance(s) are available for termination, proceed with current selection
if len(data) == 0 && len(addedInstanceIds) > 0 {
return nil, nil
}

// Add "done" option, if the added instance ids slice is not empty
// Add "done" option, if instance(s) are already selected
if len(addedInstanceIds) > 0 {
indexedOptions = append(indexedOptions, cli.ResponseNo)
data = append(data, []string{fmt.Sprintf("%d.", finalCounter+1),
Expand Down

0 comments on commit 8bde183

Please sign in to comment.