From 0505fb4a0a98ead00083ce82a72de0d76b164066 Mon Sep 17 00:00:00 2001 From: Matt Surabian Date: Thu, 11 Jul 2013 17:41:17 -0400 Subject: [PATCH] Validate that instance exists and is EBS based before trying to launch it. --- builder/amazonebs/step_run_source_instance.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/builder/amazonebs/step_run_source_instance.go b/builder/amazonebs/step_run_source_instance.go index 90e28e142..cb4ab7f25 100644 --- a/builder/amazonebs/step_run_source_instance.go +++ b/builder/amazonebs/step_run_source_instance.go @@ -28,6 +28,22 @@ func (s *stepRunSourceInstance) Run(state map[string]interface{}) multistep.Step SecurityGroups: []ec2.SecurityGroup{ec2.SecurityGroup{Id: securityGroupId}}, } + ui.Say("Validating Source AMI...") + imageResp, err := ec2conn.Images([]string{config.SourceAmi}, ec2.NewFilter()) + if err != nil { + err := fmt.Errorf("There was a problem with the provided source AMI: %s", err) + state["error"] = err + ui.Error(err.Error()) + return multistep.ActionHalt + } + + if imageResp.Images[0].RootDeviceType != "ebs" { + err := fmt.Errorf("The provided source AMI is instance-store based. The amazon-ebs bundler can only work with EBS based AMIs.") + state["error"] = err + ui.Error(err.Error()) + return multistep.ActionHalt + } + ui.Say("Launching a source AWS instance...") runResp, err := ec2conn.RunInstances(runOpts) if err != nil {