Skip to content

Commit

Permalink
Properly list attached volumes (#33)
Browse files Browse the repository at this point in the history
* use attachment instance-id

* fixup
  • Loading branch information
tenyo authored Jun 10, 2022
1 parent d2d4b3e commit 5a26649
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ec2/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,29 @@ func (e *Ec2) ListInstanceVolumes(ctx context.Context, id string) ([]string, err
return nil, apierror.New(apierror.ErrBadRequest, "invalid input", nil)
}

log.Infof("getting snapshots for instance %s/%s", e.org, id)
log.Infof("getting volumes for instance %s/%s", e.org, id)

volumes := []string{}

input := ec2.DescribeVolumesInput{
Filters: []*ec2.Filter{
withInstanceId(id),
{
Name: aws.String("attachment.instance-id"),
Values: aws.StringSlice(
[]string{id},
),
},
},
MaxResults: aws.Int64(1000),
}

for {
out, err := e.Service.DescribeVolumesWithContext(ctx, &input)
if err != nil {
return nil, common.ErrCode("describing snapshots for volumes", err)
return nil, common.ErrCode("describing volumes for instance", err)
}

log.Debugf("got describe snapshots output %+v", out)
log.Debugf("got describe volumes output %+v", out)

for _, v := range out.Volumes {
volumes = append(volumes, aws.StringValue(v.VolumeId))
Expand Down

0 comments on commit 5a26649

Please sign in to comment.