in pkg/selector/selector.go [638:684]
func (s Selector) RetrieveInstanceTypesSupportedInLocations(ctx context.Context, locations []string) (map[ec2types.InstanceType]string, error) {
if len(locations) == 0 {
return nil, nil
}
availableInstanceTypes := map[ec2types.InstanceType]int{}
for _, location := range locations {
locationType, err := s.getLocationType(ctx, location)
if err != nil {
return nil, err
}
instanceTypeOfferingsInput := &ec2.DescribeInstanceTypeOfferingsInput{
LocationType: locationType,
Filters: []ec2types.Filter{
{
Name: aws.String(locationFilterKey),
Values: []string{location},
},
},
}
p := ec2.NewDescribeInstanceTypeOfferingsPaginator(s.EC2, instanceTypeOfferingsInput)
for p.HasMorePages() {
instanceTypeOfferings, err := p.NextPage(ctx)
if err != nil {
return nil, fmt.Errorf("encountered an error when describing instance type offerings: %w", err)
}
for _, instanceType := range instanceTypeOfferings.InstanceTypeOfferings {
if i, ok := availableInstanceTypes[instanceType.InstanceType]; !ok {
availableInstanceTypes[instanceType.InstanceType] = 1
} else {
availableInstanceTypes[instanceType.InstanceType] = i + 1
}
}
}
}
availableInstanceTypesAllLocations := map[ec2types.InstanceType]string{}
for instanceType, locationsSupported := range availableInstanceTypes {
if locationsSupported == len(locations) {
availableInstanceTypesAllLocations[instanceType] = ""
}
}
return availableInstanceTypesAllLocations, nil
}