From 802993108633667d900d92d5528288a56bb1b473 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Thu, 1 Dec 2016 13:53:14 +0000 Subject: [PATCH] Do not return a root device for instance store backed AMIs. (#9483) * Do not return a root device for instance store backed AMIs. * Add root EC2 instance store acceptance test. --- .../providers/aws/resource_aws_instance.go | 5 +++ .../aws/resource_aws_instance_test.go | 40 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/builtin/providers/aws/resource_aws_instance.go b/builtin/providers/aws/resource_aws_instance.go index 331c469d8..ed9691251 100644 --- a/builtin/providers/aws/resource_aws_instance.go +++ b/builtin/providers/aws/resource_aws_instance.go @@ -859,6 +859,11 @@ func fetchRootDeviceName(ami string, conn *ec2.EC2) (*string, error) { image := res.Images[0] rootDeviceName := image.RootDeviceName + // Instance store backed AMIs do not provide a root device name. + if *image.RootDeviceType == ec2.DeviceTypeInstanceStore { + return nil, nil + } + // Some AMIs have a RootDeviceName like "/dev/sda1" that does not appear as a // DeviceName in the BlockDeviceMapping list (which will instead have // something like "/dev/sda") diff --git a/builtin/providers/aws/resource_aws_instance_test.go b/builtin/providers/aws/resource_aws_instance_test.go index 5c9028066..38c2dccfc 100644 --- a/builtin/providers/aws/resource_aws_instance_test.go +++ b/builtin/providers/aws/resource_aws_instance_test.go @@ -245,6 +245,46 @@ func TestAccAWSInstance_blockDevices(t *testing.T) { }) } +func TestAccAWSInstance_rootInstanceStore(t *testing.T) { + var v ec2.Instance + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: "aws_instance.foo", + Providers: testAccProviders, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: ` + resource "aws_instance" "foo" { + # us-west-2 + # Amazon Linux HVM Instance Store 64-bit (2016.09.0) + # https://aws.amazon.com/amazon-linux-ami + ami = "ami-44c36524" + + # Only certain instance types support ephemeral root instance stores. + # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html + instance_type = "m3.medium" + }`, + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists( + "aws_instance.foo", &v), + resource.TestCheckResourceAttr( + "aws_instance.foo", "ami", "ami-44c36524"), + resource.TestCheckResourceAttr( + "aws_instance.foo", "ebs_block_device.#", "0"), + resource.TestCheckResourceAttr( + "aws_instance.foo", "ebs_optimized", "false"), + resource.TestCheckResourceAttr( + "aws_instance.foo", "instance_type", "m3.medium"), + resource.TestCheckResourceAttr( + "aws_instance.foo", "root_block_device.#", "0"), + ), + }, + }, + }) +} + func TestAccAWSInstance_sourceDestCheck(t *testing.T) { var v ec2.Instance