Skip to content

Commit 9d055ef

Browse files
Update EdgeCacheOrigin resources to reflect current API (#5776) (#4122)
Signed-off-by: Modular Magician <[email protected]>
1 parent a48aa0c commit 9d055ef

File tree

5 files changed

+124
-35
lines changed

5 files changed

+124
-35
lines changed

.changelog/5776.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
networkservices: updated EdgeCacheOrigin to retry_conditions to include `FORBIDDEN`
3+
```
4+
```release-note:enhancement
5+
networkservices: updated EdgeCacheOrigin resource to read and write the `timeout` property, including a new `read_timeout` field.
6+
```

google-beta/resource_network_services_edge_cache_origin.go

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ and all following characters must be a dash, underscore, letter or digit.`,
5656
Required: true,
5757
Description: `A fully qualified domain name (FQDN) or IP address reachable over the public Internet, or the address of a Google Cloud Storage bucket.
5858
59-
This address will be used as the origin for cache requests - e.g. FQDN: media-backend.example.com IPv4:35.218.1.1 IPv6:[2607:f8b0:4012:809::200e] Cloud Storage: gs://bucketname
59+
This address will be used as the origin for cache requests - e.g. FQDN: media-backend.example.com, IPv4: 35.218.1.1, IPv6: 2607:f8b0:4012:809::200e, Cloud Storage: gs://bucketname
6060
61-
When providing an FQDN (hostname), it must be publicly resolvable (e.g. via Google public DNS) and IP addresses must be publicly routable.
61+
When providing an FQDN (hostname), it must be publicly resolvable (e.g. via Google public DNS) and IP addresses must be publicly routable. It must not contain a protocol (e.g., https://) and it must not contain any slashes.
6262
If a Cloud Storage bucket is provided, it must be in the canonical "gs://bucketname" format. Other forms, such as "storage.googleapis.com", will be rejected.`,
6363
},
6464
"description": {
@@ -94,8 +94,8 @@ retryConditions and failoverOrigin to control its own cache fill failures.
9494
The total number of allowed attempts to cache fill across this and failover origins is limited to four.
9595
The total time allowed for cache fill attempts across this and failover origins can be controlled with maxAttemptsTimeout.
9696
97-
The last valid response from an origin will be returned to the client.
98-
If no origin returns a valid response, an HTTP 503 will be returned to the client.
97+
The last valid, non-retried response from all origins will be returned to the client.
98+
If no origin returns a valid response, an HTTP 502 will be returned to the client.
9999
100100
Defaults to 1. Must be a value greater than 0 and less than 4.`,
101101
},
@@ -135,10 +135,11 @@ Valid values are:
135135
- HTTP_5XX: Retry if the origin responds with any 5xx response code, or if the origin does not respond at all, example: disconnects, reset, read timeout, connection failure, and refused streams.
136136
- GATEWAY_ERROR: Similar to 5xx, but only applies to response codes 502, 503 or 504.
137137
- RETRIABLE_4XX: Retry for retriable 4xx response codes, which include HTTP 409 (Conflict) and HTTP 429 (Too Many Requests)
138-
- NOT_FOUND: Retry if the origin returns a HTTP 404 (Not Found). This can be useful when generating video content, and the segment is not available yet. Possible values: ["CONNECT_FAILURE", "HTTP_5XX", "GATEWAY_ERROR", "RETRIABLE_4XX", "NOT_FOUND"]`,
138+
- NOT_FOUND: Retry if the origin returns a HTTP 404 (Not Found). This can be useful when generating video content, and the segment is not available yet.
139+
- FORBIDDEN: Retry if the origin returns a HTTP 403 (Forbidden). Possible values: ["CONNECT_FAILURE", "HTTP_5XX", "GATEWAY_ERROR", "RETRIABLE_4XX", "NOT_FOUND", "FORBIDDEN"]`,
139140
Elem: &schema.Schema{
140141
Type: schema.TypeString,
141-
ValidateFunc: validateEnum([]string{"CONNECT_FAILURE", "HTTP_5XX", "GATEWAY_ERROR", "RETRIABLE_4XX", "NOT_FOUND"}),
142+
ValidateFunc: validateEnum([]string{"CONNECT_FAILURE", "HTTP_5XX", "GATEWAY_ERROR", "RETRIABLE_4XX", "NOT_FOUND", "FORBIDDEN"}),
142143
},
143144
},
144145
"timeout": {
@@ -151,26 +152,48 @@ Valid values are:
151152
"connect_timeout": {
152153
Type: schema.TypeString,
153154
Optional: true,
154-
Description: `The maximum duration to wait for the origin connection to be established, including DNS lookup, TLS handshake and TCP/QUIC connection establishment.
155+
Description: `The maximum duration to wait for a single origin connection to be established, including DNS lookup, TLS handshake and TCP/QUIC connection establishment.
155156
156-
Defaults to 5 seconds. The timeout must be a value between 1s and 15s.`,
157-
AtLeastOneOf: []string{"timeout.0.connect_timeout", "timeout.0.max_attempts_timeout", "timeout.0.response_timeout"},
157+
Defaults to 5 seconds. The timeout must be a value between 1s and 15s.
158+
159+
The connectTimeout capped by the deadline set by the request's maxAttemptsTimeout. The last connection attempt may have a smaller connectTimeout in order to adhere to the overall maxAttemptsTimeout.`,
160+
AtLeastOneOf: []string{"timeout.0.connect_timeout", "timeout.0.max_attempts_timeout", "timeout.0.response_timeout", "timeout.0.read_timeout"},
158161
},
159162
"max_attempts_timeout": {
160163
Type: schema.TypeString,
161164
Optional: true,
162-
Description: `The maximum time across all connection attempts to the origin, including failover origins, before returning an error to the client. A HTTP 503 will be returned if the timeout is reached before a response is returned.
165+
Description: `The maximum time across all connection attempts to the origin, including failover origins, before returning an error to the client. A HTTP 504 will be returned if the timeout is reached before a response is returned.
166+
167+
Defaults to 15 seconds. The timeout must be a value between 1s and 30s.
168+
169+
If a failoverOrigin is specified, the maxAttemptsTimeout of the first configured origin sets the deadline for all connection attempts across all failoverOrigins.`,
170+
AtLeastOneOf: []string{"timeout.0.connect_timeout", "timeout.0.max_attempts_timeout", "timeout.0.response_timeout", "timeout.0.read_timeout"},
171+
},
172+
"read_timeout": {
173+
Type: schema.TypeString,
174+
Optional: true,
175+
Description: `The maximum duration to wait between reads of a single HTTP connection/stream.
176+
177+
Defaults to 15 seconds. The timeout must be a value between 1s and 30s.
178+
179+
The readTimeout is capped by the responseTimeout. All reads of the HTTP connection/stream must be completed by the deadline set by the responseTimeout.
163180
164-
Defaults to 5 seconds. The timeout must be a value between 1s and 15s.`,
165-
AtLeastOneOf: []string{"timeout.0.connect_timeout", "timeout.0.max_attempts_timeout", "timeout.0.response_timeout"},
181+
If the response headers have already been written to the connection, the response will be truncated and logged.`,
182+
AtLeastOneOf: []string{"timeout.0.connect_timeout", "timeout.0.max_attempts_timeout", "timeout.0.response_timeout", "timeout.0.read_timeout"},
166183
},
167184
"response_timeout": {
168185
Type: schema.TypeString,
169186
Optional: true,
170-
Description: `The maximum duration to wait for data to arrive when reading from the HTTP connection/stream.
187+
Description: `The maximum duration to wait for the last byte of a response to arrive when reading from the HTTP connection/stream.
171188
172-
Defaults to 5 seconds. The timeout must be a value between 1s and 30s.`,
173-
AtLeastOneOf: []string{"timeout.0.connect_timeout", "timeout.0.max_attempts_timeout", "timeout.0.response_timeout"},
189+
Defaults to 30 seconds. The timeout must be a value between 1s and 120s.
190+
191+
The responseTimeout starts after the connection has been established.
192+
193+
This also applies to HTTP Chunked Transfer Encoding responses, and/or when an open-ended Range request is made to the origin. Origins that take longer to write additional bytes to the response than the configured responseTimeout will result in an error being returned to the client.
194+
195+
If the response headers have already been written to the connection, the response will be truncated and logged.`,
196+
AtLeastOneOf: []string{"timeout.0.connect_timeout", "timeout.0.max_attempts_timeout", "timeout.0.response_timeout", "timeout.0.read_timeout"},
174197
},
175198
},
176199
},
@@ -353,6 +376,9 @@ func resourceNetworkServicesEdgeCacheOriginRead(d *schema.ResourceData, meta int
353376
if err := d.Set("retry_conditions", flattenNetworkServicesEdgeCacheOriginRetryConditions(res["retryConditions"], d, config)); err != nil {
354377
return fmt.Errorf("Error reading EdgeCacheOrigin: %s", err)
355378
}
379+
if err := d.Set("timeout", flattenNetworkServicesEdgeCacheOriginTimeout(res["timeout"], d, config)); err != nil {
380+
return fmt.Errorf("Error reading EdgeCacheOrigin: %s", err)
381+
}
356382

357383
return nil
358384
}
@@ -625,6 +651,30 @@ func flattenNetworkServicesEdgeCacheOriginRetryConditions(v interface{}, d *sche
625651
return v
626652
}
627653

