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

r/aws_{ami,ami_copy,ami_from_instance}: Configurable timeouts. #1811

Merged
merged 2 commits into from
Oct 28, 2017
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
22 changes: 14 additions & 8 deletions aws/resource_aws_ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func resourceAwsAmi() *schema.Resource {
return &schema.Resource{
Create: resourceAwsAmiCreate,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(AWSAMIRetryTimeout),
Update: schema.DefaultTimeout(AWSAMIRetryTimeout),
Delete: schema.DefaultTimeout(AWSAMIDeleteRetryTimeout),
},

Schema: resourceSchema,

// The Read, Update and Delete operations are shared with aws_ami_copy
Expand Down Expand Up @@ -117,7 +123,7 @@ func resourceAwsAmiCreate(d *schema.ResourceData, meta interface{}) error {
d.SetPartial("manage_ebs_block_devices")
d.Partial(false)

_, err = resourceAwsAmiWaitForAvailable(id, client)
_, err = resourceAwsAmiWaitForAvailable(d.Timeout(schema.TimeoutCreate), id, client)
if err != nil {
return err
}
Expand Down Expand Up @@ -170,7 +176,7 @@ func resourceAwsAmiRead(d *schema.ResourceData, meta interface{}) error {
// before we continue. We should never take this branch in normal
// circumstances since we would've waited for availability during
// the "Create" step.
image, err = resourceAwsAmiWaitForAvailable(id, client)
image, err = resourceAwsAmiWaitForAvailable(d.Timeout(schema.TimeoutCreate), id, client)
if err != nil {
return err
}
Expand Down Expand Up @@ -302,7 +308,7 @@ func resourceAwsAmiDelete(d *schema.ResourceData, meta interface{}) error {
}

// Verify that the image is actually removed, if not we need to wait for it to be removed
if err := resourceAwsAmiWaitForDestroy(d.Id(), client); err != nil {
if err := resourceAwsAmiWaitForDestroy(d.Timeout(schema.TimeoutDelete), d.Id(), client); err != nil {
return err
}

Expand Down Expand Up @@ -335,16 +341,16 @@ func AMIStateRefreshFunc(client *ec2.EC2, id string) resource.StateRefreshFunc {
}
}

func resourceAwsAmiWaitForDestroy(id string, client *ec2.EC2) error {
func resourceAwsAmiWaitForDestroy(timeout time.Duration, id string, client *ec2.EC2) error {
log.Printf("Waiting for AMI %s to be deleted...", id)

stateConf := &resource.StateChangeConf{
Pending: []string{"available", "pending", "failed"},
Target: []string{"destroyed"},
Refresh: AMIStateRefreshFunc(client, id),
Timeout: AWSAMIDeleteRetryTimeout,
Timeout: timeout,
Delay: AWSAMIRetryDelay,
MinTimeout: AWSAMIRetryTimeout,
MinTimeout: AWSAMIRetryMinTimeout,
}

_, err := stateConf.WaitForState()
Expand All @@ -355,14 +361,14 @@ func resourceAwsAmiWaitForDestroy(id string, client *ec2.EC2) error {
return nil
}

func resourceAwsAmiWaitForAvailable(id string, client *ec2.EC2) (*ec2.Image, error) {
func resourceAwsAmiWaitForAvailable(timeout time.Duration, id string, client *ec2.EC2) (*ec2.Image, error) {
log.Printf("Waiting for AMI %s to become available...", id)

stateConf := &resource.StateChangeConf{
Pending: []string{"pending"},
Target: []string{"available"},
Refresh: AMIStateRefreshFunc(client, id),
Timeout: AWSAMIRetryTimeout,
Timeout: timeout,
Delay: AWSAMIRetryDelay,
MinTimeout: AWSAMIRetryMinTimeout,
}
Expand Down
8 changes: 7 additions & 1 deletion aws/resource_aws_ami_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func resourceAwsAmiCopy() *schema.Resource {
return &schema.Resource{
Create: resourceAwsAmiCopyCreate,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(AWSAMIRetryTimeout),
Update: schema.DefaultTimeout(AWSAMIRetryTimeout),
Delete: schema.DefaultTimeout(AWSAMIDeleteRetryTimeout),
},

Schema: resourceSchema,

// The remaining operations are shared with the generic aws_ami resource,
Expand Down Expand Up @@ -81,7 +87,7 @@ func resourceAwsAmiCopyCreate(d *schema.ResourceData, meta interface{}) error {
d.SetPartial("manage_ebs_snapshots")
d.Partial(false)

_, err = resourceAwsAmiWaitForAvailable(id, client)
_, err = resourceAwsAmiWaitForAvailable(d.Timeout(schema.TimeoutCreate), id, client)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion aws/resource_aws_ami_from_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func resourceAwsAmiFromInstance() *schema.Resource {
return &schema.Resource{
Create: resourceAwsAmiFromInstanceCreate,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(AWSAMIRetryTimeout),
Update: schema.DefaultTimeout(AWSAMIRetryTimeout),
Delete: schema.DefaultTimeout(AWSAMIDeleteRetryTimeout),
},

Schema: resourceSchema,

// The remaining operations are shared with the generic aws_ami resource,
Expand Down Expand Up @@ -61,7 +67,7 @@ func resourceAwsAmiFromInstanceCreate(d *schema.ResourceData, meta interface{})
d.SetPartial("manage_ebs_snapshots")
d.Partial(false)

_, err = resourceAwsAmiWaitForAvailable(id, client)
_, err = resourceAwsAmiWaitForAvailable(d.Timeout(schema.TimeoutCreate), id, client)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_ami_launch_permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func testAccAWSAMIDisappears(imageID *string) r.TestCheckFunc {
return err
}

if err := resourceAwsAmiWaitForDestroy(*imageID, conn); err != nil {
if err := resourceAwsAmiWaitForDestroy(AWSAMIDeleteRetryTimeout, *imageID, conn); err != nil {
return err
}
return nil
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/ami.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ Nested `ephemeral_block_device` blocks have the following structure:
* `virtual_name` - (Required) A name for the ephemeral device, of the form "ephemeralN" where
*N* is a volume number starting from zero.

### Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:

* `create` - (Defaults to 40 mins) Used when creating the AMI
* `update` - (Defaults to 40 mins) Used when updating the AMI
* `delete` - (Defaults to 90 mins) Used when deregistering the AMI

## Attributes Reference

The following attributes are exported:
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/ami_copy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ The following arguments are supported:

This resource also exposes the full set of arguments from the [`aws_ami`](ami.html) resource.

### Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:

* `create` - (Defaults to 40 mins) Used when creating the AMI
* `update` - (Defaults to 40 mins) Used when updating the AMI
* `delete` - (Defaults to 90 mins) Used when deregistering the AMI

## Attributes Reference

The following attributes are exported:
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/ami_from_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ The following arguments are supported:
inconsistent filesystem state, but can be used to avoid downtime if the user otherwise
guarantees that no filesystem writes will be underway at the time of snapshot.

### Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:

* `create` - (Defaults to 40 mins) Used when creating the AMI
* `update` - (Defaults to 40 mins) Used when updating the AMI
* `delete` - (Defaults to 90 mins) Used when deregistering the AMI

## Attributes Reference

The following attributes are exported:
Expand Down