Use snapshot size if you don't specify a VolumeSize

This commit is contained in:
Yo Takezawa 2015-07-21 14:07:30 +09:00
parent 2010a0c966
commit 628462b919
2 changed files with 21 additions and 1 deletions

View File

@ -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),

View File

@ -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 {