Skip to content

Commit

Permalink
8349 - Adding timeouts for aws_ebs_volume
Browse files Browse the repository at this point in the history
  • Loading branch information
chewvader committed Oct 2, 2020
1 parent 0e4645a commit ab318c0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
14 changes: 10 additions & 4 deletions aws/resource_aws_ebs_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func resourceAwsEbsVolume() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(5 * time.Minute),
Delete: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -149,7 +155,7 @@ func resourceAwsEbsVolumeCreate(d *schema.ResourceData, meta interface{}) error
Pending: []string{ec2.VolumeStateCreating},
Target: []string{ec2.VolumeStateAvailable},
Refresh: volumeStateRefreshFunc(conn, *result.VolumeId),
Timeout: 5 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
Expand Down Expand Up @@ -199,7 +205,7 @@ func resourceAWSEbsVolumeUpdate(d *schema.ResourceData, meta interface{}) error
Pending: []string{ec2.VolumeStateCreating, ec2.VolumeModificationStateModifying},
Target: []string{ec2.VolumeStateAvailable, ec2.VolumeStateInUse},
Refresh: volumeStateRefreshFunc(conn, *result.VolumeModification.VolumeId),
Timeout: 5 * time.Minute,
Timeout: d.Timeout(schema.TimeoutUpdate),
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
Expand Down Expand Up @@ -304,7 +310,7 @@ func resourceAwsEbsVolumeDelete(d *schema.ResourceData, meta interface{}) error
VolumeId: aws.String(d.Id()),
}

err := resource.Retry(5*time.Minute, func() *resource.RetryError {
err := resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
_, err := conn.DeleteVolume(input)

if isAWSErr(err, "InvalidVolume.NotFound", "") {
Expand Down Expand Up @@ -335,7 +341,7 @@ func resourceAwsEbsVolumeDelete(d *schema.ResourceData, meta interface{}) error
}

var output *ec2.DescribeVolumesOutput
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
var err error
output, err = conn.DescribeVolumes(describeInput)

Expand Down
6 changes: 6 additions & 0 deletions aws/resource_aws_ebs_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,12 @@ resource "aws_ebs_volume" "test" {
availability_zone = data.aws_availability_zones.available.names[0]
type = "gp2"
size = 1
timeouts {
create = "10m"
update = "10m"
delete = "10m"
}
}
`

Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/ebs_volume.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ The following arguments are supported:

~> **NOTE**: When changing the `size`, `iops` or `type` of an instance, there are [considerations](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/considerations.html) to be aware of that Amazon have written about this.

### Timeouts

`aws_ebs_volume` provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - (Default `5 minutes`) Used for creating volumes. This includes the time required for the volume to become available.
- `update` - (Default `5 minutes`) Used for size, type, or iops volume changes.
- `delete` - (Default `5 minutes`) Used for destroying volumes.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down

0 comments on commit ab318c0

Please sign in to comment.