Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -846,6 +846,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