in pkg/selector/selector.go [414:456]
func (itf Selector) RetrieveInstanceTypesSupportedInLocations(locations []string) (map[string]string, error) {
if len(locations) == 0 {
return nil, nil
}
availableInstanceTypes := map[string]int{}
for _, location := range locations {
instanceTypeOfferingsInput := &ec2.DescribeInstanceTypeOfferingsInput{
Filters: []*ec2.Filter{
{
Name: aws.String(locationFilterKey),
Values: []*string{aws.String(location)},
},
},
}
locationType, err := itf.getLocationType(location)
if err != nil {
return nil, err
}
instanceTypeOfferingsInput.SetLocationType(locationType)
err = itf.EC2.DescribeInstanceTypeOfferingsPages(instanceTypeOfferingsInput, func(page *ec2.DescribeInstanceTypeOfferingsOutput, lastPage bool) bool {
for _, instanceType := range page.InstanceTypeOfferings {
if i, ok := availableInstanceTypes[*instanceType.InstanceType]; !ok {
availableInstanceTypes[*instanceType.InstanceType] = 1
} else {
availableInstanceTypes[*instanceType.InstanceType] = i + 1
}
}
return true
})
if err != nil {
return nil, fmt.Errorf("Encountered an error when describing instance type offerings: %w", err)
}
}
availableInstanceTypesAllLocations := map[string]string{}
for instanceType, locationsSupported := range availableInstanceTypes {
if locationsSupported == len(locations) {
availableInstanceTypesAllLocations[instanceType] = ""
}
}
return availableInstanceTypesAllLocations, nil
}