github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/builder/amazon/common/step_modify_ebs_instance.go (about) 1 package common 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/service/ec2" 9 "github.com/hashicorp/packer/helper/multistep" 10 "github.com/hashicorp/packer/packer" 11 ) 12 13 type StepModifyEBSBackedInstance struct { 14 EnableAMIENASupport bool 15 EnableAMISriovNetSupport bool 16 } 17 18 func (s *StepModifyEBSBackedInstance) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { 19 ec2conn := state.Get("ec2").(*ec2.EC2) 20 instance := state.Get("instance").(*ec2.Instance) 21 ui := state.Get("ui").(packer.Ui) 22 23 // Set SriovNetSupport to "simple". See http://goo.gl/icuXh5 24 // As of February 2017, this applies to C3, C4, D2, I2, R3, and M4 (excluding m4.16xlarge) 25 if s.EnableAMISriovNetSupport { 26 ui.Say("Enabling Enhanced Networking (SR-IOV)...") 27 simple := "simple" 28 _, err := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{ 29 InstanceId: instance.InstanceId, 30 SriovNetSupport: &ec2.AttributeValue{Value: &simple}, 31 }) 32 if err != nil { 33 err := fmt.Errorf("Error enabling Enhanced Networking (SR-IOV) on %s: %s", *instance.InstanceId, err) 34 state.Put("error", err) 35 ui.Error(err.Error()) 36 return multistep.ActionHalt 37 } 38 } 39 40 // Set EnaSupport to true. 41 // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge 42 if s.EnableAMIENASupport { 43 ui.Say("Enabling Enhanced Networking (ENA)...") 44 _, err := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{ 45 InstanceId: instance.InstanceId, 46 EnaSupport: &ec2.AttributeBooleanValue{Value: aws.Bool(true)}, 47 }) 48 if err != nil { 49 err := fmt.Errorf("Error enabling Enhanced Networking (ENA) on %s: %s", *instance.InstanceId, err) 50 state.Put("error", err) 51 ui.Error(err.Error()) 52 return multistep.ActionHalt 53 } 54 } 55 56 return multistep.ActionContinue 57 } 58 59 func (s *StepModifyEBSBackedInstance) Cleanup(state multistep.StateBag) { 60 // No cleanup... 61 }