Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unaligned output from GetEc2InstanceInfo #69

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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