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 field httpKeepAliveTimeoutSec to resources google_compute_target_http_proxy and google_compute_target_https_proxy #15109

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
6 changes: 6 additions & 0 deletions .changelog/8275.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
compute: added field `http_keep_alive_timeout_sec` to resource `google_compute_target_http_proxy`
```
```release-note:enhancement
compute: added field `http_keep_alive_timeout_sec` to resource `google_compute_target_https_proxy`
```
72 changes: 72 additions & 0 deletions google/resource_compute_target_http_proxy_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,78 @@ resource "google_compute_http_health_check" "default" {
`, context)
}

func TestAccComputeTargetHttpProxy_targetHttpProxyHttpKeepAliveTimeoutExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeTargetHttpProxyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeTargetHttpProxy_targetHttpProxyHttpKeepAliveTimeoutExample(context),
},
{
ResourceName: "google_compute_target_http_proxy.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"url_map"},
},
},
})
}

func testAccComputeTargetHttpProxy_targetHttpProxyHttpKeepAliveTimeoutExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_target_http_proxy" "default" {
name = "tf-test-test-http-keep-alive-timeout-proxy%{random_suffix}"
http_keep_alive_timeout_sec = 610
url_map = google_compute_url_map.default.id
}

resource "google_compute_url_map" "default" {
name = "tf-test-url-map%{random_suffix}"
default_service = google_compute_backend_service.default.id

host_rule {
hosts = ["mysite.com"]
path_matcher = "allpaths"
}

path_matcher {
name = "allpaths"
default_service = google_compute_backend_service.default.id

path_rule {
paths = ["/*"]
service = google_compute_backend_service.default.id
}
}
}

resource "google_compute_backend_service" "default" {
name = "tf-test-backend-service%{random_suffix}"
port_name = "http"
protocol = "HTTP"
timeout_sec = 10
load_balancing_scheme = "EXTERNAL_MANAGED"

health_checks = [google_compute_http_health_check.default.id]
}

resource "google_compute_http_health_check" "default" {
name = "tf-test-http-health-check%{random_suffix}"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
`, context)
}

func TestAccComputeTargetHttpProxy_targetHttpProxyHttpsRedirectExample(t *testing.T) {
t.Parallel()

Expand Down
81 changes: 81 additions & 0 deletions google/resource_compute_target_https_proxy_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,87 @@ resource "google_compute_http_health_check" "default" {
`, context)
}

func TestAccComputeTargetHttpsProxy_targetHttpsProxyHttpKeepAliveTimeoutExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeTargetHttpsProxyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeTargetHttpsProxy_targetHttpsProxyHttpKeepAliveTimeoutExample(context),
},
{
ResourceName: "google_compute_target_https_proxy.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ssl_policy", "url_map"},
},
},
})
}

func testAccComputeTargetHttpsProxy_targetHttpsProxyHttpKeepAliveTimeoutExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_target_https_proxy" "default" {
name = "tf-test-test-http-keep-alive-timeout-proxy%{random_suffix}"
http_keep_alive_timeout_sec = 610
url_map = google_compute_url_map.default.id
ssl_certificates = [google_compute_ssl_certificate.default.id]
}

resource "google_compute_ssl_certificate" "default" {
name = "tf-test-my-certificate%{random_suffix}"
private_key = file("test-fixtures/ssl_cert/test.key")
certificate = file("test-fixtures/ssl_cert/test.crt")
}

resource "google_compute_url_map" "default" {
name = "tf-test-url-map%{random_suffix}"
description = "a description"

default_service = google_compute_backend_service.default.id

host_rule {
hosts = ["mysite.com"]
path_matcher = "allpaths"
}

path_matcher {
name = "allpaths"
default_service = google_compute_backend_service.default.id

path_rule {
paths = ["/*"]
service = google_compute_backend_service.default.id
}
}
}

resource "google_compute_backend_service" "default" {
name = "tf-test-backend-service%{random_suffix}"
port_name = "http"
protocol = "HTTP"
timeout_sec = 10
load_balancing_scheme = "EXTERNAL_MANAGED"

health_checks = [google_compute_http_health_check.default.id]
}

