Convert `ena_support` to a pointer

This means it now has three states, `true`, `false`, & `nil`. The
default state is now `nil` which does nothing instead of `false` which
now will explicitly disable ENA support instead of just not enabling it.
This commit is contained in:
Matt Dainty 2018-10-19 12:21:00 +01:00
parent 556e26c093
commit feb8067c7d
10 changed files with 33 additions and 31 deletions

View File

@ -14,7 +14,7 @@ import (
// StepRegisterAMI creates the AMI. // StepRegisterAMI creates the AMI.
type StepRegisterAMI struct { type StepRegisterAMI struct {
RootVolumeSize int64 RootVolumeSize int64
EnableAMIENASupport bool EnableAMIENASupport *bool
EnableAMISriovNetSupport bool EnableAMISriovNetSupport bool
} }
@ -83,7 +83,7 @@ func (s *StepRegisterAMI) Run(ctx context.Context, state multistep.StateBag) mul
// 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)
registerOpts.SriovNetSupport = aws.String("simple") registerOpts.SriovNetSupport = aws.String("simple")
} }
if s.EnableAMIENASupport { if s.EnableAMIENASupport != nil && *s.EnableAMIENASupport {
// Set EnaSupport to true // Set EnaSupport to true
// As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge
registerOpts.EnaSupport = aws.Bool(true) registerOpts.EnaSupport = aws.Bool(true)

View File

@ -19,7 +19,7 @@ type AMIConfig struct {
AMIRegions []string `mapstructure:"ami_regions"` AMIRegions []string `mapstructure:"ami_regions"`
AMISkipRegionValidation bool `mapstructure:"skip_region_validation"` AMISkipRegionValidation bool `mapstructure:"skip_region_validation"`
AMITags TagMap `mapstructure:"tags"` AMITags TagMap `mapstructure:"tags"`
AMIENASupport bool `mapstructure:"ena_support"` AMIENASupport *bool `mapstructure:"ena_support"`
AMISriovNetSupport bool `mapstructure:"sriov_support"` AMISriovNetSupport bool `mapstructure:"sriov_support"`
AMIForceDeregister bool `mapstructure:"force_deregister"` AMIForceDeregister bool `mapstructure:"force_deregister"`
AMIForceDeleteSnapshot bool `mapstructure:"force_delete_snapshot"` AMIForceDeleteSnapshot bool `mapstructure:"force_delete_snapshot"`

View File

@ -12,7 +12,7 @@ import (
) )
type StepModifyEBSBackedInstance struct { type StepModifyEBSBackedInstance struct {
EnableAMIENASupport bool EnableAMIENASupport *bool
EnableAMISriovNetSupport bool EnableAMISriovNetSupport bool
} }
@ -40,22 +40,24 @@ func (s *StepModifyEBSBackedInstance) Run(_ context.Context, state multistep.Sta
// Handle EnaSupport flag. // Handle EnaSupport flag.
// As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge
var prefix string if s.EnableAMIENASupport != nil {
if s.EnableAMIENASupport { var prefix string
prefix = "En" if *s.EnableAMIENASupport {
} else { prefix = "En"
prefix = "Dis" } else {
} prefix = "Dis"
ui.Say(fmt.Sprintf("%sabling Enhanced Networking (ENA)...", prefix)) }
_, err := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{ ui.Say(fmt.Sprintf("%sabling Enhanced Networking (ENA)...", prefix))
InstanceId: instance.InstanceId, _, err := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
EnaSupport: &ec2.AttributeBooleanValue{Value: aws.Bool(s.EnableAMIENASupport)}, InstanceId: instance.InstanceId,
}) EnaSupport: &ec2.AttributeBooleanValue{Value: aws.Bool(*s.EnableAMIENASupport)},
if err != nil { })
err := fmt.Errorf("Error %sabling Enhanced Networking (ENA) on %s: %s", strings.ToLower(prefix), *instance.InstanceId, err) if err != nil {
state.Put("error", err) err := fmt.Errorf("Error %sabling Enhanced Networking (ENA) on %s: %s", strings.ToLower(prefix), *instance.InstanceId, err)
ui.Error(err.Error()) state.Put("error", err)
return multistep.ActionHalt ui.Error(err.Error())
return multistep.ActionHalt
}
} }
return multistep.ActionContinue return multistep.ActionContinue

View File

