From 628462b919970494962095097d5e92ae1c5e1f6e Mon Sep 17 00:00:00 2001 From: Yo Takezawa Date: Tue, 21 Jul 2015 14:07:30 +0900 Subject: [PATCH] Use snapshot size if you don't specify a VolumeSize --- builder/amazon/common/block_device.go | 6 +++++- builder/amazon/common/block_device_test.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/builder/amazon/common/block_device.go b/builder/amazon/common/block_device.go index fb14a66ae..83b79ac9e 100644 --- a/builder/amazon/common/block_device.go +++ b/builder/amazon/common/block_device.go @@ -32,7 +32,6 @@ func buildBlockDevices(b []BlockDevice) []*ec2.BlockDeviceMapping { for _, blockDevice := range b { ebsBlockDevice := &ec2.EBSBlockDevice{ VolumeType: aws.String(blockDevice.VolumeType), - VolumeSize: aws.Long(blockDevice.VolumeSize), DeleteOnTermination: aws.Boolean(blockDevice.DeleteOnTermination), } @@ -48,6 +47,11 @@ func buildBlockDevices(b []BlockDevice) []*ec2.BlockDeviceMapping { ebsBlockDevice.Encrypted = aws.Boolean(blockDevice.Encrypted) } + // Use snapshot size if you don't specify a VolumeSize + if blockDevice.VolumeSize != 0 { + ebsBlockDevice.VolumeSize = aws.Long(blockDevice.VolumeSize) + } + mapping := &ec2.BlockDeviceMapping{ DeviceName: aws.String(blockDevice.DeviceName), VirtualName: aws.String(blockDevice.VirtualName), diff --git a/builder/amazon/common/block_device_test.go b/builder/amazon/common/block_device_test.go index c69ef2efb..89adbc334 100644 --- a/builder/amazon/common/block_device_test.go +++ b/builder/amazon/common/block_device_test.go @@ -81,6 +81,22 @@ func TestBlockDevice(t *testing.T) { VirtualName: aws.String("ephemeral0"), }, }, + { + Config: &BlockDevice{ + DeviceName: "/dev/sdb", + VolumeType: "standard", + DeleteOnTermination: true, + }, + + Result: &ec2.BlockDeviceMapping{ + DeviceName: aws.String("/dev/sdb"), + VirtualName: aws.String(""), + EBS: &ec2.EBSBlockDevice{ + VolumeType: aws.String("standard"), + DeleteOnTermination: aws.Boolean(true), + }, + }, + }, } for _, tc := range cases {