Skip to content

Commit

Permalink
Allow configurable timeout when reading security group rule
Browse files Browse the repository at this point in the history
When being throttled on AWS requests, read requests are the first ones
to be throttled, and reading security group rules can take longer than
5m to complete. Transform the hard timeout of 5m with a configurable
timeout to avoid this problem.

Fixes part of hashicorp#3128
  • Loading branch information
obourdon committed Oct 11, 2021
1 parent bcc5658 commit 591e5e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion aws/resource_aws_security_group_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func resourceAwsSecurityGroupRule() *schema.Resource {
SchemaVersion: 2,
MigrateState: resourceAwsSecurityGroupRuleMigrateState,

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

Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Expand Down Expand Up @@ -227,7 +231,7 @@ information and instructions for recovery. Error: %w`, sg_id, autherr)
id := ipPermissionIDHash(sg_id, ruleType, perm)
log.Printf("[DEBUG] Computed group rule ID %s", id)

err = resource.Retry(5*time.Minute, func() *resource.RetryError {
err = resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError {
sg, err := finder.SecurityGroupByID(conn, sg_id)

if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/security_group_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ In addition to all arguments above, the following attributes are exported:

* `id` - ID of the security group rule.

## Timeouts

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

- `read` - (Default `5 minutes`) How long to wait for reading a rsecurity group rule.

## Import

Security Group Rules can be imported using the `security_group_id`, `type`, `protocol`, `from_port`, `to_port`, and source(s)/destination(s) (e.g. `cidr_block`) separated by underscores (`_`). All parts are required.
Expand Down

0 comments on commit 591e5e2

Please sign in to comment.