forcibly prevent ephemeral drives from being created in the amazon-ebs builder, when no_ephemeral is set
This commit is contained in:
parent
ef87cace9f
commit
0e2bdc8be6
|
@ -35,6 +35,7 @@ type StepRunSourceInstance struct {
|
||||||
UserData string
|
UserData string
|
||||||
UserDataFile string
|
UserDataFile string
|
||||||
VolumeTags TagMap
|
VolumeTags TagMap
|
||||||
|
NoEphemeral bool
|
||||||
|
|
||||||
instanceId string
|
instanceId string
|
||||||
}
|
}
|
||||||
|
@ -116,6 +117,26 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa
|
||||||
EbsOptimized: &s.EbsOptimized,
|
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 {
|
if s.EnableT2Unlimited {
|
||||||
creditOption := "unlimited"
|
creditOption := "unlimited"
|
||||||
runOpts.CreditSpecification = &ec2.CreditSpecificationRequest{CpuCredits: &creditOption}
|
runOpts.CreditSpecification = &ec2.CreditSpecificationRequest{CpuCredits: &creditOption}
|
||||||
|
|
|
@ -53,6 +53,12 @@ type Config struct {
|
||||||
// engine](/docs/templates/engine.html), see [Build template
|
// engine](/docs/templates/engine.html), see [Build template
|
||||||
// data](#build-template-data) for more information.
|
// data](#build-template-data) for more information.
|
||||||
VolumeRunTags awscommon.TagMap `mapstructure:"run_volume_tags"`
|
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
|
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,
|
UserData: b.config.UserData,
|
||||||
UserDataFile: b.config.UserDataFile,
|
UserDataFile: b.config.UserDataFile,
|
||||||
VolumeTags: b.config.VolumeRunTags,
|
VolumeTags: b.config.VolumeRunTags,
|
||||||
|
NoEphemeral: b.config.NoEphemeral,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue