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 fe3b0949c..4c8c7567b 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 c2c454e06..8e8b830b4 100644 --- a/builder/amazon/common/step_modify_ebs_instance.go +++ b/builder/amazon/common/step_modify_ebs_instance.go @@ -3,6 +3,7 @@ package common import ( "context" "fmt" + "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -11,7 +12,7 @@ import ( ) type StepModifyEBSBackedInstance struct { - EnableAMIENASupport bool + EnableAMIENASupport *bool EnableAMISriovNetSupport bool } @@ -37,16 +38,22 @@ func (s *StepModifyEBSBackedInstance) Run(_ context.Context, state multistep.Sta } } - // Set EnaSupport to true. + // Handle EnaSupport flag. // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge - if s.EnableAMIENASupport { - ui.Say("Enabling Enhanced Networking (ENA)...") + 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(true)}, + EnaSupport: &ec2.AttributeBooleanValue{Value: aws.Bool(*s.EnableAMIENASupport)}, }) if err != nil { - err := fmt.Errorf("Error enabling Enhanced Networking (ENA) on %s: %s", *instance.InstanceId, err) + 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 diff --git a/builder/amazon/common/step_source_ami_info.go b/builder/amazon/common/step_source_ami_info.go index 0486e6d45..8ebeb580b 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 } @@ -94,7 +94,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 7557abc8d..3e1580430 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 755d79139..bd88416d2 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 0cc7f0754..445aff34c 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 68d06d7b2..be1b28cb9 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) diff --git a/website/source/docs/builders/amazon-chroot.html.md b/website/source/docs/builders/amazon-chroot.html.md index 9bd5be7b1..bc179b861 100644 --- a/website/source/docs/builders/amazon-chroot.html.md +++ b/website/source/docs/builders/amazon-chroot.html.md @@ -131,9 +131,11 @@ each category, the available configuration keys are alphabetized. forces Packer to find an open device automatically. - `ena_support` (boolean) - Enable enhanced networking (ENA but not SriovNetSupport) - on HVM-compatible AMIs. If true, add `ec2:ModifyInstanceAttribute` to your AWS IAM policy. - Note: you must make sure enhanced networking is enabled on your instance. See [Amazon's - documentation on enabling enhanced networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking). Default `false`. + on HVM-compatible AMIs. If set, add `ec2:ModifyInstanceAttribute` to your AWS IAM policy. + If false, this will disable enhanced networking in the final AMI as opposed to passing + the setting through unchanged from the source. Note: you must make sure enhanced + networking is enabled on your instance. See [Amazon's documentation on enabling enhanced + networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking). - `force_deregister` (boolean) - Force Packer to first deregister an existing AMI if one with the same name already exists. Default `false`. diff --git a/website/source/docs/builders/amazon-ebs.html.md b/website/source/docs/builders/amazon-ebs.html.md index 13d95865d..2d3d5fccd 100644 --- a/website/source/docs/builders/amazon-ebs.html.md +++ b/website/source/docs/builders/amazon-ebs.html.md @@ -183,9 +183,11 @@ builder. Default `false`. - `ena_support` (boolean) - Enable enhanced networking (ENA but not SriovNetSupport) - on HVM-compatible AMIs. If true, add `ec2:ModifyInstanceAttribute` to your AWS IAM policy. - Note: you must make sure enhanced networking is enabled on your instance. See [Amazon's - documentation on enabling enhanced networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking). Default `false`. + on HVM-compatible AMIs. If set, add `ec2:ModifyInstanceAttribute` to your AWS IAM policy. + If false, this will disable enhanced networking in the final AMI as opposed to passing + the setting through unchanged from the source. Note: you must make sure enhanced + networking is enabled on your instance. See [Amazon's documentation on enabling enhanced + networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking). - `enable_t2_unlimited` (boolean) - Enabling T2 Unlimited allows the source instance to burst additional CPU beyond its available [CPU Credits] diff --git a/website/source/docs/builders/amazon-ebssurrogate.html.md b/website/source/docs/builders/amazon-ebssurrogate.html.md index c3ec73da8..9bf5c9038 100644 --- a/website/source/docs/builders/amazon-ebssurrogate.html.md +++ b/website/source/docs/builders/amazon-ebssurrogate.html.md @@ -176,9 +176,11 @@ builder. Default `false`. - `ena_support` (boolean) - Enable enhanced networking (ENA but not SriovNetSupport) - on HVM-compatible AMIs. If true, add `ec2:ModifyInstanceAttribute` to your AWS IAM policy. - Note: you must make sure enhanced networking is enabled on your instance. See [Amazon's - documentation on enabling enhanced networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking). Default `false`. + on HVM-compatible AMIs. If set, add `ec2:ModifyInstanceAttribute` to your AWS IAM policy. + If false, this will disable enhanced networking in the final AMI as opposed to passing + the setting through unchanged from the source. Note: you must make sure enhanced + networking is enabled on your instance. See [Amazon's documentation on enabling enhanced + networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking). - `enable_t2_unlimited` (boolean) - Enabling T2 Unlimited allows the source instance to burst additional CPU beyond its available [CPU Credits] diff --git a/website/source/docs/builders/amazon-ebsvolume.html.md b/website/source/docs/builders/amazon-ebsvolume.html.md index 4042f1ab6..1d27555b9 100644 --- a/website/source/docs/builders/amazon-ebsvolume.html.md +++ b/website/source/docs/builders/amazon-ebsvolume.html.md @@ -148,9 +148,11 @@ builder. Default `false`. - `ena_support` (boolean) - Enable enhanced networking (ENA but not SriovNetSupport) - on HVM-compatible AMIs. If true, add `ec2:ModifyInstanceAttribute` to your AWS IAM policy. - Note: you must make sure enhanced networking is enabled on your instance. See [Amazon's - documentation on enabling enhanced networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking). Default `false`. + on HVM-compatible AMIs. If set, add `ec2:ModifyInstanceAttribute` to your AWS IAM policy. + If false, this will disable enhanced networking in the final AMI as opposed to passing + the setting through unchanged from the source. Note: you must make sure enhanced + networking is enabled on your instance. See [Amazon's documentation on enabling enhanced + networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking). - `enable_t2_unlimited` (boolean) - Enabling T2 Unlimited allows the source instance to burst additional CPU beyond its available [CPU Credits] diff --git a/website/source/docs/builders/amazon-instance.html.md b/website/source/docs/builders/amazon-instance.html.md index 136af3cb9..868097c11 100644 --- a/website/source/docs/builders/amazon-instance.html.md +++ b/website/source/docs/builders/amazon-instance.html.md @@ -200,9 +200,11 @@ builder. Default `false`. - `ena_support` (boolean) - Enable enhanced networking (ENA but not SriovNetSupport) - on HVM-compatible AMIs. If true, add `ec2:ModifyInstanceAttribute` to your AWS IAM policy. - Note: you must make sure enhanced networking is enabled on your instance. See [Amazon's - documentation on enabling enhanced networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking). Default `false`. + on HVM-compatible AMIs. If set, add `ec2:ModifyInstanceAttribute` to your AWS IAM policy. + If false, this will disable enhanced networking in the final AMI as opposed to passing + the setting through unchanged from the source. Note: you must make sure enhanced + networking is enabled on your instance. See [Amazon's documentation on enabling enhanced + networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking). - `enable_t2_unlimited` (boolean) - Enabling T2 Unlimited allows the source instance to burst additional CPU beyond its available [CPU Credits]