654+
func flattenNetworkServicesEdgeCacheOriginTimeout(v interface{}, d *schema.ResourceData, config *Config) interface{} {
655+
out := make(map[string]string)
656+
657+
if v == nil {
658+
return nil
659+
}
660+
661+
in := v.(map[string]interface{})
662+
if e, ok := in["connectTimeout"]; ok {
663+
out["connect_timeout"] = e.(string)
664+
}
665+
if e, ok := in["maxAttemptsTimeout"]; ok {
666+
out["max_attempts_timeout"] = e.(string)
667+
}
668+
if e, ok := in["responseTimeout"]; ok {
669+
out["response_timeout"] = e.(string)
670+
}
671+
if e, ok := in["readTimeout"]; ok {
672+
out["read_timeout"] = e.(string)
673+
}
674+
675+
return []interface{}{out}
676+
}
677+
628678
func expandNetworkServicesEdgeCacheOriginDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
629679
return v, nil
630680
}
@@ -694,6 +744,13 @@ func expandNetworkServicesEdgeCacheOriginTimeout(v interface{}, d TerraformResou
694744
transformed["responseTimeout"] = transformedResponseTimeout
695745
}
696746

747+
transformedReadTimeout, err := expandNetworkServicesEdgeCacheOriginTimeoutReadTimeout(original["read_timeout"], d, config)
748+
if err != nil {
749+
return nil, err
750+
} else if val := reflect.ValueOf(transformedReadTimeout); val.IsValid() && !isEmptyValue(val) {
751+
transformed["readTimeout"] = transformedReadTimeout
752+
}
753+
697754
return transformed, nil
698755
}
699756

