in cmd/launch.go [221:269]
func launchNonInteractive(h *ec2helper.EC2Helper) {
simpleConfig := config.NewSimpleInfo()
if flagConfig.Region != "" {
simpleConfig.Region = flagConfig.Region
h.ChangeRegion(simpleConfig.Region)
}
// Try to get config from the config file
err := config.ReadConfig(simpleConfig, nil)
if cli.ShowError(err, "Loading config failed") {
// If getting config file fails, go for default values
fmt.Println("Generating default config...")
simpleConfig, err = h.GetDefaultSimpleConfig()
if cli.ShowError(err, "Generating config failed") {
return
}
}
// Override config with flags if applicable
config.OverrideConfigWithFlags(simpleConfig, flagConfig)
// When the flags specify a launch template
if flagConfig.LaunchTemplateId != "" {
// If using a launch template, ignore the config file. Only read from the flags
UseLaunchTemplateWithConfig(h, flagConfig)
return
}
// When the config file specifies a launch template
if simpleConfig.LaunchTemplateId != "" {
UseLaunchTemplateWithConfig(h, simpleConfig)
return
}
// Parse the simple string config to the detailed config with data structures for later use
detailedConfig, err := h.ParseConfig(simpleConfig)
if cli.ShowError(err, "Parsing config failed") {
return
}
confirmation := question.AskConfirmationWithInput(simpleConfig, detailedConfig, false)
// Launch the instance.
_, err = h.LaunchInstance(simpleConfig, detailedConfig, confirmation == cli.ResponseYes)
if cli.ShowError(err, "Launching instance failed") {
return
}
ReadSaveConfig(simpleConfig)
}