github.com/sneal/packer@v0.5.2/builder/amazon/chroot/step_source_ami_info.go (about) 1 package chroot 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/goamz/ec2" 6 "github.com/mitchellh/multistep" 7 "github.com/mitchellh/packer/packer" 8 ) 9 10 // StepSourceAMIInfo extracts critical information from the source AMI 11 // that is used throughout the AMI creation process. 12 // 13 // Produces: 14 // source_image *ec2.Image - the source AMI info 15 type StepSourceAMIInfo struct{} 16 17 func (s *StepSourceAMIInfo) Run(state multistep.StateBag) multistep.StepAction { 18 config := state.Get("config").(*Config) 19 ec2conn := state.Get("ec2").(*ec2.EC2) 20 ui := state.Get("ui").(packer.Ui) 21 22 ui.Say("Inspecting the source AMI...") 23 imageResp, err := ec2conn.Images([]string{config.SourceAmi}, ec2.NewFilter()) 24 if err != nil { 25 err := fmt.Errorf("Error querying AMI: %s", err) 26 state.Put("error", err) 27 ui.Error(err.Error()) 28 return multistep.ActionHalt 29 } 30 31 if len(imageResp.Images) == 0 { 32 err := fmt.Errorf("Source AMI '%s' was not found!", config.SourceAmi) 33 state.Put("error", err) 34 ui.Error(err.Error()) 35 return multistep.ActionHalt 36 } 37 38 image := &imageResp.Images[0] 39 40 // It must be EBS-backed otherwise the build won't work 41 if image.RootDeviceType != "ebs" { 42 err := fmt.Errorf("The root device of the source AMI must be EBS-backed.") 43 state.Put("error", err) 44 ui.Error(err.Error()) 45 return multistep.ActionHalt 46 } 47 48 state.Put("source_image", image) 49 return multistep.ActionContinue 50 } 51 52 func (s *StepSourceAMIInfo) Cleanup(multistep.StateBag) {}