From 224bb78175c4d50051f04ca4dcb922c992ca3ad0 Mon Sep 17 00:00:00 2001 From: Anthony Spring Date: Mon, 29 Jun 2015 17:11:58 -0400 Subject: [PATCH 1/5] Make EBS block device mapping optional for ephemeral virtual names. --- builder/amazon/common/block_device.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/builder/amazon/common/block_device.go b/builder/amazon/common/block_device.go index 482b876f6..48cc4ef27 100644 --- a/builder/amazon/common/block_device.go +++ b/builder/amazon/common/block_device.go @@ -4,6 +4,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/mitchellh/packer/template/interpolate" + "strings" ) // BlockDevice @@ -47,9 +48,12 @@ func buildBlockDevices(b []BlockDevice) []*ec2.BlockDeviceMapping { } mapping := &ec2.BlockDeviceMapping{ - EBS: ebsBlockDevice, - DeviceName: aws.String(blockDevice.DeviceName), - VirtualName: aws.String(blockDevice.VirtualName), + DeviceName: aws.String(blockDevice.DeviceName), + VirtualName: aws.String(blockDevice.VirtualName), + } + + if !strings.HasPrefix(blockDevice.VirtualName, "ephemeral") { + mapping.EBS = ebsBlockDevice } if blockDevice.NoDevice { From ae064207d529b8d8f81a3d121e672632ca88eb23 Mon Sep 17 00:00:00 2001 From: Tommy Ulfsparre Date: Thu, 2 Jul 2015 00:02:31 +0200 Subject: [PATCH 2/5] Add test for ephemeral block device mapping --- builder/amazon/common/block_device_test.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/builder/amazon/common/block_device_test.go b/builder/amazon/common/block_device_test.go index 063c480f1..803bfc996 100644 --- a/builder/amazon/common/block_device_test.go +++ b/builder/amazon/common/block_device_test.go @@ -17,7 +17,6 @@ func TestBlockDevice(t *testing.T) { { Config: &BlockDevice{ DeviceName: "/dev/sdb", - VirtualName: "ephemeral0", SnapshotId: "snap-1234", VolumeType: "standard", VolumeSize: 8, @@ -27,7 +26,7 @@ func TestBlockDevice(t *testing.T) { Result: &ec2.BlockDeviceMapping{ DeviceName: aws.String("/dev/sdb"), - VirtualName: aws.String("ephemeral0"), + VirtualName: aws.String(""), EBS: &ec2.EBSBlockDevice{ SnapshotID: aws.String("snap-1234"), VolumeType: aws.String("standard"), @@ -55,7 +54,6 @@ func TestBlockDevice(t *testing.T) { { Config: &BlockDevice{ DeviceName: "/dev/sdb", - VirtualName: "ephemeral0", VolumeType: "io1", VolumeSize: 8, DeleteOnTermination: true, @@ -64,7 +62,7 @@ func TestBlockDevice(t *testing.T) { Result: &ec2.BlockDeviceMapping{ DeviceName: aws.String("/dev/sdb"), - VirtualName: aws.String("ephemeral0"), + VirtualName: aws.String(""), EBS: &ec2.EBSBlockDevice{ VolumeType: aws.String("io1"), VolumeSize: aws.Long(8), @@ -73,6 +71,17 @@ func TestBlockDevice(t *testing.T) { }, }, }, + { + Config: &BlockDevice{ + DeviceName: "/dev/sdb", + VirtualName: "ephemeral0", + }, + + Result: &ec2.BlockDeviceMapping{ + DeviceName: aws.String("/dev/sdb"), + VirtualName: aws.String("ephemeral0"), + }, + }, } for _, tc := range cases { From 9365a4317976d5602a627538c3ffeff9fd03a4b6 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Wed, 15 Jul 2015 17:07:36 -0700 Subject: [PATCH 3/5] Reformat --- builder/amazon/common/block_device.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/builder/amazon/common/block_device.go b/builder/amazon/common/block_device.go index 48cc4ef27..fb14a66ae 100644 --- a/builder/amazon/common/block_device.go +++ b/builder/amazon/common/block_device.go @@ -1,10 +1,11 @@ package common import ( + "strings" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/mitchellh/packer/template/interpolate" - "strings" ) // BlockDevice @@ -48,12 +49,12 @@ func buildBlockDevices(b []BlockDevice) []*ec2.BlockDeviceMapping { } mapping := &ec2.BlockDeviceMapping{ - DeviceName: aws.String(blockDevice.DeviceName), - VirtualName: aws.String(blockDevice.VirtualName), + DeviceName: aws.String(blockDevice.DeviceName), + VirtualName: aws.String(blockDevice.VirtualName), } if !strings.HasPrefix(blockDevice.VirtualName, "ephemeral") { - mapping.EBS = ebsBlockDevice + mapping.EBS = ebsBlockDevice } if blockDevice.NoDevice { From c615539929a186875c043df1e4de4d475eef7a8e Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Wed, 15 Jul 2015 17:17:59 -0700 Subject: [PATCH 4/5] Reformat long lines --- builder/amazon/common/block_device_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/builder/amazon/common/block_device_test.go b/builder/amazon/common/block_device_test.go index 803bfc996..1bdf9cdf7 100644 --- a/builder/amazon/common/block_device_test.go +++ b/builder/amazon/common/block_device_test.go @@ -93,11 +93,14 @@ func TestBlockDevice(t *testing.T) { expected := []*ec2.BlockDeviceMapping{tc.Result} got := blockDevices.BuildAMIDevices() if !reflect.DeepEqual(expected, got) { - t.Fatalf("Bad block device, \nexpected: %s\n\ngot: %s", awsutil.StringValue(expected), awsutil.StringValue(got)) + t.Fatalf("Bad block device, \nexpected: %s\n\ngot: %s", + awsutil.StringValue(expected), awsutil.StringValue(got)) } if !reflect.DeepEqual(expected, blockDevices.BuildLaunchDevices()) { - t.Fatalf("Bad block device, \nexpected: %s\n\ngot: %s", awsutil.StringValue(expected), awsutil.StringValue(blockDevices.BuildLaunchDevices())) + t.Fatalf("Bad block device, \nexpected: %s\n\ngot: %s", + awsutil.StringValue(expected), + awsutil.StringValue(blockDevices.BuildLaunchDevices())) } } } From 241903d0b00226f76ef74f04d02e7c1d260d66d1 Mon Sep 17 00:00:00 2001 From: Tommy Ulfsparre Date: Thu, 2 Jul 2015 00:06:24 +0200 Subject: [PATCH 5/5] no point in setting iops on a standard volumes --- builder/amazon/common/block_device_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/builder/amazon/common/block_device_test.go b/builder/amazon/common/block_device_test.go index 1bdf9cdf7..c69ef2efb 100644 --- a/builder/amazon/common/block_device_test.go +++ b/builder/amazon/common/block_device_test.go @@ -21,7 +21,6 @@ func TestBlockDevice(t *testing.T) { VolumeType: "standard", VolumeSize: 8, DeleteOnTermination: true, - IOPS: 1000, }, Result: &ec2.BlockDeviceMapping{