diff --git a/cmd/ore/aws/list-regions.go b/cmd/ore/aws/list-regions.go index 6cf8a2ff7f..0338a99e39 100644 --- a/cmd/ore/aws/list-regions.go +++ b/cmd/ore/aws/list-regions.go @@ -19,6 +19,8 @@ import ( "os" "github.com/spf13/cobra" + + "github.com/coreos/mantle/platform/api/aws" ) var ( @@ -29,14 +31,25 @@ var ( specified credentials file, profile, and region.`, RunE: runListRegions, } + disabledRegions bool + allRegions bool ) func init() { AWS.AddCommand(cmdListRegions) + cmdListRegions.Flags().BoolVar(&disabledRegions, "disabled", false, "list disabled regions") + cmdListRegions.Flags().BoolVar(&allRegions, "all", false, "list all regions") } func runListRegions(cmd *cobra.Command, args []string) error { - regions, err := API.ListRegions() + var kind = aws.RegionEnabled + if allRegions { + kind = aws.RegionAny + } else if disabledRegions { + kind = aws.RegionDisabled + } + + regions, err := API.ListRegions(kind) if err != nil { fmt.Fprintf(os.Stderr, "could not list regions: %v\n", err) os.Exit(1) diff --git a/platform/api/aws/ec2.go b/platform/api/aws/ec2.go index 02603f4bdb..126de763e4 100644 --- a/platform/api/aws/ec2.go +++ b/platform/api/aws/ec2.go @@ -28,10 +28,31 @@ import ( "github.com/coreos/mantle/util" ) +type RegionKind int + +const ( + RegionEnabled RegionKind = iota + RegionDisabled + RegionAny +) + // ListRegions lists the enabled regions in the AWS partition specified // implicitly by the CredentialsFile, Profile, and Region options. -func (a *API) ListRegions() ([]string, error) { - output, err := a.ec2.DescribeRegions(nil) +func (a *API) ListRegions(kind RegionKind) ([]string, error) { + input := ec2.DescribeRegionsInput{} + switch kind { + case RegionDisabled: + input.AllRegions = aws.Bool(true) + input.Filters = []*ec2.Filter{ + { + Name: aws.String("opt-in-status"), + Values: []*string{aws.String("not-opted-in")}, + }, + } + case RegionAny: + input.AllRegions = aws.Bool(true) + } + output, err := a.ec2.DescribeRegions(&input) if err != nil { return nil, fmt.Errorf("describing regions: %v", err) }