Skip to content

Commit

Permalink
Adds test for retrieving computed root EBS device values
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavison committed Apr 4, 2020
1 parent 46d5fe0 commit 8f146ff
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion aws/resource_aws_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func TestAccAWSInstance_basic(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceDestroy,
Steps: []resource.TestStep{
// Create a volume to cover #1249
// Create a volume to cover https://github.com/hashicorp/terraform/issues/1249
{
// Need a resource in this config so the provisioner will be available
Config: testAccInstanceConfig_pre(rInt),
Expand All @@ -276,6 +276,7 @@ func TestAccAWSInstance_basic(t *testing.T) {
testAccCheckInstanceExists(resourceName, &v),
testCheck(rInt),
resource.TestCheckResourceAttr(resourceName, "user_data", "3dc39dda39be1205215e776bad998da361a5955d"),
resource.TestCheckResourceAttr(resourceName, "root_block_device.#", "0"), // This is an instance store AMI
resource.TestCheckResourceAttr(resourceName, "ebs_block_device.#", "0"),
resource.TestMatchResourceAttr(resourceName, "arn", regexp.MustCompile(`^arn:[^:]+:ec2:[^:]+:\d{12}:instance/i-.+`)),
),
Expand Down Expand Up @@ -1440,6 +1441,32 @@ func TestAccAWSInstance_changeInstanceType(t *testing.T) {
})
}

func TestAccAWSInstance_EbsRootDevice_basic(t *testing.T) {
var instance ec2.Instance
resourceName := "aws_instance.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsEc2InstanceEbsRootDeviceBasic(),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(resourceName, &instance),
resource.TestCheckResourceAttr(resourceName, "root_block_device.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "root_block_device.0.delete_on_termination"),
resource.TestCheckResourceAttrSet(resourceName, "root_block_device.0.encrypted"),
resource.TestCheckResourceAttrSet(resourceName, "root_block_device.0.iops"),
resource.TestCheckResourceAttrSet(resourceName, "root_block_device.0.volume_size"),
resource.TestCheckResourceAttrSet(resourceName, "root_block_device.0.volume_type"),
resource.TestCheckResourceAttrSet(resourceName, "root_block_device.0.volume_id"),
),
},
},
})
}

func TestAccAWSInstance_changeRootBlockDeviceVolumeSize_basic(t *testing.T) {
var before ec2.Instance
var after ec2.Instance
Expand Down Expand Up @@ -2958,6 +2985,30 @@ resource "aws_instance" "test" {
}
`

func testAccAwsEc2InstanceEbsRootDeviceBasic() string {
return fmt.Sprintf(`
data "aws_ami" "ami" {
owners = ["amazon"]
most_recent = true
filter {
name = "name"
values = ["amzn2-ami-*"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
}
resource "aws_instance" "test" {
ami = data.aws_ami.ami.id
instance_type = "t2.small"
}
`)
}

const testAccInstanceGP2IopsDeviceVolumeSizeUpdate = `
resource "aws_instance" "test" {
# us-west-2
Expand Down

0 comments on commit 8f146ff

Please sign in to comment.