Skip to content

Commit

Permalink
Merge pull request #35955 from hashicorp/f-aws_ec2_instance_read_timeout
Browse files Browse the repository at this point in the history
r/aws_ec2_instance/spot_instance_request: add configurable `read` timeout
  • Loading branch information
johnsonaj authored Feb 23, 2024
2 parents 4ddbf94 + 432b3e4 commit e2e6017
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changelog/35955.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_instance: Add configurable `read` timeout
```

```release-note:enhancement
resource/aws_spot_instance_request: Add configurable `read` timeout
```
7 changes: 4 additions & 3 deletions internal/service/ec2/ec2_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func ResourceInstance() *schema.Resource {

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Read: schema.DefaultTimeout(15 * time.Minute),
Update: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(20 * time.Minute),
},
Expand Down Expand Up @@ -1385,7 +1386,7 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta inte
}

if d.Get("get_password_data").(bool) {
passwordData, err := getInstancePasswordData(ctx, aws.StringValue(instance.InstanceId), conn)
passwordData, err := getInstancePasswordData(ctx, aws.StringValue(instance.InstanceId), conn, d.Timeout(schema.TimeoutRead))
if err != nil {
return sdkdiag.AppendErrorf(diags, "reading EC2 Instance (%s): %s", d.Id(), err)
}
Expand Down Expand Up @@ -2680,15 +2681,15 @@ func readInstanceShutdownBehavior(ctx context.Context, d *schema.ResourceData, c
return nil
}

func getInstancePasswordData(ctx context.Context, instanceID string, conn *ec2.EC2) (string, error) {
func getInstancePasswordData(ctx context.Context, instanceID string, conn *ec2.EC2, timeout time.Duration) (string, error) {
log.Printf("[INFO] Reading password data for instance %s", instanceID)

var passwordData string
var resp *ec2.GetPasswordDataOutput
input := &ec2.GetPasswordDataInput{
InstanceId: aws.String(instanceID),
}
err := retry.RetryContext(ctx, 15*time.Minute, func() *retry.RetryError {
err := retry.RetryContext(ctx, timeout, func() *retry.RetryError {
var err error
resp, err = conn.GetPasswordDataWithContext(ctx, input)

Expand Down
2 changes: 1 addition & 1 deletion internal/service/ec2/ec2_instance_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func dataSourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta in
}

if d.Get("get_password_data").(bool) {
passwordData, err := getInstancePasswordData(ctx, aws.StringValue(instance.InstanceId), conn)
passwordData, err := getInstancePasswordData(ctx, aws.StringValue(instance.InstanceId), conn, d.Timeout(schema.TimeoutRead))
if err != nil {
return sdkdiag.AppendErrorf(diags, "reading EC2 Instance (%s): %s", aws.StringValue(instance.InstanceId), err)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/service/ec2/ec2_spot_instance_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func ResourceSpotInstanceRequest() *schema.Resource {

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

Expand Down Expand Up @@ -348,7 +349,7 @@ func readInstance(ctx context.Context, d *schema.ResourceData, meta interface{})
}

if d.Get("get_password_data").(bool) {
passwordData, err := getInstancePasswordData(ctx, *instance.InstanceId, conn)
passwordData, err := getInstancePasswordData(ctx, *instance.InstanceId, conn, d.Timeout(schema.TimeoutRead))
if err != nil {
return sdkdiag.AppendFromErr(diags, err)
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ For `instance_market_options`, in addition to the arguments above, the following
[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts):

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

Expand Down
1 change: 1 addition & 0 deletions website/docs/r/spot_instance_request.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@ should only be used for informational purposes, not for resource dependencies:
[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts):

* `create` - (Default `10m`)
* `read` - (Default `15m`)
* `delete` - (Default `20m`)

0 comments on commit e2e6017

Please sign in to comment.