Skip to content

Commit

Permalink
Do not return a root device for instance store backed AMIs. (hashicor…
Browse files Browse the repository at this point in the history
…p#9483)

* Do not return a root device for instance store backed AMIs.

* Add root EC2 instance store acceptance test.
  • Loading branch information
tomwilkie authored and Gustavo Mateus committed Dec 6, 2016
1 parent 72b47ff commit 297c6fd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions builtin/providers/aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
40 changes: 40 additions & 0 deletions builtin/providers/aws/resource_aws_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 297c6fd

Please sign in to comment.