diff --git a/builder/amazon/chroot/step_register_ami.go b/builder/amazon/chroot/step_register_ami.go index 4f3ad54c4..dbb84a5be 100644 --- a/builder/amazon/chroot/step_register_ami.go +++ b/builder/amazon/chroot/step_register_ami.go @@ -14,7 +14,7 @@ import ( // StepRegisterAMI creates the AMI. type StepRegisterAMI struct { RootVolumeSize int64 - EnableAMIENASupport bool + EnableAMIENASupport *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) registerOpts.SriovNetSupport = aws.String("simple") } - if s.EnableAMIENASupport { + if s.EnableAMIENASupport != nil && *s.EnableAMIENASupport { // Set EnaSupport to true // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge registerOpts.EnaSupport = aws.Bool(true) diff --git a/builder/amazon/common/ami_config.go b/builder/amazon/common/ami_config.go index 58c6b8827..60844ec63 100644 --- a/builder/amazon/common/ami_config.go +++ b/builder/amazon/common/ami_config.go @@ -19,7 +19,7 @@ type AMIConfig struct { AMIRegions []string `mapstructure:"ami_regions"` AMISkipRegionValidation bool `mapstructure:"skip_region_validation"` AMITags TagMap `mapstructure:"tags"` - AMIENASupport bool `mapstructure:"ena_support"` + AMIENASupport *bool `mapstructure:"ena_support"` AMISriovNetSupport bool `mapstructure:"sriov_support"` AMIForceDeregister bool `mapstructure:"force_deregister"` AMIForceDeleteSnapshot bool `mapstructure:"force_delete_snapshot"` diff --git a/builder/amazon/common/step_modify_ebs_instance.go b/builder/amazon/common/step_modify_ebs_instance.go index 806417548..8e8b830b4 100644 --- a/builder/amazon/common/step_modify_ebs_instance.go +++ b/builder/amazon/common/step_modify_ebs_instance.go @@ -12,7 +12,7 @@ import ( ) type StepModifyEBSBackedInstance struct { - EnableAMIENASupport bool + EnableAMIENASupport *bool EnableAMISriovNetSupport bool } @@ -40,22 +40,24 @@ func (s *StepModifyEBSBackedInstance) Run(_ context.Context, state multistep.Sta // Handle EnaSupport flag. // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge - var prefix string - if s.EnableAMIENASupport { - prefix = "En" - } else { - prefix = "Dis" - } - ui.Say(fmt.Sprintf("%sabling Enhanced Networking (ENA)...", prefix)) - _, err := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{ - 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) - state.Put("error", err) - ui.Error(err.Error()) - return multistep.ActionHalt + if s.EnableAMIENASupport != nil { + var prefix string + if *s.EnableAMIENASupport { + prefix = "En" + } else { + prefix = "Dis" + } + ui.Say(fmt.Sprintf("%sabling Enhanced Networking (ENA)...", prefix)) + _, err := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{ + 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) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } } return multistep.ActionContinue diff --git a/builder/amazon/common/step_source_ami_info.go b/builder/amazon/common/step_source_ami_info.go index cb7a08b51..5cbcb0cc8 100644 --- a/builder/amazon/common/step_source_ami_info.go +++ b/builder/amazon/common/step_source_ami_info.go @@ -20,7 +20,7 @@ import ( type StepSourceAMIInfo struct { SourceAmi string EnableAMISriovNetSupport bool - EnableAMIENASupport bool + EnableAMIENASupport *bool AMIVirtType string 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. // See http://goo.gl/icuXh5 - if s.EnableAMIENASupport || s.EnableAMISriovNetSupport { + if (s.EnableAMIENASupport != nil && *s.EnableAMIENASupport) || s.EnableAMISriovNetSupport { err = s.canEnableEnhancedNetworking(image) if err != nil { state.Put("error", err) diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index 1980a770d..2347de1a8 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -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.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, fmt.Errorf("Spot instances do not support modification, which is required "+ "when either `ena_support` or `sriov_support` are set. Please ensure "+ diff --git a/builder/amazon/ebssurrogate/builder.go b/builder/amazon/ebssurrogate/builder.go index 59537572b..76c5ec75e 100644 --- a/builder/amazon/ebssurrogate/builder.go +++ b/builder/amazon/ebssurrogate/builder.go @@ -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)) } - 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, fmt.Errorf("Spot instances do not support modification, which is required "+ "when either `ena_support` or `sriov_support` are set. Please ensure "+ diff --git a/builder/amazon/ebssurrogate/step_register_ami.go b/builder/amazon/ebssurrogate/step_register_ami.go index 63e0f5581..60b653681 100644 --- a/builder/amazon/ebssurrogate/step_register_ami.go +++ b/builder/amazon/ebssurrogate/step_register_ami.go @@ -16,7 +16,7 @@ type StepRegisterAMI struct { RootDevice RootBlockDevice AMIDevices []*ec2.BlockDeviceMapping LaunchDevices []*ec2.BlockDeviceMapping - EnableAMIENASupport bool + EnableAMIENASupport *bool EnableAMISriovNetSupport bool 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) registerOpts.SriovNetSupport = aws.String("simple") } - if s.EnableAMIENASupport { + if s.EnableAMIENASupport != nil && *s.EnableAMIENASupport { // Set EnaSupport to true // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge registerOpts.EnaSupport = aws.Bool(true) diff --git a/builder/amazon/ebsvolume/builder.go b/builder/amazon/ebsvolume/builder.go index 643b55a2a..a661576e1 100644 --- a/builder/amazon/ebsvolume/builder.go +++ b/builder/amazon/ebsvolume/builder.go @@ -24,7 +24,7 @@ type Config struct { awscommon.RunConfig `mapstructure:",squash"` VolumeMappings []BlockDevice `mapstructure:"ebs_volumes"` - AMIENASupport bool `mapstructure:"ena_support"` + AMIENASupport *bool `mapstructure:"ena_support"` AMISriovNetSupport bool `mapstructure:"sriov_support"` launchBlockDevices awscommon.BlockDevices @@ -70,7 +70,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { 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, fmt.Errorf("Spot instances do not support modification, which is required "+ "when either `ena_support` or `sriov_support` are set. Please ensure "+ diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index 6872f3883..977370138 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -156,7 +156,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { 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, fmt.Errorf("Spot instances do not support modification, which is required "+ "when either `ena_support` or `sriov_support` are set. Please ensure "+ diff --git a/builder/amazon/instance/step_register_ami.go b/builder/amazon/instance/step_register_ami.go index 20df1f0d4..2dfcda02b 100644 --- a/builder/amazon/instance/step_register_ami.go +++ b/builder/amazon/instance/step_register_ami.go @@ -12,7 +12,7 @@ import ( ) type StepRegisterAMI struct { - EnableAMIENASupport bool + EnableAMIENASupport *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) registerOpts.SriovNetSupport = aws.String("simple") } - if s.EnableAMIENASupport { + if s.EnableAMIENASupport != nil && *s.EnableAMIENASupport { // Set EnaSupport to true // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge registerOpts.EnaSupport = aws.Bool(true)