2014-06-04 17:58:11 -04:00
|
|
|
package chroot
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2014-06-04 17:58:11 -04:00
|
|
|
"fmt"
|
|
|
|
|
2015-06-03 17:13:52 -04:00
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2014-06-04 17:58:11 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// StepCheckRootDevice makes sure the root device on the AMI is EBS-backed.
|
|
|
|
type StepCheckRootDevice struct{}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepCheckRootDevice) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2014-07-21 18:28:47 -04:00
|
|
|
image := state.Get("source_image").(*ec2.Image)
|
2014-06-04 17:58:11 -04:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
|
|
ui.Say("Checking the root device on source AMI...")
|
|
|
|
|
|
|
|
// It must be EBS-backed otherwise the build won't work
|
2015-04-05 17:58:48 -04:00
|
|
|
if *image.RootDeviceType != "ebs" {
|
2014-06-04 17:58:11 -04:00
|
|
|
err := fmt.Errorf("The root device of the source AMI must be EBS-backed.")
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepCheckRootDevice) Cleanup(multistep.StateBag) {}
|