provider/aws: Update aws_ebs_volume when attached (#14005)

Fixes: #12496

When an EBS volume was attached to an instance and the user tried to
resize, they would get an error as follows:

```
* aws_ebs_volume.ebs_data_volume: Error waiting for Volume (vol-027e83f7) to become available: unexpected state 'in-use', wanted target 'available'. last error: %!s(<nil>)
```

`available` is a state *only* when creating an EBS volume that is not attached. When an instance is attached, it will go into the state `in-use`. Therefore `in-use` is a valid state when modifying an EBS volume that is attached:

```
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSEBSVolume_'                                   ✹ ✭
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/04/27 07:08:18 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSEBSVolume_ -timeout 120m
=== RUN   TestAccAWSEBSVolume_importBasic
--- PASS: TestAccAWSEBSVolume_importBasic (41.10s)
=== RUN   TestAccAWSEBSVolume_basic
--- PASS: TestAccAWSEBSVolume_basic (38.22s)
=== RUN   TestAccAWSEBSVolume_updateAttachedEbsVolume
--- PASS: TestAccAWSEBSVolume_updateAttachedEbsVolume (199.11s)
=== RUN   TestAccAWSEBSVolume_updateSize
--- PASS: TestAccAWSEBSVolume_updateSize (70.53s)
=== RUN   TestAccAWSEBSVolume_updateType
--- PASS: TestAccAWSEBSVolume_updateType (69.75s)
=== RUN   TestAccAWSEBSVolume_updateIops
--- PASS: TestAccAWSEBSVolume_updateIops (70.38s)
=== RUN   TestAccAWSEBSVolume_kmsKey
--- PASS: TestAccAWSEBSVolume_kmsKey (76.64s)
=== RUN   TestAccAWSEBSVolume_NoIops
--- PASS: TestAccAWSEBSVolume_NoIops (39.80s)
=== RUN   TestAccAWSEBSVolume_withTags
--- PASS: TestAccAWSEBSVolume_withTags (38.04s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	643.609s
```
This commit is contained in:
Paul Stack 2017-04-27 07:30:23 +12:00 committed by GitHub
parent 0ffb5aa1d6
commit f9ba882f73
2 changed files with 144 additions and 1 deletions

View File

@ -179,7 +179,7 @@ func resourceAWSEbsVolumeUpdate(d *schema.ResourceData, meta interface{}) error
stateConf := &resource.StateChangeConf{ stateConf := &resource.StateChangeConf{
Pending: []string{"creating", "modifying"}, Pending: []string{"creating", "modifying"},
Target: []string{"available"}, Target: []string{"available", "in-use"},
Refresh: volumeStateRefreshFunc(conn, *result.VolumeModification.VolumeId), Refresh: volumeStateRefreshFunc(conn, *result.VolumeModification.VolumeId),
Timeout: 5 * time.Minute, Timeout: 5 * time.Minute,
Delay: 10 * time.Second, Delay: 10 * time.Second,

View File

@ -30,6 +30,31 @@ func TestAccAWSEBSVolume_basic(t *testing.T) {
}) })
} }
func TestAccAWSEBSVolume_updateAttachedEbsVolume(t *testing.T) {
var v ec2.Volume
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_ebs_volume.test",
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAwsEbsAttachedVolumeConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckVolumeExists("aws_ebs_volume.test", &v),
resource.TestCheckResourceAttr("aws_ebs_volume.test", "size", "10"),
),
},
{
Config: testAccAwsEbsAttachedVolumeConfigUpdateSize,
Check: resource.ComposeTestCheckFunc(
testAccCheckVolumeExists("aws_ebs_volume.test", &v),
resource.TestCheckResourceAttr("aws_ebs_volume.test", "size", "20"),
),
},
},
})
}
func TestAccAWSEBSVolume_updateSize(t *testing.T) { func TestAccAWSEBSVolume_updateSize(t *testing.T) {
var v ec2.Volume var v ec2.Volume
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
@ -200,6 +225,124 @@ resource "aws_ebs_volume" "test" {
} }
` `
const testAccAwsEbsAttachedVolumeConfig = `
data "aws_ami" "debian_jessie_latest" {
most_recent = true
filter {
name = "name"
values = ["debian-jessie-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
owners = ["379101102735"] # Debian
}
resource "aws_instance" "test" {
ami = "${data.aws_ami.debian_jessie_latest.id}"
associate_public_ip_address = true
count = 1
instance_type = "t2.medium"
root_block_device {
volume_size = "10"
volume_type = "standard"
delete_on_termination = true
}
tags {
Name = "test-terraform"
}
}
resource "aws_ebs_volume" "test" {
depends_on = ["aws_instance.test"]
availability_zone = "${aws_instance.test.availability_zone}"
type = "gp2"
size = "10"
}
resource "aws_volume_attachment" "test" {
depends_on = ["aws_ebs_volume.test"]
device_name = "/dev/xvdg"
volume_id = "${aws_ebs_volume.test.id}"
instance_id = "${aws_instance.test.id}"
}
`
const testAccAwsEbsAttachedVolumeConfigUpdateSize = `
data "aws_ami" "debian_jessie_latest" {
most_recent = true
filter {
name = "name"
values = ["debian-jessie-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
owners = ["379101102735"] # Debian
}
resource "aws_instance" "test" {
ami = "${data.aws_ami.debian_jessie_latest.id}"
associate_public_ip_address = true
count = 1
instance_type = "t2.medium"
root_block_device {
volume_size = "10"
volume_type = "standard"
delete_on_termination = true
}
tags {
Name = "test-terraform"
}
}
resource "aws_ebs_volume" "test" {
depends_on = ["aws_instance.test"]
availability_zone = "${aws_instance.test.availability_zone}"
type = "gp2"
size = "20"
}
resource "aws_volume_attachment" "test" {
depends_on = ["aws_ebs_volume.test"]
device_name = "/dev/xvdg"
volume_id = "${aws_ebs_volume.test.id}"
instance_id = "${aws_instance.test.id}"
}
`
const testAccAwsEbsVolumeConfigUpdateSize = ` const testAccAwsEbsVolumeConfigUpdateSize = `
resource "aws_ebs_volume" "test" { resource "aws_ebs_volume" "test" {
availability_zone = "us-west-2a" availability_zone = "us-west-2a"