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 TCP TIME_WAIT timeout to google_compute_router_nat #5123

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/7154.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `tcp_time_wait_timeout_sec` field to `google_compute_router_nat` resource
```
40 changes: 40 additions & 0 deletions google-beta/resource_compute_router_nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ is set to MANUAL_ONLY.`,
Defaults to 1200s if not set.`,
Default: 1200,
},
"tcp_time_wait_timeout_sec": {
Type: schema.TypeInt,
Optional: true,
Description: `Timeout (in seconds) for TCP connections that are in TIME_WAIT state.
Defaults to 120s if not set.`,
Default: 120,
},
"tcp_transitory_idle_timeout_sec": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -540,6 +547,12 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
} else if v, ok := d.GetOkExists("tcp_transitory_idle_timeout_sec"); !isEmptyValue(reflect.ValueOf(tcpTransitoryIdleTimeoutSecProp)) && (ok || !reflect.DeepEqual(v, tcpTransitoryIdleTimeoutSecProp)) {
obj["tcpTransitoryIdleTimeoutSec"] = tcpTransitoryIdleTimeoutSecProp
}
tcpTimeWaitTimeoutSecProp, err := expandNestedComputeRouterNatTcpTimeWaitTimeoutSec(d.Get("tcp_time_wait_timeout_sec"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("tcp_time_wait_timeout_sec"); !isEmptyValue(reflect.ValueOf(tcpTimeWaitTimeoutSecProp)) && (ok || !reflect.DeepEqual(v, tcpTimeWaitTimeoutSecProp)) {
obj["tcpTimeWaitTimeoutSec"] = tcpTimeWaitTimeoutSecProp
}
logConfigProp, err := expandNestedComputeRouterNatLogConfig(d.Get("log_config"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -702,6 +715,9 @@ func resourceComputeRouterNatRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("tcp_transitory_idle_timeout_sec", flattenNestedComputeRouterNatTcpTransitoryIdleTimeoutSec(res["tcpTransitoryIdleTimeoutSec"], d, config)); err != nil {
return fmt.Errorf("Error reading RouterNat: %s", err)
}
if err := d.Set("tcp_time_wait_timeout_sec", flattenNestedComputeRouterNatTcpTimeWaitTimeoutSec(res["tcpTimeWaitTimeoutSec"], d, config)); err != nil {
return fmt.Errorf("Error reading RouterNat: %s", err)
}
if err := d.Set("log_config", flattenNestedComputeRouterNatLogConfig(res["logConfig"], d, config)); err != nil {
return fmt.Errorf("Error reading RouterNat: %s", err)
}
Expand Down Expand Up @@ -803,6 +819,12 @@ func resourceComputeRouterNatUpdate(d *schema.ResourceData, meta interface{}) er
} else if v, ok := d.GetOkExists("tcp_transitory_idle_timeout_sec"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, tcpTransitoryIdleTimeoutSecProp)) {
obj["tcpTransitoryIdleTimeoutSec"] = tcpTransitoryIdleTimeoutSecProp
}
tcpTimeWaitTimeoutSecProp, err := expandNestedComputeRouterNatTcpTimeWaitTimeoutSec(d.Get("tcp_time_wait_timeout_sec"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("tcp_time_wait_timeout_sec"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, tcpTimeWaitTimeoutSecProp)) {
obj["tcpTimeWaitTimeoutSec"] = tcpTimeWaitTimeoutSecProp
}
logConfigProp, err := expandNestedComputeRouterNatLogConfig(d.Get("log_config"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1104,6 +1126,20 @@ func flattenNestedComputeRouterNatTcpTransitoryIdleTimeoutSec(v interface{}, d *
return v
}

func flattenNestedComputeRouterNatTcpTimeWaitTimeoutSec(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil || isEmptyValue(reflect.ValueOf(v)) {
return 120
}
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := stringToFixed64(strVal); err == nil {
return intVal
} // let terraform core handle it if we can't convert the string to an int.
}

return v
}

func flattenNestedComputeRouterNatLogConfig(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -1335,6 +1371,10 @@ func expandNestedComputeRouterNatTcpTransitoryIdleTimeoutSec(v interface{}, d Te
return v, nil
}

func expandNestedComputeRouterNatTcpTimeWaitTimeoutSec(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandNestedComputeRouterNatLogConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
3 changes: 3 additions & 0 deletions google-beta/resource_compute_router_nat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ resource "google_compute_router_nat" "foobar" {
icmp_idle_timeout_sec = 60
tcp_established_idle_timeout_sec = 1600
tcp_transitory_idle_timeout_sec = 60
tcp_time_wait_timeout_sec = 60

log_config {
enable = true
Expand Down Expand Up @@ -645,6 +646,7 @@ resource "google_compute_router_nat" "foobar" {
icmp_idle_timeout_sec = 60
tcp_established_idle_timeout_sec = 1600
tcp_transitory_idle_timeout_sec = 60
tcp_time_wait_timeout_sec = 60

log_config {
enable = true
Expand Down Expand Up @@ -696,6 +698,7 @@ resource "google_compute_router_nat" "foobar" {
icmp_idle_timeout_sec = 60
tcp_established_idle_timeout_sec = 1600
tcp_transitory_idle_timeout_sec = 60
tcp_time_wait_timeout_sec = 60

log_config {
enable = true
Expand Down
5 changes: 5 additions & 0 deletions website/docs/r/compute_router_nat.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ The following arguments are supported:
Timeout (in seconds) for TCP transitory connections.
Defaults to 30s if not set.

* `tcp_time_wait_timeout_sec` -
(Optional)
Timeout (in seconds) for TCP connections that are in TIME_WAIT state.
Defaults to 120s if not set.

* `log_config` -
(Optional)
Configuration for logging on NAT
Expand Down