Files
Packer-Cn/builder/amazon/common/step_modify_ebs_instance.go
T

58 lines
1.8 KiB
Go
Raw Normal View History

2016-10-31 16:44:41 -05:00
package common
import (
"fmt"
2017-02-26 19:33:34 -08:00
"github.com/aws/aws-sdk-go/aws"
2015-06-03 17:13:52 -04:00
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
2016-10-31 16:44:41 -05:00
type StepModifyEBSBackedInstance struct {
EnableEnhancedNetworking bool
}
2016-10-31 16:44:41 -05:00
func (s *StepModifyEBSBackedInstance) Run(state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(*ec2.EC2)
instance := state.Get("instance").(*ec2.Instance)
ui := state.Get("ui").(packer.Ui)
2016-10-31 16:44:41 -05:00
if s.EnableEnhancedNetworking {
// 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)
ui.Say("Enabling Enhanced Networking (SR-IOV)...")
simple := "simple"
2017-02-26 19:33:34 -08:00
_, err := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
InstanceId: instance.InstanceId,
SriovNetSupport: &ec2.AttributeValue{Value: &simple},
})
2017-02-26 19:33:34 -08:00
if err != nil {
err := fmt.Errorf("Error enabling Enhanced Networking (SR-IOV) on %s: %s", *instance.InstanceId, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
// Set EnaSupport to true.
// As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge
ui.Say("Enabling Enhanced Networking (ENA)...")
2017-02-26 19:33:34 -08:00
_, err = ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
InstanceId: instance.InstanceId,
2017-02-26 19:33:34 -08:00
EnaSupport: &ec2.AttributeBooleanValue{Value: aws.Bool(true)},
})
2017-02-26 19:33:34 -08:00
if err != nil {
err := fmt.Errorf("Error enabling Enhanced Networking (ENA) on %s: %s", *instance.InstanceId, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
}
return multistep.ActionContinue
}
2016-10-31 16:44:41 -05:00
func (s *StepModifyEBSBackedInstance) Cleanup(state multistep.StateBag) {
// No cleanup...
}