pkg/random/aws.go (176 lines of code) (raw):
package random
import "math/rand"
var (
availabilityZones = [...]string{
"us-east-2a",
"us-east-2b",
"us-east-2c",
"us-east-1a",
"us-east-1b",
"us-east-1c",
"us-east-1d",
"us-east-1e",
"us-east-1f",
"us-west-1a",
"us-west-1c",
"us-west-2a",
"us-west-2b",
"us-west-2c",
"us-west-2d",
"ap-south-1a",
"ap-south-1b",
"ap-south-1c",
"ap-northeast-2a",
"ap-northeast-2b",
"ap-northeast-2c",
"ap-southeast-1a",
"ap-southeast-1b",
"ap-southeast-1c",
"ap-southeast-2a",
"ap-southeast-2b",
"ap-southeast-2c",
"ap-northeast-1a",
"ap-northeast-1c",
"ap-northeast-1d",
"ca-central-1a",
"ca-central-1b",
"eu-central-1a",
"eu-central-1b",
"eu-central-1c",
"eu-west-1a",
"eu-west-1b",
"eu-west-1c",
"eu-west-2a",
"eu-west-2b",
"eu-west-2c",
"eu-west-3a",
"eu-west-3b",
"eu-west-3c",
"eu-north-1a",
"eu-north-1b",
"eu-north-1c",
"sa-east-1a",
"sa-east-1b",
"sa-east-1c",
}
regions = [...]string{
"us-east-2",
"us-east-1",
"us-west-1",
"us-west-2",
"af-south-1",
"ap-east-1",
"ap-southeast-3",
"ap-south-1",
"ap-northeast-2",
"ap-southeast-1",
"ap-southeast-2",
"ap-northeast-1",
"ca-central-1",
"eu-central-1",
"eu-west-1",
"eu-west-2",
"eu-south-1",
"eu-west-3",
"eu-north-1",
"me-south-1",
"sa-east-1",
}
regionAZMap = map[string][]string{
"us-east-2": {
"us-east-2a",
"us-east-2b",
"us-east-2c",
},
"us-east-1": {
"us-east-1a",
"us-east-1b",
"us-east-1c",
"us-east-1d",
"us-east-1e",
"us-east-1f",
},
"us-west-1": {
"us-west-1a",
"us-west-1c",
},
"us-west-2": {
"us-west-2a",
"us-west-2b",
"us-west-2c",
"us-west-2d",
},
"ap-south-1": {
"ap-south-1a",
"ap-south-1b",
"ap-south-1c",
},
"ap-northeast-2": {
"ap-northeast-2a",
"ap-northeast-2b",
"ap-northeast-2c",
},
"ap-southeast-1": {
"ap-southeast-1a",
"ap-southeast-1b",
"ap-southeast-1c",
},
"ap-southeast-2": {
"ap-southeast-2a",
"ap-southeast-2b",
"ap-southeast-2c",
},
"ap-northeast-1": {
"ap-northeast-1a",
"ap-northeast-1c",
"ap-northeast-1d",
},
"ca-central-1": {
"ca-central-1a",
"ca-central-1b",
},
"eu-central-1": {
"eu-central-1a",
"eu-central-1b",
"eu-central-1c",
},
"eu-west-1": {
"eu-west-1a",
"eu-west-1b",
"eu-west-1c",
},
"eu-west-2": {
"eu-west-2a",
"eu-west-2b",
"eu-west-2c",
},
"eu-west-3": {
"eu-west-3a",
"eu-west-3b",
"eu-west-3c",
},
"eu-north-1": {
"eu-north-1a",
"eu-north-1b",
"eu-north-1c",
},
"sa-east-1": {
"sa-east-1a",
"sa-east-1b",
"sa-east-1c",
},
}
)
// AWSAvailabilityZone will return a random AWS Availability Zone.
func AWSAvailabilityZone() string {
return availabilityZones[rand.Intn(len(availabilityZones))]
}
// AWSAvailabilityZoneInRegion will return a random AWS Availability
// Zone in the provided region. If the region cannot be found, an empty
// string will be returned.
func AWSAvailabilityZoneInRegion(region string) string {
regionAZs, ok := regionAZMap[region]
if !ok {
return ""
}
return regionAZs[rand.Intn(len(regionAZs))]
}
// AWSRegion returns a random AWS region.
func AWSRegion() string {
return regions[rand.Intn(len(regions))]
}