Commit 39a8ba13 authored by Chris Bednarski's avatar Chris Bednarski

Merge pull request #2459 from mitchellh/b-2360

Don't add ephemeral block devices to the EBS mapping
parents f2750562 241903d0
package common package common
import ( import (
"strings"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/mitchellh/packer/template/interpolate" "github.com/mitchellh/packer/template/interpolate"
...@@ -47,11 +49,14 @@ func buildBlockDevices(b []BlockDevice) []*ec2.BlockDeviceMapping { ...@@ -47,11 +49,14 @@ func buildBlockDevices(b []BlockDevice) []*ec2.BlockDeviceMapping {
} }
mapping := &ec2.BlockDeviceMapping{ mapping := &ec2.BlockDeviceMapping{
EBS: ebsBlockDevice,
DeviceName: aws.String(blockDevice.DeviceName), DeviceName: aws.String(blockDevice.DeviceName),
VirtualName: aws.String(blockDevice.VirtualName), VirtualName: aws.String(blockDevice.VirtualName),
} }
if !strings.HasPrefix(blockDevice.VirtualName, "ephemeral") {
mapping.EBS = ebsBlockDevice
}
if blockDevice.NoDevice { if blockDevice.NoDevice {
mapping.NoDevice = aws.String("") mapping.NoDevice = aws.String("")
} }
......
...@@ -17,17 +17,15 @@ func TestBlockDevice(t *testing.T) { ...@@ -17,17 +17,15 @@ func TestBlockDevice(t *testing.T) {
{ {
Config: &BlockDevice{ Config: &BlockDevice{
DeviceName: "/dev/sdb", DeviceName: "/dev/sdb",
VirtualName: "ephemeral0",
SnapshotId: "snap-1234", SnapshotId: "snap-1234",
VolumeType: "standard", VolumeType: "standard",
VolumeSize: 8, VolumeSize: 8,
DeleteOnTermination: true, DeleteOnTermination: true,
IOPS: 1000,
}, },
Result: &ec2.BlockDeviceMapping{ Result: &ec2.BlockDeviceMapping{
DeviceName: aws.String("/dev/sdb"), DeviceName: aws.String("/dev/sdb"),
VirtualName: aws.String("ephemeral0"), VirtualName: aws.String(""),
EBS: &ec2.EBSBlockDevice{ EBS: &ec2.EBSBlockDevice{
SnapshotID: aws.String("snap-1234"), SnapshotID: aws.String("snap-1234"),
VolumeType: aws.String("standard"), VolumeType: aws.String("standard"),
...@@ -55,7 +53,6 @@ func TestBlockDevice(t *testing.T) { ...@@ -55,7 +53,6 @@ func TestBlockDevice(t *testing.T) {
{ {
Config: &BlockDevice{ Config: &BlockDevice{
DeviceName: "/dev/sdb", DeviceName: "/dev/sdb",
VirtualName: "ephemeral0",
VolumeType: "io1", VolumeType: "io1",
VolumeSize: 8, VolumeSize: 8,
DeleteOnTermination: true, DeleteOnTermination: true,
...@@ -64,7 +61,7 @@ func TestBlockDevice(t *testing.T) { ...@@ -64,7 +61,7 @@ func TestBlockDevice(t *testing.T) {
Result: &ec2.BlockDeviceMapping{ Result: &ec2.BlockDeviceMapping{
DeviceName: aws.String("/dev/sdb"), DeviceName: aws.String("/dev/sdb"),
VirtualName: aws.String("ephemeral0"), VirtualName: aws.String(""),
EBS: &ec2.EBSBlockDevice{ EBS: &ec2.EBSBlockDevice{
VolumeType: aws.String("io1"), VolumeType: aws.String("io1"),
VolumeSize: aws.Long(8), VolumeSize: aws.Long(8),
...@@ -73,6 +70,17 @@ func TestBlockDevice(t *testing.T) { ...@@ -73,6 +70,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 { for _, tc := range cases {
...@@ -84,11 +92,14 @@ func TestBlockDevice(t *testing.T) { ...@@ -84,11 +92,14 @@ func TestBlockDevice(t *testing.T) {
expected := []*ec2.BlockDeviceMapping{tc.Result} expected := []*ec2.BlockDeviceMapping{tc.Result}
got := blockDevices.BuildAMIDevices() got := blockDevices.BuildAMIDevices()
if !reflect.DeepEqual(expected, got) { 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()) { 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()))
} }
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment