func AskVpc()

in pkg/question/question.go [608:653]


func AskVpc(h *ec2helper.EC2Helper) (*string, error) {
	vpcs, err := h.GetAllVpcs()
	if err != nil {
		return nil, err
	}

	data := [][]string{}
	indexedOptions := []string{}
	defaultOptionRepr, defaultOptionValue := "Create new VPC", cli.ResponseNew

	// Add VPCs to the data for table
	if vpcs != nil {
		for index, vpc := range vpcs {
			indexedOptions = append(indexedOptions, *vpc.VpcId)

			vpcName := *vpc.VpcId
			vpcTagName := ec2helper.GetTagName(vpc.Tags)
			if vpcTagName != nil {
				vpcName = fmt.Sprintf("%s(%s)", *vpcTagName, *vpc.VpcId)
			}

			if *vpc.IsDefault {
				defaultOptionRepr, defaultOptionValue = vpcName, *vpc.VpcId
			}

			data = append(data, []string{fmt.Sprintf("%d.", index+1), vpcName, *vpc.CidrBlock})
		}
	}

	indexedOptions = append(indexedOptions, cli.ResponseNew)
	data = append(data, []string{fmt.Sprintf("%d.", len(data)+1),
		fmt.Sprintf("Create new VPC with default CIDR and %d subnets", cfn.RequiredAvailabilityZones)})

	question := "VPC"
	optionsText := table.BuildTable(data, []string{"Option", "VPC", "CIDR Block"})

	answer := AskQuestion(&AskQuestionInput{
		QuestionString:    question,
		DefaultOptionRepr: &defaultOptionRepr,
		DefaultOption:     &defaultOptionValue,
		OptionsString:     &optionsText,
		IndexedOptions:    indexedOptions,
	})

	return &answer, nil
}