in pkg/question/question.go [891:1039]
func AskConfirmationWithInput(simpleConfig *config.SimpleInfo, detailedConfig *config.DetailedInfo,
allowEdit bool) string {
// If new subnets will be created, skip formatting the subnet info.
subnetInfo := "New Subnet"
subnet := detailedConfig.Subnet
if simpleConfig.NewVPC {
/*
If the subnet id is not empty and is not a real subnet id,
it will be a placeholder subnet with an availability zone.
*/
if simpleConfig.SubnetId != "" && simpleConfig.SubnetId[0:6] != "subnet" {
subnetInfo += " in " + simpleConfig.SubnetId
}
} else {
subnetInfo = *subnet.SubnetId
subnetTagName := ec2helper.GetTagName(subnet.Tags)
if subnetTagName != nil {
subnetInfo = fmt.Sprintf("%s(%s)", *subnetTagName, *subnet.SubnetId)
}
}
// If a new VPC will be created, skip formatting
vpcInfo := "New VPC"
vpc := detailedConfig.Vpc
if !simpleConfig.NewVPC {
vpcInfo = *vpc.VpcId
vpcTagName := ec2helper.GetTagName(vpc.Tags)
if vpcTagName != nil {
vpcInfo = fmt.Sprintf("%s(%s)", *vpcTagName, *vpc.VpcId)
}
}
// Get display data ready
data := [][]string{
{cli.ResourceRegion, simpleConfig.Region},
{cli.ResourceVpc, vpcInfo},
{cli.ResourceSubnet, subnetInfo},
{cli.ResourceInstanceType, simpleConfig.InstanceType},
{cli.ResourceImage, simpleConfig.ImageId},
}
indexedOptions := []string{}
stringOptions := []string{cli.ResponseYes, cli.ResponseNo}
/*
Append all security groups.
If security groups were successfully parsed into the detailed config, append them here.
Otherwise, look for placeholder security groups, such as "all" and "new" in the simple config.
Also, use the bool value to tell the next block what question option to use for security group
*/
if detailedConfig.SecurityGroups != nil {
data = table.AppendSecurityGroups(data, detailedConfig.SecurityGroups)
} else if simpleConfig.SecurityGroupIds != nil && len(simpleConfig.SecurityGroupIds) >= 1 {
if simpleConfig.SecurityGroupIds[0] == cli.ResponseNew {
data = append(data, []string{cli.ResourceSecurityGroup, "New security group for SSH"})
} else if simpleConfig.SecurityGroupIds[0] == cli.ResponseAll {
data = append(data, []string{cli.ResourceSecurityGroup, "New default security group"})
}
}
if ec2helper.HasEbsVolume(detailedConfig.Image) {
data = append(data, []string{cli.ResourceKeepEbsVolume,
strconv.FormatBool(simpleConfig.KeepEbsVolumeAfterTermination)})
}
if detailedConfig.Image.PlatformDetails != nil &&
ec2helper.IsLinux(*detailedConfig.Image.PlatformDetails) {
if simpleConfig.AutoTerminationTimerMinutes > 0 {
data = append(data, []string{cli.ResourceAutoTerminationTimer,
strconv.Itoa(simpleConfig.AutoTerminationTimerMinutes)})
} else {
data = append(data, []string{cli.ResourceAutoTerminationTimer, "None"})
}
}
// If edit is allowed, give all items a number and fill the indexed options
if allowEdit {
for i := 0; i < len(data); i++ {
// Skip region
if data[i][0] == cli.ResourceRegion {
continue
}
/*
Only add an option number for rows that has a value in the first column,
because some rows are subrows
*/
if data[i][0] != "" {
/*
If the row is for placeholder security group or placeholder subnet,
append a placeholder option.
Otherwise, append the first column of the row as option
*/
if simpleConfig.NewVPC {
if data[i][0] == cli.ResourceSecurityGroup {
indexedOptions = append(indexedOptions, cli.ResourceSecurityGroupPlaceholder)
} else if data[i][0] == cli.ResourceSubnet {
indexedOptions = append(indexedOptions, cli.ResourceSubnetPlaceholder)
} else {
indexedOptions = append(indexedOptions, data[i][0])
}
} else {
indexedOptions = append(indexedOptions, data[i][0])
}
data[i][0] = fmt.Sprintf("%s", data[i][0])
}
}
}
// Append all EBS blocks, if applicable
blockDeviceMappings := detailedConfig.Image.BlockDeviceMappings
data = table.AppendEbs(data, blockDeviceMappings)
// Append instance store, if applicable
if detailedConfig.InstanceTypeInfo.InstanceStorageInfo != nil {
data = append(data, []string{"Instance Storage", fmt.Sprintf("%d GB",
*detailedConfig.InstanceTypeInfo.InstanceStorageInfo.TotalSizeInGB)})
}
// Append instance profile, if applicable
if simpleConfig.IamInstanceProfile != "" {
data = append(data, []string{cli.ResourceIamInstanceProfile, simpleConfig.IamInstanceProfile})
}
if simpleConfig.BootScriptFilePath != "" {
data = append(data, []string{cli.ResourceBootScriptFilePath, simpleConfig.BootScriptFilePath})
}
if len(simpleConfig.UserTags) != 0 {
var tags []string
for k, v := range simpleConfig.UserTags {
tags = append(tags, fmt.Sprintf("%s|%s", k, v))
}
data = append(data, []string{cli.ResourceUserTags, strings.Join(tags, "\n")})
}
configText := table.BuildTable(data, nil)
optionsText := configText + yesNoOption + "\n"
question := "Please confirm if you would like to launch instance with following options"
answer := AskQuestion(&AskQuestionInput{
QuestionString: question,
OptionsString: &optionsText,
IndexedOptions: indexedOptions,
StringOptions: stringOptions,
})
return answer
}