@@ -708,3 +765,7 @@ func expandNetworkServicesEdgeCacheOriginTimeoutMaxAttemptsTimeout(v interface{}
708765
func expandNetworkServicesEdgeCacheOriginTimeoutResponseTimeout(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
709766
return v, nil
710767
}
768+
769+
func expandNetworkServicesEdgeCacheOriginTimeoutReadTimeout(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
770+
return v, nil
771+
}

google-beta/resource_network_services_edge_cache_origin_generated_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestAccNetworkServicesEdgeCacheOrigin_networkServicesEdgeCacheOriginBasicEx
4242
ResourceName: "google_network_services_edge_cache_origin.default",
4343
ImportState: true,
4444
ImportStateVerify: true,
45-
ImportStateVerifyIgnore: []string{"timeout", "name", "timeout"},
45+
ImportStateVerifyIgnore: []string{"name", "timeout"},
4646
},
4747
},
4848
})
@@ -77,7 +77,7 @@ func TestAccNetworkServicesEdgeCacheOrigin_networkServicesEdgeCacheOriginAdvance
7777
ResourceName: "google_network_services_edge_cache_origin.default",
7878
ImportState: true,
7979
ImportStateVerify: true,
80-
ImportStateVerifyIgnore: []string{"timeout", "name", "timeout"},
80+
ImportStateVerifyIgnore: []string{"name", "timeout"},
8181
},
8282
},
8383
})
@@ -97,12 +97,14 @@ resource "google_network_services_edge_cache_origin" "fallback" {
9797
retry_conditions = [
9898
"CONNECT_FAILURE",
9999
"NOT_FOUND",
100-
"HTTP_5XX"
100+
"HTTP_5XX",
101+
"FORBIDDEN",
101102
]
102103
timeout {
103104
connect_timeout = "10s"
104-
max_attempts_timeout = "10s"
105-
response_timeout = "10s"
105+
max_attempts_timeout = "20s"
106+
response_timeout = "60s"
107+
read_timeout = "5s"
106108
}
107109
}
108110