@ -20,7 +20,7 @@ import (
type StepSourceAMIInfo struct { type StepSourceAMIInfo struct {
SourceAmi string SourceAmi string
EnableAMISriovNetSupport bool EnableAMISriovNetSupport bool
EnableAMIENASupport bool EnableAMIENASupport *bool
AMIVirtType string AMIVirtType string
AmiFilters AmiFilterOptions AmiFilters AmiFilterOptions
} }
@ -106,7 +106,7 @@ func (s *StepSourceAMIInfo) Run(_ context.Context, state multistep.StateBag) mul
// Enhanced Networking can only be enabled on HVM AMIs. // Enhanced Networking can only be enabled on HVM AMIs.
// See http://goo.gl/icuXh5 // See http://goo.gl/icuXh5
if s.EnableAMIENASupport || s.EnableAMISriovNetSupport { if (s.EnableAMIENASupport != nil && *s.EnableAMIENASupport) || s.EnableAMISriovNetSupport {
err = s.canEnableEnhancedNetworking(image) err = s.canEnableEnhancedNetworking(image)
if err != nil { if err != nil {
state.Put("error", err) state.Put("error", err)

View File

@ -70,7 +70,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, b.config.BlockDevices.Prepare(&b.config.ctx)...) errs = packer.MultiErrorAppend(errs, b.config.BlockDevices.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...) errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
if b.config.IsSpotInstance() && (b.config.AMIENASupport || b.config.AMISriovNetSupport) { if b.config.IsSpotInstance() && ((b.config.AMIENASupport != nil && *b.config.AMIENASupport) || b.config.AMISriovNetSupport) {
errs = packer.MultiErrorAppend(errs, errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Spot instances do not support modification, which is required "+ fmt.Errorf("Spot instances do not support modification, which is required "+
"when either `ena_support` or `sriov_support` are set. Please ensure "+ "when either `ena_support` or `sriov_support` are set. Please ensure "+

View File

@ -85,7 +85,7 @@ 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 || b.config.AMISriovNetSupport) { if b.config.IsSpotInstance() && ((b.config.AMIENASupport != nil && *b.config.AMIENASupport) || b.config.AMISriovNetSupport) {
errs = packer.MultiErrorAppend(errs, errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Spot instances do not support modification, which is required "+ fmt.Errorf("Spot instances do not support modification, which is required "+
"when either `ena_support` or `sriov_support` are set. Please ensure "+ "when either `ena_support` or `sriov_support` are set. Please ensure "+

View File

@ -16,7 +16,7 @@ type StepRegisterAMI struct {
RootDevice RootBlockDevice RootDevice RootBlockDevice
AMIDevices []*ec2.BlockDeviceMapping AMIDevices []*ec2.BlockDeviceMapping
LaunchDevices []*ec2.BlockDeviceMapping LaunchDevices []*ec2.BlockDeviceMapping
EnableAMIENASupport bool EnableAMIENASupport *bool
EnableAMISriovNetSupport bool EnableAMISriovNetSupport bool
image *ec2.Image image *ec2.Image
} }
@ -44,7 +44,7 @@ func (s *StepRegisterAMI) Run(ctx context.Context, state multistep.StateBag) mul
// 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)
registerOpts.SriovNetSupport = aws.String("simple") registerOpts.SriovNetSupport = aws.String("simple")
} }
if s.EnableAMIENASupport { if s.EnableAMIENASupport != nil && *s.EnableAMIENASupport {
// Set EnaSupport to true // Set EnaSupport to true
// As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge
registerOpts.EnaSupport = aws.Bool(true) registerOpts.EnaSupport = aws.Bool(true)

View File

@ -24,7 +24,7 @@ type Config struct {
awscommon.RunConfig `mapstructure:",squash"` awscommon.RunConfig `mapstructure:",squash"`
VolumeMappings []BlockDevice `mapstructure:"ebs_volumes"` VolumeMappings []BlockDevice `mapstructure:"ebs_volumes"`
AMIENASupport bool `mapstructure:"ena_support"` AMIENASupport *bool `mapstructure:"ena_support"`
AMISriovNetSupport bool `mapstructure:"sriov_support"` AMISriovNetSupport bool `mapstructure:"sriov_support"`
launchBlockDevices awscommon.BlockDevices launchBlockDevices awscommon.BlockDevices
@ -70,7 +70,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, err) errs = packer.MultiErrorAppend(errs, err)
} }
if b.config.IsSpotInstance() && (b.config.AMIENASupport || b.config.AMISriovNetSupport) { if b.config.IsSpotInstance() && ((b.config.AMIENASupport != nil && *b.config.AMIENASupport) || b.config.AMISriovNetSupport) {
errs = packer.MultiErrorAppend(errs, errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Spot instances do not support modification, which is required "+ fmt.Errorf("Spot instances do not support modification, which is required "+
"when either `ena_support` or `sriov_support` are set. Please ensure "+ "when either `ena_support` or `sriov_support` are set. Please ensure "+

View File

@ -156,7 +156,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs, fmt.Errorf("x509_key_path points to bad file: %s", err)) errs, fmt.Errorf("x509_key_path points to bad file: %s", err))
} }
if b.config.IsSpotInstance() && (b.config.AMIENASupport || b.config.AMISriovNetSupport) { if b.config.IsSpotInstance() && ((b.config.AMIENASupport != nil && *b.config.AMIENASupport) || b.config.AMISriovNetSupport) {
errs = packer.MultiErrorAppend(errs, errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Spot instances do not support modification, which is required "+ fmt.Errorf("Spot instances do not support modification, which is required "+
"when either `ena_support` or `sriov_support` are set. Please ensure "+ "when either `ena_support` or `sriov_support` are set. Please ensure "+

View File

@ -12,7 +12,7 @@ import (
) )
type StepRegisterAMI struct { type StepRegisterAMI struct {
EnableAMIENASupport bool EnableAMIENASupport *bool
EnableAMISriovNetSupport bool EnableAMISriovNetSupport bool
} }
@ -38,7 +38,7 @@ func (s *StepRegisterAMI) Run(ctx context.Context, state multistep.StateBag) mul
// 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)
registerOpts.SriovNetSupport = aws.String("simple") registerOpts.SriovNetSupport = aws.String("simple")
} }
if s.EnableAMIENASupport { if s.EnableAMIENASupport != nil && *s.EnableAMIENASupport {
// Set EnaSupport to true // Set EnaSupport to true
// As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge
registerOpts.EnaSupport = aws.Bool(true) registerOpts.EnaSupport = aws.Bool(true)