Skip to content

Commit 1f6326e

Browse files
authored
Merge pull request #50602 from hashicorp/f-dx_connection_confirmation-timeouts
r/aws_dx_connection_confirmation: add configurable `create` timeout
2 parents 6badba3 + 2b879fd commit 1f6326e

5 files changed

Lines changed: 41 additions & 16 deletions

File tree

‎.changelog/50602.txt‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```release-note:enhancement
2+
resource/aws_dx_connection: Add configurable `update` timeout. Defaults to the previously hard-coded value of `10m`.
3+
```
4+
```release-note:enhancement
5+
resource/aws_dx_connection_confirmation: Add configurable `create` timeout. Defaults to the previously hard-coded value of `10m`.
6+
```
7+
```release-note:note
8+
resource/aws_dx_connection_confirmation: Because we cannot easily test this functionality, it is best effort and we ask for community help in testing
9+
```

‎internal/service/directconnect/connection.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ func resourceConnection() *schema.Resource {
257257
},
258258
}
259259
},
260+
261+
Timeouts: &schema.ResourceTimeout{
262+
Update: schema.DefaultTimeout(10 * time.Minute),
263+
},
260264
}
261265
}
262266

@@ -354,7 +358,7 @@ func resourceConnectionUpdate(ctx context.Context, d *schema.ResourceData, meta
354358
return sdkdiag.AppendErrorf(diags, "updating Direct Connect Connection (%s): %s", d.Id(), err)
355359
}
356360

357-
if _, err := waitConnectionConfirmed(ctx, conn, d.Id()); err != nil {
361+
if err := waitConnectionConfirmed(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
358362
return sdkdiag.AppendErrorf(diags, "waiting for Direct Connect Connection (%s) update: %s", d.Id(), err)
359363
}
360364
}

‎internal/service/directconnect/connection_confirmation.go‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func resourceConnectionConfirmation() *schema.Resource {
3838
},
3939
}
4040
},
41+
42+
Timeouts: &schema.ResourceTimeout{
43+
Create: schema.DefaultTimeout(10 * time.Minute),
44+
},
4145
}
4246
}
4347

@@ -56,12 +60,16 @@ func resourceConnectionConfirmationCreate(ctx context.Context, d *schema.Resourc
5660
return sdkdiag.AppendErrorf(diags, "confirming Direct Connect Connection (%s): %s", connectionID, err)
5761
}
5862

59-
d.SetId(connectionID)
60-
61-
if _, err := waitConnectionConfirmed(ctx, conn, d.Id()); err != nil {
62-
return sdkdiag.AppendErrorf(diags, "waiting for Direct Connect Connection (%s) confirm: %s", d.Id(), err)
63+
if err := waitConnectionConfirmed(ctx, conn, connectionID, d.Timeout(schema.TimeoutCreate)); err != nil {
64+
return sdkdiag.AppendErrorf(diags, "waiting for Direct Connect Connection (%s) confirm: %s", connectionID, err)
6365
}
6466

67+
// Setting ID is deferred until after the waiter to prevent a timeout from producing
68+
// a tainted resource.
69+
//
70+
// As a "connection" resource type, there is nothing to clean up when waiting times out.
71+
d.SetId(connectionID)
72+
6573
return diags
6674
}
6775

@@ -84,22 +92,14 @@ func resourceConnectionConfirmationRead(ctx context.Context, d *schema.ResourceD
8492
return diags
8593
}
8694

87-
func waitConnectionConfirmed(ctx context.Context, conn *directconnect.Client, id string) (*awstypes.Connection, error) { //nolint:unparam
88-
const (
89-
timeout = 10 * time.Minute
90-
)
95+
func waitConnectionConfirmed(ctx context.Context, conn *directconnect.Client, id string, timeout time.Duration) error {
9196
stateConf := &retry.StateChangeConf{
9297
Pending: enum.Slice(awstypes.ConnectionStatePending, awstypes.ConnectionStateOrdering, awstypes.ConnectionStateRequested),
9398
Target: enum.Slice(awstypes.ConnectionStateAvailable),
9499
Refresh: statusConnection(conn, id),
95100
Timeout: timeout,
96101
}
97102

98-
outputRaw, err := stateConf.WaitForStateContext(ctx)
99-
100-
if output, ok := outputRaw.(*awstypes.Connection); ok {
101-
return output, err
102-
}
103-
104-
return nil, err
103+
_, err := stateConf.WaitForStateContext(ctx)
104+
return err
105105
}

‎website/docs/r/dx_connection.html.markdown‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ This resource exports the following attributes in addition to the arguments abov
9595
* `remaining` - Number of rate limiters remaining (available).
9696
* `total_bandwidth` - Total bandwidth allocated across all rate limiters.
9797

98+
## Timeouts
99+
100+
[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts):
101+
102+
- `update` - (Default `10m`)
103+
98104
## Import
99105

100106
In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Direct Connect connections using the connection `id`. For example:

‎website/docs/r/dx_connection_confirmation.html.markdown‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ from your statefile and management, **but will not destroy the Hosted Connection
3535
This resource exports the following attributes in addition to the arguments above:
3636

3737
* `id` - The ID of the connection.
38+
39+
## Timeouts
40+
41+
[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts):
42+
43+
- `create` - (Default `10m`)

0 commit comments

Comments
 (0)