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

Add timeouts to the aws_networkfirewall_firewall resource #34918

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/34918.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_networkfirewall_firewall: Add configurable timeouts
```
30 changes: 16 additions & 14 deletions internal/service/networkfirewall/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func ResourceFirewall() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},

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

CustomizeDiff: customdiff.Sequence(
customdiff.ComputedIf("firewall_status", func(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
return diff.HasChange("subnet_mapping")
Expand Down Expand Up @@ -191,7 +197,7 @@ func resourceFirewallCreate(ctx context.Context, d *schema.ResourceData, meta in

d.SetId(aws.StringValue(output.Firewall.FirewallArn))

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

Expand Down Expand Up @@ -362,7 +368,7 @@ func resourceFirewallUpdate(ctx context.Context, d *schema.ResourceData, meta in
return sdkdiag.AppendErrorf(diags, "associating NetworkFirewall Firewall (%s) subnets: %s", d.Id(), err)
}

updateToken, err = waitFirewallUpdated(ctx, conn, d.Id())
updateToken, err = waitFirewallUpdated(ctx, conn, d.Timeout(schema.TimeoutUpdate), d.Id())

if err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for NetworkFirewall Firewall (%s) update: %s", d.Id(), err)
Expand All @@ -379,7 +385,7 @@ func resourceFirewallUpdate(ctx context.Context, d *schema.ResourceData, meta in
_, err := conn.DisassociateSubnetsWithContext(ctx, input)

if err == nil {
/*updateToken*/ _, err = waitFirewallUpdated(ctx, conn, d.Id())
/*updateToken*/ _, err = waitFirewallUpdated(ctx, conn, d.Timeout(schema.TimeoutUpdate), d.Id())

if err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for NetworkFirewall Firewall (%s) update: %s", d.Id(), err)
Expand Down Expand Up @@ -411,7 +417,7 @@ func resourceFirewallDelete(ctx context.Context, d *schema.ResourceData, meta in
return sdkdiag.AppendErrorf(diags, "deleting NetworkFirewall Firewall (%s): %s", d.Id(), err)
}

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

Expand Down Expand Up @@ -459,16 +465,12 @@ func statusFirewall(ctx context.Context, conn *networkfirewall.NetworkFirewall,
}
}

const (
firewallTimeout = 20 * time.Minute
)

func waitFirewallCreated(ctx context.Context, conn *networkfirewall.NetworkFirewall, arn string) (*networkfirewall.Firewall, error) {
func waitFirewallCreated(ctx context.Context, conn *networkfirewall.NetworkFirewall, timeout time.Duration, arn string) (*networkfirewall.Firewall, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{networkfirewall.FirewallStatusValueProvisioning},
Target: []string{networkfirewall.FirewallStatusValueReady},
Refresh: statusFirewall(ctx, conn, arn),
Timeout: firewallTimeout,
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)
Expand All @@ -480,12 +482,12 @@ func waitFirewallCreated(ctx context.Context, conn *networkfirewall.NetworkFirew
return nil, err
}

func waitFirewallUpdated(ctx context.Context, conn *networkfirewall.NetworkFirewall, arn string) (string, error) {
func waitFirewallUpdated(ctx context.Context, conn *networkfirewall.NetworkFirewall, timeout time.Duration, arn string) (string, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{networkfirewall.FirewallStatusValueProvisioning},
Target: []string{networkfirewall.FirewallStatusValueReady},
Refresh: statusFirewall(ctx, conn, arn),
Timeout: firewallTimeout,
Timeout: timeout,
// Delay added to account for Associate/DisassociateSubnet calls that return
// a READY status immediately after the method is called instead of immediately
// returning PROVISIONING
Expand All @@ -501,12 +503,12 @@ func waitFirewallUpdated(ctx context.Context, conn *networkfirewall.NetworkFirew
return "", err
}

func waitFirewallDeleted(ctx context.Context, conn *networkfirewall.NetworkFirewall, arn string) (*networkfirewall.Firewall, error) {
func waitFirewallDeleted(ctx context.Context, conn *networkfirewall.NetworkFirewall, timeout time.Duration, arn string) (*networkfirewall.Firewall, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{networkfirewall.FirewallStatusValueDeleting},
Target: []string{},
Refresh: statusFirewall(ctx, conn, arn),
Timeout: firewallTimeout,
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)
Expand Down
8 changes: 8 additions & 0 deletions internal/service/networkfirewall/firewall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,10 @@ resource "aws_networkfirewall_firewall" "test" {
subnet_mapping {
subnet_id = aws_subnet.example.id
}

timeouts {
update = "1h"
}
}
`, rName))
}
Expand Down Expand Up @@ -632,6 +636,10 @@ resource "aws_networkfirewall_firewall" "test" {
subnet_mapping {
subnet_id = aws_subnet.example.id
}

timeouts {
update = "1h"
}
}
`, rName))
}
Expand Down
14 changes: 14 additions & 0 deletions website/docs/r/networkfirewall_firewall.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ resource "aws_networkfirewall_firewall" "example" {
Tag1 = "Value1"
Tag2 = "Value2"
}

timeouts {
create = "40m"
update = "50m"
delete = "1h"
}
}
```

Expand Down Expand Up @@ -85,6 +91,14 @@ This resource exports the following attributes in addition to the arguments abov

* `update_token` - A string token used when updating a firewall.

## Timeouts

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

- `create` - (Default `30m`)
- `update` - (Default `30m`)
- `delete` - (Default `30m`)

## Import

In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Network Firewall Firewalls using their `arn`. For example:
Expand Down
Loading