diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index a5ac070d4..c5449a60a 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -34,6 +34,7 @@ type Config struct { DevicePath string `mapstructure:"device_path"` MountPath string `mapstructure:"mount_path"` SourceAmi string `mapstructure:"source_ami"` + RootVolumeSize int64 `mapstructure:"root_volume_size"` ctx interpolate.Context } @@ -159,7 +160,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &StepCheckRootDevice{}, &StepFlock{}, &StepPrepareDevice{}, - &StepCreateVolume{}, + &StepCreateVolume{ + RootVolumeSize: b.config.RootVolumeSize, + }, &StepAttachVolume{}, &StepEarlyUnflock{}, &StepMountDevice{}, @@ -172,7 +175,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ForceDeregister: b.config.AMIForceDeregister, AMIName: b.config.AMIName, }, - &StepRegisterAMI{}, + &StepRegisterAMI{ + RootVolumeSize: b.config.RootVolumeSize, + }, &awscommon.StepAMIRegionCopy{ AccessConfig: &b.config.AccessConfig, Regions: b.config.AMIRegions, diff --git a/builder/amazon/chroot/step_create_volume.go b/builder/amazon/chroot/step_create_volume.go index 81486f5e2..40925483a 100644 --- a/builder/amazon/chroot/step_create_volume.go +++ b/builder/amazon/chroot/step_create_volume.go @@ -4,6 +4,8 @@ import ( "fmt" "log" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awsutil" "github.com/aws/aws-sdk-go/service/ec2" "github.com/mitchellh/multistep" awscommon "github.com/mitchellh/packer/builder/amazon/common" @@ -16,7 +18,8 @@ import ( // Produces: // volume_id string - The ID of the created volume type StepCreateVolume struct { - volumeId string + volumeId string + RootVolumeSize int64 } func (s *StepCreateVolume) Run(state multistep.StateBag) multistep.StepAction { @@ -43,14 +46,18 @@ func (s *StepCreateVolume) Run(state multistep.StateBag) multistep.StepAction { } ui.Say("Creating the root volume...") + vs := *rootDevice.EBS.VolumeSize + if s.RootVolumeSize > *rootDevice.EBS.VolumeSize { + vs = s.RootVolumeSize + } createVolume := &ec2.CreateVolumeInput{ AvailabilityZone: instance.Placement.AvailabilityZone, - Size: rootDevice.EBS.VolumeSize, + Size: aws.Long(vs), SnapshotID: rootDevice.EBS.SnapshotID, VolumeType: rootDevice.EBS.VolumeType, IOPS: rootDevice.EBS.IOPS, } - log.Printf("Create args: %#v", createVolume) + log.Printf("Create args: %s", awsutil.StringValue(createVolume)) createVolumeResp, err := ec2conn.CreateVolume(createVolume) if err != nil { diff --git a/builder/amazon/chroot/step_register_ami.go b/builder/amazon/chroot/step_register_ami.go index 09df1e13d..5314ef0a1 100644 --- a/builder/amazon/chroot/step_register_ami.go +++ b/builder/amazon/chroot/step_register_ami.go @@ -11,7 +11,9 @@ import ( ) // StepRegisterAMI creates the AMI. -type StepRegisterAMI struct{} +type StepRegisterAMI struct { + RootVolumeSize int64 +} func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction { config := state.Get("config").(*Config) @@ -30,6 +32,10 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction { } else { newDevice.EBS = &ec2.EBSBlockDevice{SnapshotID: aws.String(snapshotId)} } + + if s.RootVolumeSize > *newDevice.EBS.VolumeSize { + newDevice.EBS.VolumeSize = aws.Long(s.RootVolumeSize) + } } // assume working from a snapshot, so we unset the Encrypted field if set,