Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions builder/common/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ type RunConfig struct {
// Optimized](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSOptimized.html).
// Default `false`.
EbsOptimized bool `mapstructure:"ebs_optimized" required:"false"`
// Enable nested virtualization for the launched instance.
// Note: this option is not supported by builders using the legacy AWS SDK v1 (this package).
// See [Nested Virtualization](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/amazon-ec2-nested-virtualization.html) for details.
EnableNestedVirtualization bool `mapstructure:"enable_nested_virtualization" required:"false"`
// Enable support for Nitro Enclaves on the instance. Note that the instance type must
// be able to [support Nitro Enclaves](https://aws.amazon.com/ec2/nitro/nitro-enclaves/faqs/).
// This option is not supported for spot instances.
Expand Down
9 changes: 9 additions & 0 deletions builder/common/run_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,15 @@ func TestRunConfigPrepare_EnableNitroEnclaveGood(t *testing.T) {
}
}

func TestRunConfigPrepare_EnableNestedVirtualization(t *testing.T) {
c := testConfig()
c.EnableNestedVirtualization = true
err := c.Prepare(nil)
if len(err) != 0 {
t.Fatalf("Should not error when enable_nested_virtualization is set: %v", err)
}
}

func TestRunConfigPrepare_FailIfBothHostIDAndGroupSpecified(t *testing.T) {
c := testConfig()
c.Placement.HostId = "host"
Expand Down
6 changes: 6 additions & 0 deletions builder/common/step_run_source_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type StepRunSourceInstance struct {
VolumeTags map[string]string
NoEphemeral bool
EnableNitroEnclave bool
EnableNestedVirtualization bool
IsBurstableInstanceType bool

instanceId string
Expand Down Expand Up @@ -123,6 +124,11 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa
Enabled: &s.EnableNitroEnclave,
}

if s.EnableNestedVirtualization {
log.Println("Warning: EnableNestedVirtualization is not supported with the legacy AWS SDK v1. " +
"Use the ebs, ebssurrogate, or ebs-volume builders which use the AWS SDK v2.")
}

az := state.Get("availability_zone").(string)
runOpts := &ec2.RunInstancesInput{
ImageId: &s.SourceAMI,
Expand Down
6 changes: 6 additions & 0 deletions builder/common/step_run_spot_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type StepRunSpotInstance struct {
NoEphemeral bool
IsBurstableInstanceType bool
EnableUnlimitedCredits bool
EnableNestedVirtualization bool

instanceId string
}
Expand Down Expand Up @@ -168,6 +169,11 @@ func (s *StepRunSpotInstance) CreateTemplateData(userData *string, az string,
templateData.CreditSpecification = &ec2.CreditSpecificationRequest{CpuCredits: aws.String(CPUCreditsUnlimited)}
}

if s.EnableNestedVirtualization {
log.Println("Warning: EnableNestedVirtualization is not supported with the legacy AWS SDK v1. " +
"Use the ebs, ebssurrogate, or ebs-volume builders which use the AWS SDK v2.")
}

if s.HttpEndpoint == "enabled" {
templateData.MetadataOptions = &ec2.LaunchTemplateInstanceMetadataOptionsRequest{
HttpEndpoint: &s.HttpEndpoint,
Expand Down
7 changes: 7 additions & 0 deletions builder/common/step_run_spot_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,16 @@ func getBasicStep() *StepRunSpotInstance {
func TestCreateTemplateData(t *testing.T) {
state := tStateSpot()
stepRunSpotInstance := getBasicStep()
stepRunSpotInstance.EnableNestedVirtualization = true
template := stepRunSpotInstance.CreateTemplateData(aws.String("userdata"), "az", state,
&ec2.LaunchTemplateInstanceMarketOptionsRequest{})

// EnableNestedVirtualization is not supported with the legacy AWS SDK v1,
// so CpuOptions should not be set in this code path.
if template.CpuOptions != nil {
t.Fatalf("Template should not set CpuOptions with the legacy AWS SDK v1, received %#v", template.CpuOptions)
}

// expected := []*ec2.LaunchTemplateInstanceNetworkInterfaceSpecificationRequest{
// &ec2.LaunchTemplateInstanceNetworkInterfaceSpecificationRequest{
// DeleteOnTermination: aws.Bool(true),
Expand Down
2 changes: 2 additions & 0 deletions builder/ebs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
Comm: &b.config.RunConfig.Comm,
Debug: b.config.PackerDebug,
EbsOptimized: b.config.EbsOptimized,
EnableNestedVirtualization: b.config.EnableNestedVirtualization,
IsBurstableInstanceType: b.config.RunConfig.IsBurstableInstanceType(),
EnableUnlimitedCredits: b.config.EnableUnlimitedCredits,
ExpectedRootDevice: "ebs",
Expand Down Expand Up @@ -275,6 +276,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
Ctx: b.config.ctx,
Debug: b.config.PackerDebug,
EbsOptimized: b.config.EbsOptimized,
EnableNestedVirtualization: b.config.EnableNestedVirtualization,
EnableNitroEnclave: b.config.EnableNitroEnclave,
IsBurstableInstanceType: b.config.RunConfig.IsBurstableInstanceType(),
EnableUnlimitedCredits: b.config.EnableUnlimitedCredits,
Expand Down
2 changes: 2 additions & 0 deletions builder/ebs/builder.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions builder/ebssurrogate/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
Comm: &b.config.RunConfig.Comm,
Debug: b.config.PackerDebug,
EbsOptimized: b.config.EbsOptimized,
EnableNestedVirtualization: b.config.EnableNestedVirtualization,
IsBurstableInstanceType: b.config.RunConfig.IsBurstableInstanceType(),
EnableUnlimitedCredits: b.config.EnableUnlimitedCredits,
ExpectedRootDevice: "ebs",
Expand Down Expand Up @@ -312,6 +313,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
Ctx: b.config.ctx,
Debug: b.config.PackerDebug,
EbsOptimized: b.config.EbsOptimized,
EnableNestedVirtualization: b.config.EnableNestedVirtualization,
EnableNitroEnclave: b.config.EnableNitroEnclave,
IsBurstableInstanceType: b.config.IsBurstableInstanceType(),
EnableUnlimitedCredits: b.config.EnableUnlimitedCredits,
Expand Down
2 changes: 2 additions & 0 deletions builder/ebssurrogate/builder.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions builder/ebsvolume/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
Ctx: b.config.ctx,
Debug: b.config.PackerDebug,
EbsOptimized: b.config.EbsOptimized,
EnableNestedVirtualization: b.config.EnableNestedVirtualization,
ExpectedRootDevice: "ebs",
IsBurstableInstanceType: b.config.RunConfig.IsBurstableInstanceType(),
EnableUnlimitedCredits: b.config.EnableUnlimitedCredits,
Expand Down Expand Up @@ -258,6 +259,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
Ctx: b.config.ctx,
Debug: b.config.PackerDebug,
EbsOptimized: b.config.EbsOptimized,
EnableNestedVirtualization: b.config.EnableNestedVirtualization,
EnableNitroEnclave: b.config.EnableNitroEnclave,
IsBurstableInstanceType: b.config.RunConfig.IsBurstableInstanceType(),
EnableUnlimitedCredits: b.config.EnableUnlimitedCredits,
Expand Down
2 changes: 2 additions & 0 deletions builder/ebsvolume/builder.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 23 additions & 21 deletions builder/instance/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,27 +278,28 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)

if b.config.IsSpotInstance() {
instanceStep = &awscommon.StepRunSpotInstance{
PollingConfig: b.config.PollingConfig,
AssociatePublicIpAddress: b.config.AssociatePublicIpAddress,
LaunchMappings: b.config.LaunchMappings,
BlockDurationMinutes: b.config.BlockDurationMinutes,
Ctx: b.config.ctx,
Comm: &b.config.RunConfig.Comm,
Debug: b.config.PackerDebug,
EbsOptimized: b.config.EbsOptimized,
IsBurstableInstanceType: b.config.RunConfig.IsBurstableInstanceType(),
EnableUnlimitedCredits: b.config.EnableUnlimitedCredits,
InstanceType: b.config.InstanceType,
FleetTags: b.config.FleetTags,
Region: *ec2conn.Config.Region,
SourceAMI: b.config.SourceAmi,
SpotPrice: b.config.SpotPrice,
SpotInstanceTypes: b.config.SpotInstanceTypes,
SpotAllocationStrategy: b.config.SpotAllocationStrategy,
Tags: b.config.RunTags,
SpotTags: b.config.SpotTags,
UserData: b.config.UserData,
UserDataFile: b.config.UserDataFile,
PollingConfig: b.config.PollingConfig,
AssociatePublicIpAddress: b.config.AssociatePublicIpAddress,
LaunchMappings: b.config.LaunchMappings,
BlockDurationMinutes: b.config.BlockDurationMinutes,
Ctx: b.config.ctx,
Comm: &b.config.RunConfig.Comm,
Debug: b.config.PackerDebug,
EbsOptimized: b.config.EbsOptimized,
EnableNestedVirtualization: b.config.EnableNestedVirtualization,
IsBurstableInstanceType: b.config.RunConfig.IsBurstableInstanceType(),
EnableUnlimitedCredits: b.config.EnableUnlimitedCredits,
InstanceType: b.config.InstanceType,
FleetTags: b.config.FleetTags,
Region: *ec2conn.Config.Region,
SourceAMI: b.config.SourceAmi,
SpotPrice: b.config.SpotPrice,
SpotInstanceTypes: b.config.SpotInstanceTypes,
SpotAllocationStrategy: b.config.SpotAllocationStrategy,
Tags: b.config.RunTags,
SpotTags: b.config.SpotTags,
UserData: b.config.UserData,
UserDataFile: b.config.UserDataFile,
}
} else {
var tenancy string
Expand All @@ -322,6 +323,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
Ctx: b.config.ctx,
Debug: b.config.PackerDebug,
EbsOptimized: b.config.EbsOptimized,
EnableNestedVirtualization: b.config.EnableNestedVirtualization,
EnableNitroEnclave: b.config.EnableNitroEnclave,
IsBurstableInstanceType: b.config.RunConfig.IsBurstableInstanceType(),
EnableUnlimitedCredits: b.config.EnableUnlimitedCredits,
Expand Down
2 changes: 2 additions & 0 deletions builder/instance/builder.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading