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

aws_ec2_host: Add configurable timeout #36538

Merged
merged 1 commit into from
Mar 25, 2024
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
3 changes: 3 additions & 0 deletions .changelog/36538.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ec2_host: Add user configurable timeouts
```
13 changes: 10 additions & 3 deletions internal/service/ec2/ec2_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
Expand Down Expand Up @@ -39,6 +40,12 @@ func ResourceHost() *schema.Resource {

CustomizeDiff: verify.SetTagsDiff,

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

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -130,7 +137,7 @@ func resourceHostCreate(ctx context.Context, d *schema.ResourceData, meta interf

d.SetId(aws.StringValue(output.HostIds[0]))

if _, err := WaitHostCreated(ctx, conn, d.Id()); err != nil {
if _, err := WaitHostCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for EC2 Host (%s) create: %s", d.Id(), err)
}

Expand Down Expand Up @@ -210,7 +217,7 @@ func resourceHostUpdate(ctx context.Context, d *schema.ResourceData, meta interf
return sdkdiag.AppendErrorf(diags, "modifying EC2 Host (%s): %s", d.Id(), err)
}

if _, err := WaitHostUpdated(ctx, conn, d.Id()); err != nil {
if _, err := WaitHostUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for EC2 Host (%s) update: %s", d.Id(), err)
}
}
Expand Down Expand Up @@ -239,7 +246,7 @@ func resourceHostDelete(ctx context.Context, d *schema.ResourceData, meta interf
return sdkdiag.AppendErrorf(diags, "releasing EC2 Host (%s): %s", d.Id(), err)
}

if _, err := WaitHostDeleted(ctx, conn, d.Id()); err != nil {
if _, err := WaitHostDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for EC2 Host (%s) delete: %s", d.Id(), err)
}

Expand Down
18 changes: 6 additions & 12 deletions internal/service/ec2/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -2160,17 +2160,11 @@ func WaitVPNGatewayDeleted(ctx context.Context, conn *ec2.EC2, id string) (*ec2.
return nil, err
}

const (
HostCreatedTimeout = 10 * time.Minute
HostUpdatedTimeout = 10 * time.Minute
HostDeletedTimeout = 20 * time.Minute
)

func WaitHostCreated(ctx context.Context, conn *ec2.EC2, id string) (*ec2.Host, error) {
func WaitHostCreated(ctx context.Context, conn *ec2.EC2, id string, timeout time.Duration) (*ec2.Host, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{ec2.AllocationStatePending},
Target: []string{ec2.AllocationStateAvailable},
Timeout: HostCreatedTimeout,
Timeout: timeout,
Refresh: StatusHostState(ctx, conn, id),
}

Expand All @@ -2183,11 +2177,11 @@ func WaitHostCreated(ctx context.Context, conn *ec2.EC2, id string) (*ec2.Host,
return nil, err
}

func WaitHostUpdated(ctx context.Context, conn *ec2.EC2, id string) (*ec2.Host, error) {
func WaitHostUpdated(ctx context.Context, conn *ec2.EC2, id string, timeout time.Duration) (*ec2.Host, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{ec2.AllocationStatePending},
Target: []string{ec2.AllocationStateAvailable},
Timeout: HostUpdatedTimeout,
Timeout: timeout,
Refresh: StatusHostState(ctx, conn, id),
}

Expand All @@ -2200,11 +2194,11 @@ func WaitHostUpdated(ctx context.Context, conn *ec2.EC2, id string) (*ec2.Host,
return nil, err
}

func WaitHostDeleted(ctx context.Context, conn *ec2.EC2, id string) (*ec2.Host, error) {
func WaitHostDeleted(ctx context.Context, conn *ec2.EC2, id string, timeout time.Duration) (*ec2.Host, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{ec2.AllocationStateAvailable},
Target: []string{},
Timeout: HostDeletedTimeout,
Timeout: timeout,
Refresh: StatusHostState(ctx, conn, id),
}

Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/ec2_host.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ This resource exports the following attributes in addition to the arguments abov
* `owner_id` - The ID of the AWS account that owns the Dedicated Host.
* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).

## Timeouts

[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts):

* `create` - (Default `10m`)
* `update` - (Default `10m`)
* `delete` - (Default `20m`)

## Import

In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import hosts using the host `id`. For example:
Expand Down
Loading