amazon-ebssurrogate: allow enabling ena/sr-iov on spot instances

This commit is contained in:
Anthony Dong 2019-11-21 11:13:32 +01:00
parent ef87cace9f
commit 2e989088e5
2 changed files with 7 additions and 7 deletions

View File

@ -13,6 +13,7 @@ import (
) )
type StepModifyEBSBackedInstance struct { type StepModifyEBSBackedInstance struct {
Skip bool
EnableAMIENASupport confighelper.Trilean EnableAMIENASupport confighelper.Trilean
EnableAMISriovNetSupport bool EnableAMISriovNetSupport bool
} }
@ -22,6 +23,11 @@ func (s *StepModifyEBSBackedInstance) Run(ctx context.Context, state multistep.S
instance := state.Get("instance").(*ec2.Instance) instance := state.Get("instance").(*ec2.Instance)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
// Skip when it is a spot instance
if s.Skip {
return multistep.ActionContinue
}
// Set SriovNetSupport to "simple". See http://goo.gl/icuXh5 // Set SriovNetSupport to "simple". See http://goo.gl/icuXh5
// As of February 2017, this applies to C3, C4, D2, I2, R3, and M4 (excluding m4.16xlarge) // As of February 2017, this applies to C3, C4, D2, I2, R3, and M4 (excluding m4.16xlarge)
if s.EnableAMISriovNetSupport { if s.EnableAMISriovNetSupport {

View File

@ -123,13 +123,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("no volume with name '%s' is found", b.config.RootDevice.SourceDeviceName)) errs = packer.MultiErrorAppend(errs, fmt.Errorf("no volume with name '%s' is found", b.config.RootDevice.SourceDeviceName))
} }
if b.config.IsSpotInstance() && (b.config.AMIENASupport.True() || b.config.AMISriovNetSupport) {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Spot instances do not support modification, which is required "+
"when either `ena_support` or `sriov_support` are set. Please ensure "+
"you use an AMI that already has either SR-IOV or ENA enabled."))
}
if b.config.RunConfig.SpotPriceAutoProduct != "" { if b.config.RunConfig.SpotPriceAutoProduct != "" {
warns = append(warns, "spot_price_auto_product is deprecated and no "+ warns = append(warns, "spot_price_auto_product is deprecated and no "+
"longer necessary for Packer builds. In future versions of "+ "longer necessary for Packer builds. In future versions of "+
@ -294,6 +287,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
DisableStopInstance: b.config.DisableStopInstance, DisableStopInstance: b.config.DisableStopInstance,
}, },
&awscommon.StepModifyEBSBackedInstance{ &awscommon.StepModifyEBSBackedInstance{
Skip: b.config.IsSpotInstance(),
EnableAMISriovNetSupport: b.config.AMISriovNetSupport, EnableAMISriovNetSupport: b.config.AMISriovNetSupport,
EnableAMIENASupport: b.config.AMIENASupport, EnableAMIENASupport: b.config.AMIENASupport,
}, },