resource "google_compute_http_health_check" "default" {
name = "tf-test-http-health-check%{random_suffix}"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
`, context)
}

func testAccCheckComputeTargetHttpsProxyDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
41 changes: 41 additions & 0 deletions google/services/compute/resource_compute_target_http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ to the BackendService.`,
ForceNew: true,
Description: `An optional description of this resource.`,
},
"http_keep_alive_timeout_sec": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: `Specifies how long to keep a connection open, after completing a response,
while there is no matching traffic (in seconds). If an HTTP keepalive is
not specified, a default value (610 seconds) will be used. For Global
external HTTP(S) load balancer, the minimum allowed value is 5 seconds and
the maximum allowed value is 1200 seconds. For Global external HTTP(S)
load balancer (classic), this option is not available publicly.`,
},
"proxy_bind": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -137,6 +148,12 @@ func resourceComputeTargetHttpProxyCreate(d *schema.ResourceData, meta interface
} else if v, ok := d.GetOkExists("proxy_bind"); !tpgresource.IsEmptyValue(reflect.ValueOf(proxyBindProp)) && (ok || !reflect.DeepEqual(v, proxyBindProp)) {
obj["proxyBind"] = proxyBindProp
}
httpKeepAliveTimeoutSecProp, err := expandComputeTargetHttpProxyHttpKeepAliveTimeoutSec(d.Get("http_keep_alive_timeout_sec"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("http_keep_alive_timeout_sec"); !tpgresource.IsEmptyValue(reflect.ValueOf(httpKeepAliveTimeoutSecProp)) && (ok || !reflect.DeepEqual(v, httpKeepAliveTimeoutSecProp)) {
obj["httpKeepAliveTimeoutSec"] = httpKeepAliveTimeoutSecProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/targetHttpProxies")
if err != nil {
Expand Down Expand Up @@ -250,6 +267,9 @@ func resourceComputeTargetHttpProxyRead(d *schema.ResourceData, meta interface{}
if err := d.Set("proxy_bind", flattenComputeTargetHttpProxyProxyBind(res["proxyBind"], d, config)); err != nil {
return fmt.Errorf("Error reading TargetHttpProxy: %s", err)
}
if err := d.Set("http_keep_alive_timeout_sec", flattenComputeTargetHttpProxyHttpKeepAliveTimeoutSec(res["httpKeepAliveTimeoutSec"], d, config)); err != nil {
return fmt.Errorf("Error reading TargetHttpProxy: %s", err)
}
if err := d.Set("self_link", tpgresource.ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading TargetHttpProxy: %s", err)
}
Expand Down Expand Up @@ -435,6 +455,23 @@ func flattenComputeTargetHttpProxyProxyBind(v interface{}, d *schema.ResourceDat
return v
}

func flattenComputeTargetHttpProxyHttpKeepAliveTimeoutSec(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func expandComputeTargetHttpProxyDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand All @@ -454,3 +491,7 @@ func expandComputeTargetHttpProxyUrlMap(v interface{}, d tpgresource.TerraformRe
func expandComputeTargetHttpProxyProxyBind(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputeTargetHttpProxyHttpKeepAliveTimeoutSec(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
41 changes: 41 additions & 0 deletions google/services/compute/resource_compute_target_https_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ Accepted format is '//certificatemanager.googleapis.com/projects/{project}/locat
ForceNew: true,
Description: `An optional description of this resource.`,
},
"http_keep_alive_timeout_sec": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: `Specifies how long to keep a connection open, after completing a response,
while there is no matching traffic (in seconds). If an HTTP keepalive is
not specified, a default value (610 seconds) will be used. For Global
external HTTP(S) load balancer, the minimum allowed value is 5 seconds and
the maximum allowed value is 1200 seconds. For Global external HTTP(S)
load balancer (classic), this option is not available publicly.`,
},
"proxy_bind": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -198,6 +209,12 @@ func resourceComputeTargetHttpsProxyCreate(d *schema.ResourceData, meta interfac
} else if v, ok := d.GetOkExists("proxy_bind"); !tpgresource.IsEmptyValue(reflect.ValueOf(proxyBindProp)) && (ok || !reflect.DeepEqual(v, proxyBindProp)) {
obj["proxyBind"] = proxyBindProp
}
httpKeepAliveTimeoutSecProp, err := expandComputeTargetHttpsProxyHttpKeepAliveTimeoutSec(d.Get("http_keep_alive_timeout_sec"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("http_keep_alive_timeout_sec"); !tpgresource.IsEmptyValue(reflect.ValueOf(httpKeepAliveTimeoutSecProp)) && (ok || !reflect.DeepEqual(v, httpKeepAliveTimeoutSecProp)) {
obj["httpKeepAliveTimeoutSec"] = httpKeepAliveTimeoutSecProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/targetHttpsProxies")
if err != nil {
Expand Down Expand Up @@ -323,6 +340,9 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{
if err := d.Set("proxy_bind", flattenComputeTargetHttpsProxyProxyBind(res["proxyBind"], d, config)); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
if err := d.Set("http_keep_alive_timeout_sec", flattenComputeTargetHttpsProxyHttpKeepAliveTimeoutSec(res["httpKeepAliveTimeoutSec"], d, config)); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
if err := d.Set("self_link", tpgresource.ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
Expand Down Expand Up @@ -702,6 +722,23 @@ func flattenComputeTargetHttpsProxyProxyBind(v interface{}, d *schema.ResourceDa
return v
}

func flattenComputeTargetHttpsProxyHttpKeepAliveTimeoutSec(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func expandComputeTargetHttpsProxyDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -753,3 +790,7 @@ func expandComputeTargetHttpsProxyUrlMap(v interface{}, d tpgresource.TerraformR
func expandComputeTargetHttpsProxyProxyBind(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputeTargetHttpsProxyHttpKeepAliveTimeoutSec(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
8 changes: 2 additions & 6 deletions website/docs/r/compute_target_http_proxy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ resource "google_compute_http_health_check" "default" {

```hcl
resource "google_compute_target_http_proxy" "default" {
provider = google-beta
name = "test-http-keep-alive-timeout-proxy"
http_keep_alive_timeout_sec = 120
http_keep_alive_timeout_sec = 610
url_map = google_compute_url_map.default.id
}

resource "google_compute_url_map" "default" {
provider = google-beta
name = "url-map"
default_service = google_compute_backend_service.default.id

Expand All @@ -118,7 +116,6 @@ resource "google_compute_url_map" "default" {
}

resource "google_compute_backend_service" "default" {
provider = google-beta
name = "backend-service"
port_name = "http"
protocol = "HTTP"
Expand All @@ -129,7 +126,6 @@ resource "google_compute_backend_service" "default" {
}

resource "google_compute_http_health_check" "default" {
provider = google-beta
name = "http-health-check"
request_path = "/"
check_interval_sec = 1
Expand Down Expand Up @@ -193,7 +189,7 @@ The following arguments are supported:
this target proxy has a loadBalancingScheme set to INTERNAL_SELF_MANAGED.

* `http_keep_alive_timeout_sec` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
(Optional)
Specifies how long to keep a connection open, after completing a response,
while there is no matching traffic (in seconds). If an HTTP keepalive is
not specified, a default value (610 seconds) will be used. For Global
Expand Down
Loading