diff --git a/builder/amazon/common/block_device.go b/builder/amazon/common/block_device.go index 985c582ea..949241463 100644 --- a/builder/amazon/common/block_device.go +++ b/builder/amazon/common/block_device.go @@ -22,7 +22,15 @@ type BlockDevice struct { } type BlockDevices struct { - AMIMappings []BlockDevice `mapstructure:"ami_block_device_mappings"` + AMIBlockDevices `mapstructure:",squash"` + LaunchBlockDevices `mapstructure:",squash"` +} + +type AMIBlockDevices struct { + AMIMappings []BlockDevice `mapstructure:"ami_block_device_mappings"` +} + +type LaunchBlockDevices struct { LaunchMappings []BlockDevice `mapstructure:"launch_block_device_mappings"` } @@ -77,10 +85,10 @@ func (b *BlockDevices) Prepare(ctx *interpolate.Context) []error { return nil } -func (b *BlockDevices) BuildAMIDevices() []*ec2.BlockDeviceMapping { +func (b *AMIBlockDevices) BuildAMIDevices() []*ec2.BlockDeviceMapping { return buildBlockDevices(b.AMIMappings) } -func (b *BlockDevices) BuildLaunchDevices() []*ec2.BlockDeviceMapping { +func (b *LaunchBlockDevices) BuildLaunchDevices() []*ec2.BlockDeviceMapping { return buildBlockDevices(b.LaunchMappings) } diff --git a/builder/amazon/common/block_device_test.go b/builder/amazon/common/block_device_test.go index acdba6fbd..5fc25f243 100644 --- a/builder/amazon/common/block_device_test.go +++ b/builder/amazon/common/block_device_test.go @@ -124,22 +124,26 @@ func TestBlockDevice(t *testing.T) { } for _, tc := range cases { - blockDevices := BlockDevices{ - AMIMappings: []BlockDevice{*tc.Config}, + amiBlockDevices := AMIBlockDevices{ + AMIMappings: []BlockDevice{*tc.Config}, + } + + launchBlockDevices := LaunchBlockDevices{ LaunchMappings: []BlockDevice{*tc.Config}, } expected := []*ec2.BlockDeviceMapping{tc.Result} - got := blockDevices.BuildAMIDevices() - if !reflect.DeepEqual(expected, got) { + + amiResults := amiBlockDevices.BuildAMIDevices() + if !reflect.DeepEqual(expected, amiResults) { t.Fatalf("Bad block device, \nexpected: %#v\n\ngot: %#v", - expected, got) + expected, amiResults) } - if !reflect.DeepEqual(expected, blockDevices.BuildLaunchDevices()) { + launchResults := launchBlockDevices.BuildLaunchDevices() + if !reflect.DeepEqual(expected, launchResults) { t.Fatalf("Bad block device, \nexpected: %#v\n\ngot: %#v", - expected, - blockDevices.BuildLaunchDevices()) + expected, launchResults) } } }