Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions pkg/asset/installconfig/powervs/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ func IsKnownZone(region string, zone string) bool {
// GetRegion prompts the user to select a region and returns that region.
func GetRegion(defaultRegion string) (string, error) {
regions := knownRegions()

longRegions := make([]string, 0, len(regions))
var idToLocationMappingHelpText string
shortRegions := make([]string, 0, len(regions))
for id, location := range regions {
longRegions = append(longRegions, fmt.Sprintf("%s (%s)", id, location))
shortRegions = append(shortRegions, id)
idToLocationMappingHelpText += fmt.Sprintf("%s: %s ", id, location)
}
sort.Strings(longRegions)
sort.Strings(shortRegions)

var regionTransform survey.Transformer = func(ans interface{}) interface{} {
Expand All @@ -79,16 +77,16 @@ func GetRegion(defaultRegion string) (string, error) {
if li == len(shortRegions) || shortRegions[li] != defaultRegion {
defaultRegion = "dal"
} else {
defaultRegion = longRegions[li]
defaultRegion = shortRegions[li]
}

err := survey.Ask([]*survey.Question{
{
Prompt: &survey.Select{
Message: "Region",
Help: "The Power VS region to be used for installation.",
Help: fmt.Sprintf("The Power VS region to be used for installation. The available regions are: %s", idToLocationMappingHelpText),
Default: defaultRegion,
Options: longRegions,
Options: shortRegions,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
choice := regionTransform(ans).(core.OptionAnswer).Value
Expand Down
8 changes: 6 additions & 2 deletions pkg/asset/installconfig/powervs/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ func getSecondSessionVarsFromUser(psv *SessionVars, pss *SessionStore) error {
return fmt.Errorf("failed to list resourceGroups: %w", err)
}

if len(resourceGroups.Resources) == 0 {
return fmt.Errorf("there are no resource groups in the account. Follow https://cloud.ibm.com/docs/account?topic=account-rgs for instructions to create a resource group")
}

resourceGroupsSurvey := make([]string, len(resourceGroups.Resources))
for i, resourceGroup := range resourceGroups.Resources {
resourceGroupsSurvey[i] = *resourceGroup.Name
Expand All @@ -384,8 +388,8 @@ func getSecondSessionVarsFromUser(psv *SessionVars, pss *SessionStore) error {
{
Prompt: &survey.Select{
Message: "Resource Group",
Help: "The Power VS resource group to be used for installation.",
Default: "",
Help: "The PowerVS resource group to be used for installation.",
Default: resourceGroupsSurvey[0],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this will always exist, and be the default resource group.
It'd be good to add this to the comment.

Options: resourceGroupsSurvey,
},
},
Expand Down