Use DescribeRegions for aws region validation
This commit is contained in:
parent
31bbe2983b
commit
98f13eaf29
|
@ -1,29 +1,26 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
// aws ec2 describe-regions --query 'Regions[].{Name:RegionName}' --output text | sed 's/\(.*\)/"\1",/' | sort
|
import (
|
||||||
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
|
)
|
||||||
|
|
||||||
func listEC2Regions() []string {
|
func listEC2Regions() []string {
|
||||||
return []string{
|
var regions []string
|
||||||
"ap-northeast-1",
|
// append regions that are not part of autogenerated list
|
||||||
"ap-northeast-2",
|
regions = append(regions, "us-gov-west-1", "cn-north-1", "cn-northwest-1")
|
||||||
"ap-northeast-3",
|
|
||||||
"ap-south-1",
|
sess := session.Must(session.NewSessionWithOptions(session.Options{
|
||||||
"ap-southeast-1",
|
SharedConfigState: session.SharedConfigEnable,
|
||||||
"ap-southeast-2",
|
}))
|
||||||
"ca-central-1",
|
|
||||||
"eu-central-1",
|
ec2conn := ec2.New(sess)
|
||||||
"eu-west-1",
|
resultRegions, _ := ec2conn.DescribeRegions(nil)
|
||||||
"eu-west-2",
|
for _, region := range resultRegions.Regions {
|
||||||
"eu-west-3",
|
regions = append(regions, *region.RegionName)
|
||||||
"sa-east-1",
|
|
||||||
"us-east-1",
|
|
||||||
"us-east-2",
|
|
||||||
"us-west-1",
|
|
||||||
"us-west-2",
|
|
||||||
// not part of autogenerated list
|
|
||||||
"us-gov-west-1",
|
|
||||||
"cn-north-1",
|
|
||||||
"cn-northwest-1",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return regions
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateRegion returns true if the supplied region is a valid AWS
|
// ValidateRegion returns true if the supplied region is a valid AWS
|
||||||
|
|
Loading…
Reference in New Issue