2016-10-31 16:44:41 -05:00
|
|
|
package common
|
2014-06-04 14:58:11 -07:00
|
|
|
|
|
|
|
|
import (
|
2018-01-22 15:32:33 -08:00
|
|
|
"context"
|
2014-06-04 14:58:11 -07:00
|
|
|
"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"
|
2018-01-19 16:18:44 -08:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 13:39:01 -07:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2014-06-04 14:58:11 -07:00
|
|
|
)
|
|
|
|
|
|
2016-10-31 16:44:41 -05:00
|
|
|
type StepModifyEBSBackedInstance struct {
|
2017-08-28 09:18:23 -07:00
|
|
|
EnableAMIENASupport bool
|
|
|
|
|
EnableAMISriovNetSupport bool
|
2016-10-31 16:44:41 -05:00
|
|
|
}
|
2014-06-04 14:58:11 -07:00
|
|
|
|
2018-01-22 15:31:41 -08:00
|
|
|
func (s *StepModifyEBSBackedInstance) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2014-06-04 14:58:11 -07:00
|
|
|
ec2conn := state.Get("ec2").(*ec2.EC2)
|
|
|
|
|
instance := state.Get("instance").(*ec2.Instance)
|
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
2017-08-25 09:14:12 -07:00
|
|
|
// 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)
|
2017-08-28 09:18:23 -07:00
|
|
|
if s.EnableAMISriovNetSupport {
|
2017-02-21 17:46:16 -08:00
|
|
|
ui.Say("Enabling Enhanced Networking (SR-IOV)...")
|
2015-04-05 17:58:48 -04:00
|
|
|
simple := "simple"
|
2017-02-26 19:33:34 -08:00
|
|
|
_, err := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
|
2015-08-17 17:44:01 -07:00
|
|
|
InstanceId: instance.InstanceId,
|
|
|
|
|
SriovNetSupport: &ec2.AttributeValue{Value: &simple},
|
2015-04-05 17:58:48 -04:00
|
|
|
})
|
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)
|
2017-02-21 17:46:16 -08:00
|
|
|
state.Put("error", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
2017-08-25 09:14:12 -07:00
|
|
|
}
|
2017-02-21 17:46:16 -08:00
|
|
|
|
2017-08-25 09:14:12 -07:00
|
|
|
// Set EnaSupport to true.
|
|
|
|
|
// As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge
|
2017-08-28 09:18:23 -07:00
|
|
|
if s.EnableAMIENASupport {
|
2017-02-21 17:46:16 -08:00
|
|
|
ui.Say("Enabling Enhanced Networking (ENA)...")
|
2017-08-25 09:14:12 -07:00
|
|
|
_, err := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
|
2017-02-21 17:46:16 -08:00
|
|
|
InstanceId: instance.InstanceId,
|
2017-02-26 19:33:34 -08:00
|
|
|
EnaSupport: &ec2.AttributeBooleanValue{Value: aws.Bool(true)},
|
2017-02-21 17:46:16 -08:00
|
|
|
})
|
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)
|
2014-06-04 14:58:11 -07:00
|
|
|
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) {
|
2014-06-04 14:58:11 -07:00
|
|
|
// No cleanup...
|
|
|
|
|
}
|