Skip to content

Commit a1000f3

Browse files
Add field httpKeepAliveTimeoutSec to resources google_compute_target_http_proxy and google_compute_target_https_proxy (beta) (#8131) (#5818)
* HTTP Keep-alive Timeout: Add http_keep_alive_timeout_sec to Target HTTP Proxy and Target HTTPS Proxy * HTTP Keep-alive Timeout: Add target_http_proxy_http_keep_alive_timeout and target_https_proxy_http_keep_alive_timeout examples * HTTP Keep-alive Timeout: Fix indent for cloudloadbalancing_target_http_proxy_http_keep_alive_timeout * HTTP Keep-alive Timeout: Fix examples generation * HTTP Keep-alive Timeout: Specofy google-beta provider for HTTP keep-alive timeout tests * HTTP Keep-alive Timeout: Update example target http proxy name * HTTP Keep-alive Timeout: Mark httpKeepAliveTimeoutSec with beta Signed-off-by: Modular Magician <[email protected]>
1 parent 8c59e9f commit a1000f3

7 files changed

+390
-0
lines changed

.changelog/8131.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
compute: added field `httpKeepAliveTimeoutSec` to resource `google_compute_target_http_proxy` (beta)
3+
```
4+
```release-note:enhancement
5+
compute: added field `httpKeepAliveTimeoutSec` to resource `google_compute_target_https_proxy` (beta)
6+
```

google-beta/resource_compute_target_http_proxy_generated_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,82 @@ resource "google_compute_http_health_check" "default" {
100100
`, context)
101101
}
102102

