Skip to content

Commit b4f5ceb

Browse files
Merge pull request #688 from wking/aws-default-region
pkg/asset/installconfig: Pull AWS region default from usual places
2 parents bc7e553 + 3325a68 commit b4f5ceb

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

docs/user/environment-variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The installer accepts a number of environment variable that allow the interactiv
3737
## Platform-Specific
3838

3939
* `AWS_PROFILE`:
40-
The AWS profile that corresponds to value in `${HOME}/.aws/credentials`. If not provided, the default is "default".
40+
The AWS profile that corresponds to value in `${HOME}/.aws/credentials`. If not provided, the default is "default".
4141
* `OPENSHIFT_INSTALL_AWS_REGION`:
4242
The AWS region to be used for installation.
4343
* `OPENSHIFT_INSTALL_LIBVIRT_URI`:

pkg/asset/installconfig/aws/aws.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"sort"
99
"strings"
1010

11+
"github.com/aws/aws-sdk-go/aws/session"
1112
"github.com/pkg/errors"
13+
"github.com/sirupsen/logrus"
1214
survey "gopkg.in/AlecAivazis/survey.v1"
1315

1416
"github.com/openshift/installer/pkg/asset"
@@ -53,6 +55,26 @@ func Platform() (*aws.Platform, error) {
5355
regionTransform := survey.TransformString(func(s string) string {
5456
return strings.SplitN(s, " ", 2)[0]
5557
})
58+
59+
defaultRegion := "us-east-1"
60+
_, ok := validAWSRegions[defaultRegion]
61+
if !ok {
62+
panic(fmt.Sprintf("installer bug: invalid default AWS region %q", defaultRegion))
63+
}
64+
65+
ssn := session.Must(session.NewSessionWithOptions(session.Options{
66+
SharedConfigState: session.SharedConfigEnable,
67+
}))
68+
defaultRegionPointer := ssn.Config.Region
69+
if defaultRegionPointer != nil {
70+
_, ok := validAWSRegions[*defaultRegionPointer]
71+
if ok {
72+
defaultRegion = *defaultRegionPointer
73+
} else {
74+
logrus.Warnf("Unrecognized AWS region %q, defaulting to %s", *defaultRegionPointer, defaultRegion)
75+
}
76+
}
77+
5678
sort.Strings(longRegions)
5779
sort.Strings(shortRegions)
5880
region, err := asset.GenerateUserProvidedAsset(
@@ -61,7 +83,7 @@ func Platform() (*aws.Platform, error) {
6183
Prompt: &survey.Select{
6284
Message: "Region",
6385
Help: "The AWS region to be used for installation.",
64-
Default: "us-east-1 (N. Virginia)",
86+
Default: fmt.Sprintf("%s (%s)", defaultRegion, validAWSRegions[defaultRegion]),
6587
Options: longRegions,
6688
},
6789
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {

0 commit comments

Comments
 (0)