github.phpd.cn/hashicorp/packer@v1.3.2/builder/amazon/chroot/step_check_root_device.go (about)

     1  package chroot
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/aws/aws-sdk-go/service/ec2"
     8  	"github.com/hashicorp/packer/helper/multistep"
     9  	"github.com/hashicorp/packer/packer"
    10  )
    11  
    12  // StepCheckRootDevice makes sure the root device on the AMI is EBS-backed.
    13  type StepCheckRootDevice struct{}
    14  
    15  func (s *StepCheckRootDevice) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
    16  	image := state.Get("source_image").(*ec2.Image)
    17  	ui := state.Get("ui").(packer.Ui)
    18  
    19  	ui.Say("Checking the root device on source AMI...")
    20  
    21  	// It must be EBS-backed otherwise the build won't work
    22  	if *image.RootDeviceType != "ebs" {
    23  		err := fmt.Errorf("The root device of the source AMI must be EBS-backed.")
    24  		state.Put("error", err)
    25  		ui.Error(err.Error())
    26  		return multistep.ActionHalt
    27  	}
    28  
    29  	return multistep.ActionContinue
    30  }
    31  
    32  func (s *StepCheckRootDevice) Cleanup(multistep.StateBag) {}