diff --git a/builtin/providers/aws/resource_aws_instance_test.go b/builtin/providers/aws/resource_aws_instance_test.go index ff7087732..fc72ff452 100644 --- a/builtin/providers/aws/resource_aws_instance_test.go +++ b/builtin/providers/aws/resource_aws_instance_test.go @@ -64,6 +64,44 @@ func TestAccAWSInstance_normal(t *testing.T) { }) } +func TestAccAWSInstance_blockDevicesCheck(t *testing.T) { + var v ec2.Instance + + testCheck := func() resource.TestCheckFunc { + return func(*terraform.State) error { + + // Map out the block devices by name, which should be unique. + blockDevices := make(map[string]ec2.BlockDevice) + for _, blockDevice := range v.BlockDevices { + blockDevices[blockDevice.DeviceName] = blockDevice + } + + // Check if the secondary block device exists. + if _, ok := blockDevices["/dev/sdb"]; !ok { + fmt.Errorf("block device doesn't exist: /dev/sdb") + } + + return nil + } + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccInstanceConfigBlockDevices, + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists( + "aws_instance.foo", &v), + testCheck(), + ), + }, + }, + }) +} + func TestAccAWSInstance_sourceDestCheck(t *testing.T) { var v ec2.Instance @@ -233,6 +271,19 @@ resource "aws_instance" "foo" { } ` +const testAccInstanceConfigBlockDevices = ` +resource "aws_instance" "foo" { + # us-west-2 + ami = "ami-55a7ea65" + instance_type = "m1.small" + block_device { + device_name = "/dev/sdb" + volume_type = "gp2" + volume_size = 10 + } +} +` + const testAccInstanceConfigSourceDest = ` resource "aws_vpc" "foo" { cidr_block = "10.1.0.0/16"