in pkg/question/question.go [527:588]
func AskIamProfile(i *iamhelper.IAMHelper) (string, error) {
input := &iam.ListInstanceProfilesInput{
MaxItems: aws.Int64(10),
}
output, err := i.Client.ListInstanceProfiles(input)
if err != nil {
return "", err
}
instanceProfiles := output.InstanceProfiles
for {
if *output.IsTruncated {
input = &iam.ListInstanceProfilesInput{
MaxItems: aws.Int64(10),
Marker: aws.String(*output.Marker),
}
output, err = i.Client.ListInstanceProfiles(input)
if err != nil {
return "", err
}
if len(output.InstanceProfiles) > 0 {
instanceProfiles = append(instanceProfiles, output.InstanceProfiles...)
}
} else {
break
}
}
data := [][]string{}
indexedOptions := []string{}
var optionsText string
if len(instanceProfiles) > 0 {
counter := 0
for _, profile := range instanceProfiles {
indexedOptions = append(indexedOptions, *profile.InstanceProfileName)
data = append(data, []string{fmt.Sprintf("%d.", counter+1), *profile.InstanceProfileName, *profile.InstanceProfileId,
profile.CreateDate.String()})
counter++
}
} else {
optionsText = "No IAM Profiles available\n"
}
// Add the do not attach IAM profile option at the end
defaultOptionRepr, defaultOptionValue := "Do not attach IAM profile", cli.ResponseNo
indexedOptions = append(indexedOptions, defaultOptionValue)
data = append(data, []string{fmt.Sprintf("%d.", len(data)+1), defaultOptionRepr, "", ""})
optionsText = table.BuildTable(data, []string{"Option", "PROFILE NAME", "PROFILE ID",
"Creation Date"})
question := "IAM Profile"
answer := AskQuestion(&AskQuestionInput{
QuestionString: question,
DefaultOptionRepr: &defaultOptionRepr,
DefaultOption: &defaultOptionValue,
OptionsString: &optionsText,
IndexedOptions: indexedOptions,
})
return answer, nil
}