From c189c7ed12e3734a38f22268d5c37df7f66dc162 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 29 Jul 2013 17:19:17 -0700 Subject: [PATCH] builder/amazon/chroot: verify we're on an EC2 instance --- builder/amazon/chroot/step_check_ec2.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/builder/amazon/chroot/step_check_ec2.go b/builder/amazon/chroot/step_check_ec2.go index d600e8a8e..4e8d5e6e8 100644 --- a/builder/amazon/chroot/step_check_ec2.go +++ b/builder/amazon/chroot/step_check_ec2.go @@ -1,15 +1,32 @@ package chroot import ( + "fmt" + "github.com/mitchellh/goamz/aws" "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" + "log" ) +// StepCheckEC2 verifies that this builder is running on an EC2 instance. type StepCheckEC2 struct{} func (s *StepCheckEC2) Run(state map[string]interface{}) multistep.StepAction { ui := state["ui"].(packer.Ui) + ui.Say("Verifying we're on an EC2 instance...") + id, err := aws.GetMetaData("instance-id") + if err != nil { + log.Printf("Error: %s", err) + err := fmt.Errorf( + "Error retrieving the ID of the instance Packer is running on.\n" + + "Please verify Packer is running on a proper AWS EC2 instance.") + state["error"] = err + ui.Error(err.Error()) + return multistep.ActionHalt + } + log.Printf("Instance ID: %s", string(id)) + return multistep.ActionContinue }