Skip to content

Commit

Permalink
Merge pull request #688 from wking/aws-default-region
Browse files Browse the repository at this point in the history
pkg/asset/installconfig: Pull AWS region default from usual places
  • Loading branch information
openshift-merge-robot committed Dec 6, 2018
2 parents bc7e553 + 3325a68 commit b4f5ceb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/user/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The installer accepts a number of environment variable that allow the interactiv
## Platform-Specific

* `AWS_PROFILE`:
The AWS profile that corresponds to value in `${HOME}/.aws/credentials`. If not provided, the default is "default".
The AWS profile that corresponds to value in `${HOME}/.aws/credentials`. If not provided, the default is "default".
* `OPENSHIFT_INSTALL_AWS_REGION`:
The AWS region to be used for installation.
* `OPENSHIFT_INSTALL_LIBVIRT_URI`:
Expand Down
24 changes: 23 additions & 1 deletion pkg/asset/installconfig/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"sort"
"strings"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
survey "gopkg.in/AlecAivazis/survey.v1"

"github.com/openshift/installer/pkg/asset"
Expand Down Expand Up @@ -53,6 +55,26 @@ func Platform() (*aws.Platform, error) {
regionTransform := survey.TransformString(func(s string) string {
return strings.SplitN(s, " ", 2)[0]
})

defaultRegion := "us-east-1"
_, ok := validAWSRegions[defaultRegion]
if !ok {
panic(fmt.Sprintf("installer bug: invalid default AWS region %q", defaultRegion))
}

ssn := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
defaultRegionPointer := ssn.Config.Region
if defaultRegionPointer != nil {
_, ok := validAWSRegions[*defaultRegionPointer]
if ok {
defaultRegion = *defaultRegionPointer
} else {
logrus.Warnf("Unrecognized AWS region %q, defaulting to %s", *defaultRegionPointer, defaultRegion)
}
}

sort.Strings(longRegions)
sort.Strings(shortRegions)
region, err := asset.GenerateUserProvidedAsset(
Expand All @@ -61,7 +83,7 @@ func Platform() (*aws.Platform, error) {
Prompt: &survey.Select{
Message: "Region",
Help: "The AWS region to be used for installation.",
Default: "us-east-1 (N. Virginia)",
Default: fmt.Sprintf("%s (%s)", defaultRegion, validAWSRegions[defaultRegion]),
Options: longRegions,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
Expand Down

0 comments on commit b4f5ceb

Please sign in to comment.