Skip to content

Commit

Permalink
Fix unaligned output from GetEc2InstanceInfo (#69)
Browse files Browse the repository at this point in the history
* Fix mismatch of instanceInfo and id

* align the return from GetEC2InstanceInfo to input
  • Loading branch information
Nate Catelli authored Oct 17, 2022
1 parent 19f7eb2 commit 1e43224
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ec2/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ import (
)

func GetEC2InstanceInfo(client ec2iface.EC2API, instances []*string) (output []*ec2.Instance, err error) {
keyedInstances := make(map[string]*ec2.Instance)

// Set up our DI input object
diInput := &ec2.DescribeInstancesInput{
InstanceIds: instances,
}

describeInstancesPager := func(page *ec2.DescribeInstancesOutput, lastPage bool) bool {
for _, reservation := range page.Reservations {
output = append(output, reservation.Instances...)
for _, i := range reservation.Instances {
keyedInstances[*i.InstanceId] = i
}

}

// If it's not the last page, continue
Expand All @@ -27,6 +32,10 @@ func GetEC2InstanceInfo(client ec2iface.EC2API, instances []*string) (output []*
return nil, fmt.Errorf("Could not describe EC2 instances\n%v", err)
}

for _, i := range instances {
output = append(output, keyedInstances[*i])
}

return output, nil
}

Expand Down

0 comments on commit 1e43224

Please sign in to comment.