103+
func TestAccComputeTargetHttpProxy_targetHttpProxyHttpKeepAliveTimeoutExample(t *testing.T) {
104+
t.Parallel()
105+
106+
context := map[string]interface{}{
107+
"random_suffix": RandString(t, 10),
108+
}
109+
110+
VcrTest(t, resource.TestCase{
111+
PreCheck: func() { acctest.AccTestPreCheck(t) },
112+
ProtoV5ProviderFactories: ProtoV5ProviderBetaFactories(t),
113+
CheckDestroy: testAccCheckComputeTargetHttpProxyDestroyProducer(t),
114+
Steps: []resource.TestStep{
115+
{
116+
Config: testAccComputeTargetHttpProxy_targetHttpProxyHttpKeepAliveTimeoutExample(context),
117+
},
118+
{
119+
ResourceName: "google_compute_target_http_proxy.default",
120+
ImportState: true,
121+
ImportStateVerify: true,
122+
ImportStateVerifyIgnore: []string{"url_map"},
123+
},
124+
},
125+
})
126+
}
127+
128+
func testAccComputeTargetHttpProxy_targetHttpProxyHttpKeepAliveTimeoutExample(context map[string]interface{}) string {
129+
return tpgresource.Nprintf(`
130+
resource "google_compute_target_http_proxy" "default" {
131+
provider = google-beta
132+
name = "tf-test-test-http-keep-alive-timeout-proxy%{random_suffix}"
133+
http_keep_alive_timeout_sec = 120
134+
url_map = google_compute_url_map.default.id
135+
}
136+
137+
resource "google_compute_url_map" "default" {
138+
provider = google-beta
139+
name = "tf-test-url-map%{random_suffix}"
140+
default_service = google_compute_backend_service.default.id
141+
142+
host_rule {
143+
hosts = ["mysite.com"]
144+
path_matcher = "allpaths"
145+
}
146+
147+
path_matcher {
148+
name = "allpaths"
149+
default_service = google_compute_backend_service.default.id
150+
151+
path_rule {
152+
paths = ["/*"]
153+
service = google_compute_backend_service.default.id
154+
}
155+
}
156+
}
157+
158+
resource "google_compute_backend_service" "default" {
159+
provider = google-beta
160+
name = "tf-test-backend-service%{random_suffix}"
161+
port_name = "http"
162+
protocol = "HTTP"
163+
timeout_sec = 10
164+
load_balancing_scheme = "EXTERNAL_MANAGED"
165+
166+
health_checks = [google_compute_http_health_check.default.id]
167+
}
168+
169+
resource "google_compute_http_health_check" "default" {
170+
provider = google-beta
171+
name = "tf-test-http-health-check%{random_suffix}"
172+
request_path = "/"
173+
check_interval_sec = 1
174+
timeout_sec = 1
175+
}
176+
`, context)
177+
}
178+
103179
func TestAccComputeTargetHttpProxy_targetHttpProxyHttpsRedirectExample(t *testing.T) {
104180
t.Parallel()
105181

google-beta/resource_compute_target_https_proxy_generated_test.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,92 @@ resource "google_compute_http_health_check" "default" {
109109
`, context)
110110
}
111111

112+
func TestAccComputeTargetHttpsProxy_targetHttpsProxyHttpKeepAliveTimeoutExample(t *testing.T) {
113+
t.Parallel()
114+
115+
context := map[string]interface{}{
116+
"random_suffix": RandString(t, 10),
117+
}
118+
119+
VcrTest(t, resource.TestCase{
120+
PreCheck: func() { acctest.AccTestPreCheck(t) },
121+
ProtoV5ProviderFactories: ProtoV5ProviderBetaFactories(t),
122+
CheckDestroy: testAccCheckComputeTargetHttpsProxyDestroyProducer(t),
123+
Steps: []resource.TestStep{
124+
{
125+
Config: testAccComputeTargetHttpsProxy_targetHttpsProxyHttpKeepAliveTimeoutExample(context),
126+
},
127+
{
128+
ResourceName: "google_compute_target_https_proxy.default",
129+
ImportState: true,
130+
ImportStateVerify: true,
131+
ImportStateVerifyIgnore: []string{"ssl_policy", "url_map"},
132+
},
133+
},
134+
})
135+
}
136+
137+
func testAccComputeTargetHttpsProxy_targetHttpsProxyHttpKeepAliveTimeoutExample(context map[string]interface{}) string {
138+
return tpgresource.Nprintf(`
139+
resource "google_compute_target_https_proxy" "default" {
140+
provider = google-beta
141+
name = "tf-test-test-http-keep-alive-timeout-proxy%{random_suffix}"
142+
http_keep_alive_timeout_sec = 120
143+
url_map = google_compute_url_map.default.id
144+
ssl_certificates = [google_compute_ssl_certificate.default.id]
145+
}
146+
147+
resource "google_compute_ssl_certificate" "default" {
148+
provider = google-beta
149+
name = "tf-test-my-certificate%{random_suffix}"
150+
private_key = file("test-fixtures/ssl_cert/test.key")
151+
certificate = file("test-fixtures/ssl_cert/test.crt")
152+
}
153+
154+
resource "google_compute_url_map" "default" {
155+
provider = google-beta
156+
name = "tf-test-url-map%{random_suffix}"
157+
description = "a description"
158+
159+
default_service = google_compute_backend_service.default.id
160+
161+
host_rule {
162+
hosts = ["mysite.com"]
163+
path_matcher = "allpaths"
164+
}
165+
166+
path_matcher {
167+
name = "allpaths"
168+
default_service = google_compute_backend_service.default.id
169+
170+
path_rule {
171+
paths = ["/*"]
172+
service = google_compute_backend_service.default.id
173+
}
174+
}
175+
}
176+
177+
resource "google_compute_backend_service" "default" {
178+
provider = google-beta
179+
name = "tf-test-backend-service%{random_suffix}"
180+
port_name = "http"
181+
protocol = "HTTP"
182+
timeout_sec = 10
183+
load_balancing_scheme = "EXTERNAL_MANAGED"
184+
185+
health_checks = [google_compute_http_health_check.default.id]
186+
}
187+
188+
resource "google_compute_http_health_check" "default" {
189+
provider = google-beta
190+
name = "tf-test-http-health-check%{random_suffix}"
191+
request_path = "/"
192+
check_interval_sec = 1
193+
timeout_sec = 1
194+
}
195+
`, context)
196+
}
197+
112198
func testAccCheckComputeTargetHttpsProxyDestroyProducer(t *testing.T) func(s *terraform.State) error {
113199
return func(s *terraform.State) error {
114200
for name, rs := range s.RootModule().Resources {

google-beta/services/compute/resource_compute_target_http_proxy.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ to the BackendService.`,
7272
ForceNew: true,
7373
Description: `An optional description of this resource.`,
7474
},
75+
"http_keep_alive_timeout_sec": {
76+
Type: schema.TypeInt,
77+
Optional: true,
78+
ForceNew: true,
79+
Description: `Specifies how long to keep a connection open, after completing a response,
80+
while there is no matching traffic (in seconds). If an HTTP keepalive is
81+
not specified, a default value (610 seconds) will be used. For Global
82+
external HTTP(S) load balancer, the minimum allowed value is 5 seconds and
83+
the maximum allowed value is 1200 seconds. For Global external HTTP(S)
84+
load balancer (classic), this option is not available publicly.`,
85+
},
7586
"proxy_bind": {
7687
Type: schema.TypeBool,
7788
Computed: true,
@@ -137,6 +148,12 @@ func resourceComputeTargetHttpProxyCreate(d *schema.ResourceData, meta interface
137148
} else if v, ok := d.GetOkExists("proxy_bind"); !tpgresource.IsEmptyValue(reflect.ValueOf(proxyBindProp)) && (ok || !reflect.DeepEqual(v, proxyBindProp)) {
138149
obj["proxyBind"] = proxyBindProp
139150
}
151+
httpKeepAliveTimeoutSecProp, err := expandComputeTargetHttpProxyHttpKeepAliveTimeoutSec(d.Get("http_keep_alive_timeout_sec"), d, config)
152+
if err != nil {
153+
return err
154+
} else if v, ok := d.GetOkExists("http_keep_alive_timeout_sec"); !tpgresource.IsEmptyValue(reflect.ValueOf(httpKeepAliveTimeoutSecProp)) && (ok || !reflect.DeepEqual(v, httpKeepAliveTimeoutSecProp)) {
155+
obj["httpKeepAliveTimeoutSec"] = httpKeepAliveTimeoutSecProp
156+
}
140157

141158
url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/targetHttpProxies")
142159
if err != nil {
@@ -250,6 +267,9 @@ func resourceComputeTargetHttpProxyRead(d *schema.ResourceData, meta interface{}
250267
if err := d.Set("proxy_bind", flattenComputeTargetHttpProxyProxyBind(res["proxyBind"], d, config)); err != nil {
251268
return fmt.Errorf("Error reading TargetHttpProxy: %s", err)
252269
}
270+
if err := d.Set("http_keep_alive_timeout_sec", flattenComputeTargetHttpProxyHttpKeepAliveTimeoutSec(res["httpKeepAliveTimeoutSec"], d, config)); err != nil {
271+
return fmt.Errorf("Error reading TargetHttpProxy: %s", err)
272+
}
253273
if err := d.Set("self_link", tpgresource.ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
254274
return fmt.Errorf("Error reading TargetHttpProxy: %s", err)
255275
}
@@ -435,6 +455,23 @@ func flattenComputeTargetHttpProxyProxyBind(v interface{}, d *schema.ResourceDat
435455
return v
436456
}
437457

458+
func flattenComputeTargetHttpProxyHttpKeepAliveTimeoutSec(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
459+
// Handles the string fixed64 format
460+
if strVal, ok := v.(string); ok {
461+
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
462+
return intVal
463+
}
464+
}
465+
466+
// number values are represented as float64
467+
if floatVal, ok := v.(float64); ok {
468+
intVal := int(floatVal)
469+
return intVal
470+
}
471+
472+
return v // let terraform core handle it otherwise
473+
}
474+
438475
func expandComputeTargetHttpProxyDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
439476
return v, nil
440477
}
@@ -454,3 +491,7 @@ func expandComputeTargetHttpProxyUrlMap(v interface{}, d tpgresource.TerraformRe
454491
func expandComputeTargetHttpProxyProxyBind(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
455492
return v, nil
456493
}
494+
495+
func expandComputeTargetHttpProxyHttpKeepAliveTimeoutSec(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
496+
return v, nil
497+
}

google-beta/services/compute/resource_compute_target_https_proxy.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ Accepted format is '//certificatemanager.googleapis.com/projects/{project}/locat
8080
ForceNew: true,
8181
Description: `An optional description of this resource.`,
8282
},
83+
"http_keep_alive_timeout_sec": {
84+
Type: schema.TypeInt,
85+
Optional: true,
86+
ForceNew: true,
87+
Description: `Specifies how long to keep a connection open, after completing a response,
88+
while there is no matching traffic (in seconds). If an HTTP keepalive is
89+
not specified, a default value (610 seconds) will be used. For Global
90+
external HTTP(S) load balancer, the minimum allowed value is 5 seconds and
91+
the maximum allowed value is 1200 seconds. For Global external HTTP(S)
92+
load balancer (classic), this option is not available publicly.`,
93+
},
8394
"proxy_bind": {
8495
Type: schema.TypeBool,
8596
Computed: true,
@@ -198,6 +209,12 @@ func resourceComputeTargetHttpsProxyCreate(d *schema.ResourceData, meta interfac
198209
} else if v, ok := d.GetOkExists("proxy_bind"); !tpgresource.IsEmptyValue(reflect.ValueOf(proxyBindProp)) && (ok || !reflect.DeepEqual(v, proxyBindProp)) {
199210
obj["proxyBind"] = proxyBindProp
200211
}
212+
httpKeepAliveTimeoutSecProp, err := expandComputeTargetHttpsProxyHttpKeepAliveTimeoutSec(d.Get("http_keep_alive_timeout_sec"), d, config)
213+
if err != nil {
214+
return err
215+
} else if v, ok := d.GetOkExists("http_keep_alive_timeout_sec"); !tpgresource.IsEmptyValue(reflect.ValueOf(httpKeepAliveTimeoutSecProp)) && (ok || !reflect.DeepEqual(v, httpKeepAliveTimeoutSecProp)) {
216+
obj["httpKeepAliveTimeoutSec"] = httpKeepAliveTimeoutSecProp
217+
}
201218

202219
url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/targetHttpsProxies")
203220
if err != nil {
@@ -323,6 +340,9 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{
323340
if err := d.Set("proxy_bind", flattenComputeTargetHttpsProxyProxyBind(res["proxyBind"], d, config)); err != nil {
324341
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
325342
}
343+
if err := d.Set("http_keep_alive_timeout_sec", flattenComputeTargetHttpsProxyHttpKeepAliveTimeoutSec(res["httpKeepAliveTimeoutSec"], d, config)); err != nil {
344+
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
345+
}
326346
if err := d.Set("self_link", tpgresource.ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
327347
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
328348
}
@@ -702,6 +722,23 @@ func flattenComputeTargetHttpsProxyProxyBind(v interface{}, d *schema.ResourceDa
702722
return v
703723
}
704724

725+
func flattenComputeTargetHttpsProxyHttpKeepAliveTimeoutSec(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
726+
// Handles the string fixed64 format
727+
if strVal, ok := v.(string); ok {
728+
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
729+
return intVal
730+
}
731+
}
732+
733+
// number values are represented as float64
734+
if floatVal, ok := v.(float64); ok {
735+
intVal := int(floatVal)
736+
return intVal
737+
}
738+
739+
return v // let terraform core handle it otherwise
740+
}
741+
705742
func expandComputeTargetHttpsProxyDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
706743
return v, nil
707744
}
@@ -753,3 +790,7 @@ func expandComputeTargetHttpsProxyUrlMap(v interface{}, d tpgresource.TerraformR
753790
func expandComputeTargetHttpsProxyProxyBind(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
754791
return v, nil
755792
}
793+
794+
func expandComputeTargetHttpsProxyHttpKeepAliveTimeoutSec(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
795+
return v, nil
796+
}

0 commit comments

Comments
 (0)