diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index ed0cefe53..008355330 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -35,6 +35,7 @@ type StepRunSourceInstance struct { UserData string UserDataFile string VolumeTags TagMap + NoEphemeral bool instanceId string } @@ -116,6 +117,26 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa EbsOptimized: &s.EbsOptimized, } + if s.NoEphemeral { + // This is only relevant for windows guests. Ephemeral drives by + // default are assigned to drive names xvdca-xvdcz. + // When vms are launched from the AWS console, they're automatically + // removed from the block devices if the user hasn't said to use them, + // but the SDK does not perform this cleanup. The following code just + // manually removes the ephemeral drives from the mapping so that they + // don't clutter up console views and cause confusion. + log.Printf("no_ephemeral was set, so creating drives xvdca-xvdcz as empty mappings") + DefaultEphemeralDeviceLetters := "abcdefghijklmnopqrstuvwxyz" + for i := 0; i < len(DefaultEphemeralDeviceLetters); i++ { + + bd := &ec2.BlockDeviceMapping{ + DeviceName: aws.String("xvdc" + string(DefaultEphemeralDeviceLetters[i])), + NoDevice: aws.String(""), + } + runOpts.BlockDeviceMappings = append(runOpts.BlockDeviceMappings, bd) + } + } + if s.EnableT2Unlimited { creditOption := "unlimited" runOpts.CreditSpecification = &ec2.CreditSpecificationRequest{CpuCredits: &creditOption} diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index ab9f8a0e2..075ad4621 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -53,6 +53,12 @@ type Config struct { // engine](/docs/templates/engine.html), see [Build template // data](#build-template-data) for more information. VolumeRunTags awscommon.TagMap `mapstructure:"run_volume_tags"` + // If you set this flag, we'll add clauses to the + // launch_block_device_mappings that make sure ephemeral drives don't show + // up in the EC2 console. If you launched from the EC2 console, you'd get + // this automatically, but the SDK does not provide this service. + // This only applies when you are not running spot instances. + NoEphemeral bool `mapstructure:"no_ephemeral" required:"false"` ctx interpolate.Context } @@ -181,6 +187,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack UserData: b.config.UserData, UserDataFile: b.config.UserDataFile, VolumeTags: b.config.VolumeRunTags, + NoEphemeral: b.config.NoEphemeral, } }