Skip to content

Commit b7654d9

Browse files
authored
AWS: Include volumes created from snapshots (#786)
1 parent 8adaaf5 commit b7654d9

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

pkg/aws/client/compute.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,7 @@ func (e *compute) listComputeInstances(ctx context.Context) ([]types.Reservation
5656
// DISK
5757

5858
func (e *compute) listEBSVolumes(ctx context.Context) ([]types.Volume, error) {
59-
params := &awsEc2.DescribeVolumesInput{
60-
Filters: []types.Filter{
61-
// excludes volumes created from snapshots
62-
{
63-
Name: aws.String("snapshot-id"),
64-
Values: []string{""},
65-
},
66-
},
67-
}
68-
69-
pager := awsEc2.NewDescribeVolumesPaginator(e.client, params)
59+
pager := awsEc2.NewDescribeVolumesPaginator(e.client, &awsEc2.DescribeVolumesInput{})
7060
var volumes []types.Volume
7161

7262
for pager.HasMorePages() {

pkg/aws/client/compute_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,38 @@ func TestListEBSVolumes(t *testing.T) {
255255
},
256256
expectedCalls: 2,
257257
},
258+
"includes volumes created from snapshots": {
259+
DescribeVolumes: func(ctx context.Context, e *ec2.DescribeVolumesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeVolumesOutput, error) {
260+
for _, filter := range e.Filters {
261+
if filter.Name != nil && *filter.Name == "snapshot-id" {
262+
t.Errorf("snapshot-id filter should not be applied, as it excludes volumes created from snapshots")
263+
}
264+
}
265+
return &ec2.DescribeVolumesOutput{
266+
Volumes: []types.Volume{
267+
{
268+
VolumeId: aws.String("vol-no-snapshot"),
269+
SnapshotId: aws.String(""),
270+
},
271+
{
272+
VolumeId: aws.String("vol-from-snapshot"),
273+
SnapshotId: aws.String("snap-1234567890abcdef0"),
274+
},
275+
},
276+
}, nil
277+
},
278+
expected: []types.Volume{
279+
{
280+
VolumeId: aws.String("vol-no-snapshot"),
281+
SnapshotId: aws.String(""),
282+
},
283+
{
284+
VolumeId: aws.String("vol-from-snapshot"),
285+
SnapshotId: aws.String("snap-1234567890abcdef0"),
286+
},
287+
},
288+
expectedCalls: 1,
289+
},
258290
}
259291

260292
for name, tt := range tests {

0 commit comments

Comments
 (0)