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
14 changes: 10 additions & 4 deletions builder/common/step_modify_ebs_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@ type StepModifyEBSBackedInstance struct {
Skip bool
EnableAMIENASupport config.Trilean
EnableAMISriovNetSupport bool
AMISkipCreateImage bool
}

func (s *StepModifyEBSBackedInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(ec2iface.EC2API)
instance := state.Get("instance").(*ec2.Instance)
ui := state.Get("ui").(packersdk.Ui)

// Skip when it is a spot instance
if s.Skip {
return multistep.ActionContinue
}

ui := state.Get("ui").(packersdk.Ui)
if s.AMISkipCreateImage {
ui.Say("skip_create_ami was set; skipping source instance attribute modification")
return multistep.ActionContinue
}

ec2conn := state.Get("ec2").(ec2iface.EC2API)
instance := state.Get("instance").(*ec2.Instance)

// 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)
if s.EnableAMISriovNetSupport {
Expand Down
34 changes: 34 additions & 0 deletions builder/common/step_modify_ebs_instance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright IBM Corp. 2013, 2026
// SPDX-License-Identifier: MPL-2.0

package common

import (
"context"
"testing"

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/config"
)

func TestStepModifyEBSBackedInstance_SkipCreateAMISkipsModification(t *testing.T) {
state := new(multistep.BasicStateBag)
state.Put("ui", packersdk.TestUi(t))

step := &StepModifyEBSBackedInstance{
AMISkipCreateImage: true,
EnableAMISriovNetSupport: true,
EnableAMIENASupport: config.TriTrue,
}

action := step.Run(context.Background(), state)

if action != multistep.ActionContinue {
t.Fatalf("expected ActionContinue, got %v", action)
}

if rawErr, ok := state.GetOk("error"); ok {
t.Fatalf("expected no error, got %v", rawErr)
}
}
11 changes: 9 additions & 2 deletions builder/common/step_stop_ebs_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@ type StepStopEBSBackedInstance struct {
PollingConfig *AWSPollingConfig
Skip bool
DisableStopInstance bool
AMISkipCreateImage bool
}

func (s *StepStopEBSBackedInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(*ec2.EC2)
instance := state.Get("instance").(*ec2.Instance)
ui := state.Get("ui").(packersdk.Ui)

// Skip when it is a spot instance
if s.Skip {
return multistep.ActionContinue
}

if s.AMISkipCreateImage {
ui.Say("skip_create_ami was set; skipping source instance stop")
return multistep.ActionContinue
}

ec2conn := state.Get("ec2").(*ec2.EC2)
instance := state.Get("instance").(*ec2.Instance)

var err error

if !s.DisableStopInstance {
Expand Down
31 changes: 31 additions & 0 deletions builder/common/step_stop_ebs_instance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright IBM Corp. 2013, 2026
// SPDX-License-Identifier: MPL-2.0

package common

import (
"context"
"testing"

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
)

func TestStepStopEBSBackedInstance_SkipCreateAMISkipsStop(t *testing.T) {
state := new(multistep.BasicStateBag)
state.Put("ui", packersdk.TestUi(t))

step := &StepStopEBSBackedInstance{
AMISkipCreateImage: true,
}

action := step.Run(context.Background(), state)

if action != multistep.ActionContinue {
t.Fatalf("expected ActionContinue, got %v", action)
}

if rawErr, ok := state.GetOk("error"); ok {
t.Fatalf("expected no error, got %v", rawErr)
}
}
2 changes: 2 additions & 0 deletions builder/ebs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,12 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
PollingConfig: b.config.PollingConfig,
Skip: b.config.IsSpotInstance(),
DisableStopInstance: b.config.DisableStopInstance,
AMISkipCreateImage: b.config.AMISkipCreateImage,
},
&awscommon.StepModifyEBSBackedInstance{
EnableAMISriovNetSupport: b.config.AMISriovNetSupport,
EnableAMIENASupport: b.config.AMIENASupport,
AMISkipCreateImage: b.config.AMISkipCreateImage,
},
&awscommon.StepDeregisterAMI{
AccessConfig: &b.config.AccessConfig,
Expand Down
14 changes: 10 additions & 4 deletions common/step_modify_ebs_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ type StepModifyEBSBackedInstance struct {
Skip bool
EnableAMIENASupport config.Trilean
EnableAMISriovNetSupport bool
AMISkipCreateImage bool
}

func (s *StepModifyEBSBackedInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2Client := state.Get("ec2v2").(clients.Ec2Client)
instance := state.Get("instance").(ec2types.Instance)
ui := state.Get("ui").(packersdk.Ui)

// Skip when it is a spot instance
if s.Skip {
return multistep.ActionContinue
}

ui := state.Get("ui").(packersdk.Ui)
if s.AMISkipCreateImage {
ui.Say("skip_create_ami was set; skipping source instance attribute modification")
return multistep.ActionContinue
}

ec2Client := state.Get("ec2v2").(clients.Ec2Client)
instance := state.Get("instance").(ec2types.Instance)

// 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)
if s.EnableAMISriovNetSupport {
Expand Down
34 changes: 34 additions & 0 deletions common/step_modify_ebs_instance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright IBM Corp. 2013, 2026
// SPDX-License-Identifier: MPL-2.0

package common

import (
"context"
"testing"

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/config"
)

func TestStepModifyEBSBackedInstance_SkipCreateAMISkipsModification(t *testing.T) {
state := new(multistep.BasicStateBag)
state.Put("ui", packersdk.TestUi(t))

step := &StepModifyEBSBackedInstance{
AMISkipCreateImage: true,
EnableAMISriovNetSupport: true,
EnableAMIENASupport: config.TriTrue,
}

action := step.Run(context.Background(), state)

if action != multistep.ActionContinue {
t.Fatalf("expected ActionContinue, got %v", action)
}

if rawErr, ok := state.GetOk("error"); ok {
t.Fatalf("expected no error, got %v", rawErr)
}
}
11 changes: 9 additions & 2 deletions common/step_stop_ebs_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@ type StepStopEBSBackedInstance struct {
PollingConfig *AWSPollingConfig
Skip bool
DisableStopInstance bool
AMISkipCreateImage bool
}

func (s *StepStopEBSBackedInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2Client := state.Get("ec2v2").(clients.Ec2Client)
instance := state.Get("instance").(ec2types.Instance)
ui := state.Get("ui").(packersdk.Ui)

// Skip when it is a spot instance
if s.Skip {
return multistep.ActionContinue
}

if s.AMISkipCreateImage {
ui.Say("skip_create_ami was set; skipping source instance stop")
return multistep.ActionContinue
}

ec2Client := state.Get("ec2v2").(clients.Ec2Client)
instance := state.Get("instance").(ec2types.Instance)

var err error

if !s.DisableStopInstance {
Expand Down
31 changes: 31 additions & 0 deletions common/step_stop_ebs_instance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright IBM Corp. 2013, 2026
// SPDX-License-Identifier: MPL-2.0

package common

import (
"context"
"testing"

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
)

func TestStepStopEBSBackedInstance_SkipCreateAMISkipsStop(t *testing.T) {
state := new(multistep.BasicStateBag)
state.Put("ui", packersdk.TestUi(t))

step := &StepStopEBSBackedInstance{
AMISkipCreateImage: true,
}

action := step.Run(context.Background(), state)

if action != multistep.ActionContinue {
t.Fatalf("expected ActionContinue, got %v", action)
}

if rawErr, ok := state.GetOk("error"); ok {
t.Fatalf("expected no error, got %v", rawErr)
}
}