google-beta/resource_network_services_edge_cache_origin_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestAccNetworkServicesEdgeCacheOrigin_updateAndImport(t *testing.T) {
2222
ResourceName: "google_network_services_edge_cache_origin.instance",
2323
ImportState: true,
2424
ImportStateVerify: true,
25-
ImportStateVerifyIgnore: []string{"name", "timeout"},
25+
ImportStateVerifyIgnore: []string{"name"},
2626
},
2727
{
2828
Config: testAccNetworkServicesEdgeCacheOrigin_update_1(name),
@@ -31,7 +31,7 @@ func TestAccNetworkServicesEdgeCacheOrigin_updateAndImport(t *testing.T) {
3131
ResourceName: "google_network_services_edge_cache_origin.instance",
3232
ImportState: true,
3333
ImportStateVerify: true,
34-
ImportStateVerifyIgnore: []string{"name", "timeout"},
34+
ImportStateVerifyIgnore: []string{"name"},
3535
},
3636
},
3737
})
@@ -46,6 +46,7 @@ func testAccNetworkServicesEdgeCacheOrigin_update_0(name string) string {
4646
labels = {
4747
a = "b"
4848
}
49+
retry_conditions = ["NOT_FOUND"]
4950
timeout {
5051
connect_timeout = "10s"
5152
}
@@ -59,8 +60,12 @@ func testAccNetworkServicesEdgeCacheOrigin_update_1(name string) string {
5960
origin_address = "gs://media-edge-fallback"
6061
description = "The default bucket for media edge test"
6162
max_attempts = 3
63+
retry_conditions = ["FORBIDDEN"]
6264
timeout {
6365
connect_timeout = "9s"
66+
max_attempts_timeout = "14s"
67+
response_timeout = "29s"
68+
read_timeout = "13s"
6469
}
6570
}
6671
`, name)

website/docs/r/network_services_edge_cache_origin.html.markdown

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ resource "google_network_services_edge_cache_origin" "fallback" {
6262
retry_conditions = [
6363
"CONNECT_FAILURE",
6464
"NOT_FOUND",
65-
"HTTP_5XX"
65+
"HTTP_5XX",
66+
"FORBIDDEN",
6667
]
6768
timeout {
6869
connect_timeout = "10s"
69-
max_attempts_timeout = "10s"
70-
response_timeout = "10s"
70+
max_attempts_timeout = "20s"
71+
response_timeout = "60s"
72+
read_timeout = "5s"
7173
}
7274
}
7375
@@ -95,8 +97,8 @@ The following arguments are supported:
9597
* `origin_address` -
9698
(Required)
9799
A fully qualified domain name (FQDN) or IP address reachable over the public Internet, or the address of a Google Cloud Storage bucket.
98-
This address will be used as the origin for cache requests - e.g. FQDN: media-backend.example.com IPv4:35.218.1.1 IPv6:[2607:f8b0:4012:809::200e] Cloud Storage: gs://bucketname
99-
When providing an FQDN (hostname), it must be publicly resolvable (e.g. via Google public DNS) and IP addresses must be publicly routable.
100+
This address will be used as the origin for cache requests - e.g. FQDN: media-backend.example.com, IPv4: 35.218.1.1, IPv6: 2607:f8b0:4012:809::200e, Cloud Storage: gs://bucketname
101+
When providing an FQDN (hostname), it must be publicly resolvable (e.g. via Google public DNS) and IP addresses must be publicly routable. It must not contain a protocol (e.g., https://) and it must not contain any slashes.
100102
If a Cloud Storage bucket is provided, it must be in the canonical "gs://bucketname" format. Other forms, such as "storage.googleapis.com", will be rejected.
101103

102104
* `name` -
@@ -135,8 +137,8 @@ The following arguments are supported:
135137
retryConditions and failoverOrigin to control its own cache fill failures.
136138
The total number of allowed attempts to cache fill across this and failover origins is limited to four.
137139
The total time allowed for cache fill attempts across this and failover origins can be controlled with maxAttemptsTimeout.
138-
The last valid response from an origin will be returned to the client.
139-
If no origin returns a valid response, an HTTP 503 will be returned to the client.
140+
The last valid, non-retried response from all origins will be returned to the client.
141+
If no origin returns a valid response, an HTTP 502 will be returned to the client.
140142
Defaults to 1. Must be a value greater than 0 and less than 4.
141143

142144
* `failover_origin` -
@@ -160,7 +162,8 @@ The following arguments are supported:
160162
- GATEWAY_ERROR: Similar to 5xx, but only applies to response codes 502, 503 or 504.
161163
- RETRIABLE_4XX: Retry for retriable 4xx response codes, which include HTTP 409 (Conflict) and HTTP 429 (Too Many Requests)
162164
- NOT_FOUND: Retry if the origin returns a HTTP 404 (Not Found). This can be useful when generating video content, and the segment is not available yet.
163-
Each value may be one of `CONNECT_FAILURE`, `HTTP_5XX`, `GATEWAY_ERROR`, `RETRIABLE_4XX`, and `NOT_FOUND`.
165+
- FORBIDDEN: Retry if the origin returns a HTTP 403 (Forbidden).
166+
Each value may be one of `CONNECT_FAILURE`, `HTTP_5XX`, `GATEWAY_ERROR`, `RETRIABLE_4XX`, `NOT_FOUND`, and `FORBIDDEN`.
164167

165168
* `timeout` -
166169
(Optional)
@@ -175,18 +178,30 @@ The following arguments are supported:
175178

176179
* `connect_timeout` -
177180
(Optional)
178-
The maximum duration to wait for the origin connection to be established, including DNS lookup, TLS handshake and TCP/QUIC connection establishment.
181+
The maximum duration to wait for a single origin connection to be established, including DNS lookup, TLS handshake and TCP/QUIC connection establishment.
179182
Defaults to 5 seconds. The timeout must be a value between 1s and 15s.
183+
The connectTimeout capped by the deadline set by the request's maxAttemptsTimeout. The last connection attempt may have a smaller connectTimeout in order to adhere to the overall maxAttemptsTimeout.
180184

181185
* `max_attempts_timeout` -
182186
(Optional)
183-
The maximum time across all connection attempts to the origin, including failover origins, before returning an error to the client. A HTTP 503 will be returned if the timeout is reached before a response is returned.
184-
Defaults to 5 seconds. The timeout must be a value between 1s and 15s.
187+
The maximum time across all connection attempts to the origin, including failover origins, before returning an error to the client. A HTTP 504 will be returned if the timeout is reached before a response is returned.
188+
Defaults to 15 seconds. The timeout must be a value between 1s and 30s.
189+
If a failoverOrigin is specified, the maxAttemptsTimeout of the first configured origin sets the deadline for all connection attempts across all failoverOrigins.
185190

186191
* `response_timeout` -
187192
(Optional)
188-
The maximum duration to wait for data to arrive when reading from the HTTP connection/stream.
189-
Defaults to 5 seconds. The timeout must be a value between 1s and 30s.
193+
The maximum duration to wait for the last byte of a response to arrive when reading from the HTTP connection/stream.
194+
Defaults to 30 seconds. The timeout must be a value between 1s and 120s.
195+
The responseTimeout starts after the connection has been established.
196+
This also applies to HTTP Chunked Transfer Encoding responses, and/or when an open-ended Range request is made to the origin. Origins that take longer to write additional bytes to the response than the configured responseTimeout will result in an error being returned to the client.
197+
If the response headers have already been written to the connection, the response will be truncated and logged.
198+
199+
* `read_timeout` -
200+
(Optional)
201+
The maximum duration to wait between reads of a single HTTP connection/stream.
202+
Defaults to 15 seconds. The timeout must be a value between 1s and 30s.
203+
The readTimeout is capped by the responseTimeout. All reads of the HTTP connection/stream must be completed by the deadline set by the responseTimeout.
204+
If the response headers have already been written to the connection, the response will be truncated and logged.
190205

191206
## Attributes Reference
192207

0 commit comments

Comments
 (0)