Skip to content

Commit fd2ed72

Browse files
REGION URL MAP: add support for header_action and path_matcher.header_action in google_compute_region_url_map (#15052)
1 parent a80f496 commit fd2ed72

File tree

2 files changed

+276
-0
lines changed

2 files changed

+276
-0
lines changed

mmv1/products/compute/RegionUrlMap.yaml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,64 @@ properties:
270270
item_type:
271271
type: NestedObject
272272
properties:
273+
- name: 'headerAction'
274+
type: NestedObject
275+
description: |
276+
Specifies changes to request and response headers that need to take effect for the selected backendService.
277+
headerAction specified here take effect before headerAction in the enclosing HttpRouteRule, PathMatcher and UrlMap.
278+
headerAction is not supported for load balancers that have their loadBalancingScheme set to EXTERNAL.
279+
Not supported when the URL map is bound to a target gRPC proxy that has validateForProxyless field set to true.
280+
properties:
281+
- name: 'requestHeadersToRemove'
282+
type: Array
283+
description: |
284+
A list of header names for headers that need to be removed from the request before forwarding the request to the backendService.
285+
item_type:
286+
type: String
287+
- name: 'requestHeadersToAdd'
288+
type: Array
289+
description: |
290+
Headers to add to a matching request before forwarding the request to the backendService.
291+
item_type:
292+
type: NestedObject
293+
properties:
294+
- name: 'headerName'
295+
type: String
296+
description: 'The name of the header.'
297+
- name: 'headerValue'
298+
type: String
299+
description: 'The value of the header to add.'
300+
- name: 'replace'
301+
type: Boolean
302+
description: |
303+
If false, headerValue is appended to any values that already exist for the header. If true, headerValue is set for the header, discarding any values that were set for that header.
304+
The default value is false.
305+
default_value: false
306+
- name: 'responseHeadersToRemove'
307+
type: Array
308+
description: |
309+
A list of header names for headers that need to be removed from the response before sending the response back to the client.
310+
item_type:
311+
type: String
312+
- name: 'responseHeadersToAdd'
313+
type: Array
314+
description: |
315+
Headers to add the response before sending the response back to the client.
316+
item_type:
317+
type: NestedObject
318+
properties:
319+
- name: 'headerName'
320+
type: String
321+
description: 'The name of the header.'
322+
- name: 'headerValue'
323+
type: String
324+
description: 'The value of the header to add.'
325+
- name: 'replace'
326+
type: Boolean
327+
description: |
328+
If false, headerValue is appended to any values that already exist for the header. If true, headerValue is set for the header, discarding any values that were set for that header.
329+
The default value is false.
330+
default_value: false
273331
- name: 'defaultService'
274332
type: ResourceRef
275333
description: |
@@ -2571,3 +2629,61 @@ properties:
25712629
- 'default_route_action.0.fault_injection_policy.0.abort.0.percentage'
25722630
validation:
25732631
function: 'validation.FloatBetween(0, 100)'
2632+
- name: 'headerAction'
2633+
type: NestedObject
2634+
description: |
2635+
Specifies changes to request and response headers that need to take effect for the selected backendService.
2636+
headerAction specified here take effect before headerAction in the enclosing HttpRouteRule, PathMatcher and UrlMap.
2637+
headerAction is not supported for load balancers that have their loadBalancingScheme set to EXTERNAL.
2638+
Not supported when the URL map is bound to a target gRPC proxy that has validateForProxyless field set to true.
2639+
properties:
2640+
- name: 'requestHeadersToRemove'
2641+
type: Array
2642+
description: |
2643+
A list of header names for headers that need to be removed from the request before forwarding the request to the backendService.
2644+
item_type:
2645+
type: String
2646+
- name: 'requestHeadersToAdd'
2647+
type: Array
2648+
description: |
2649+
Headers to add to a matching request before forwarding the request to the backendService.
2650+
item_type:
2651+
type: NestedObject
2652+
properties:
2653+
- name: 'headerName'
2654+
type: String
2655+
description: 'The name of the header.'
2656+
- name: 'headerValue'
2657+
type: String
2658+
description: 'The value of the header to add.'
2659+
- name: 'replace'
2660+
type: Boolean
2661+
description: |
2662+
If false, headerValue is appended to any values that already exist for the header. If true, headerValue is set for the header, discarding any values that were set for that header.
2663+
The default value is false.
2664+
default_value: false
2665+
- name: 'responseHeadersToRemove'
2666+
type: Array
2667+
description: |
2668+
A list of header names for headers that need to be removed from the response before sending the response back to the client.
2669+
item_type:
2670+
type: String
2671+
- name: 'responseHeadersToAdd'
2672+
type: Array
2673+
description: |
2674+
Headers to add the response before sending the response back to the client.
2675+
item_type:
2676+
type: NestedObject
2677+
properties:
2678+
- name: 'headerName'
2679+
type: String
2680+
description: 'The name of the header.'
2681+
- name: 'headerValue'
2682+
type: String
2683+
description: 'The value of the header to add.'
2684+
- name: 'replace'
2685+
type: Boolean
2686+
description: |
2687+
If false, headerValue is appended to any values that already exist for the header. If true, headerValue is set for the header, discarding any values that were set for that header.
2688+
The default value is false.
2689+
default_value: false

mmv1/third_party/terraform/services/compute/resource_compute_region_url_map_test.go

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,166 @@ import (
88
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
99
)
1010

11+
func TestAccComputeRegionUrlMap_headerAction(t *testing.T) {
12+
t.Parallel()
13+
14+
randomSuffix := acctest.RandString(t, 10)
15+
16+
acctest.VcrTest(t, resource.TestCase{
17+
PreCheck: func() { acctest.AccTestPreCheck(t) },
18+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
19+
CheckDestroy: testAccCheckComputeUrlMapDestroyProducer(t),
20+
Steps: []resource.TestStep{
21+
{
22+
Config: testAccComputeRegionUrlMap_headerAction1(randomSuffix),
23+
},
24+
{
25+
ResourceName: "google_compute_region_url_map.foobar",
26+
ImportState: true,
27+
ImportStateVerify: true,
28+
},
29+
{
30+
Config: testAccComputeRegionUrlMap_headerAction2(randomSuffix),
31+
},
32+
{
33+
ResourceName: "google_compute_region_url_map.foobar",
34+
ImportState: true,
35+
ImportStateVerify: true,
36+
},
37+
},
38+
})
39+
}
40+
41+
func testAccComputeRegionUrlMap_headerAction1(randomSuffix string) string {
42+
return fmt.Sprintf(`
43+
resource "google_compute_region_backend_service" "foobar" {
44+
region = "us-central1"
45+
name = "regionurlmap-headeraction-%s"
46+
protocol = "HTTP"
47+
load_balancing_scheme = "INTERNAL_MANAGED"
48+
health_checks = [google_compute_region_health_check.zero.self_link]
49+
}
50+
51+
resource "google_compute_region_health_check" "zero" {
52+
region = "us-central1"
53+
name = "regionurlmap-headeraction-%s"
54+
http_health_check {
55+
port = 80
56+
}
57+
}
58+
59+
resource "google_compute_region_url_map" "foobar" {
60+
region = "us-central1"
61+
name = "regionurlmap-headeraction-%s"
62+
default_service = google_compute_region_backend_service.foobar.self_link
63+
64+
// root-level header_action
65+
header_action {
66+
request_headers_to_add {
67+
header_name = "x-root-test"
68+
header_value = "foo"
69+
replace = true
70+
}
71+
}
72+
73+
host_rule {
74+
hosts = ["mysite.com"]
75+
path_matcher = "with-headers"
76+
}
77+
78+
path_matcher {
79+
name = "with-headers"
80+
default_service = google_compute_region_backend_service.foobar.self_link
81+
82+
// path_matcher-level header_action
83+
header_action {
84+
request_headers_to_add {
85+
header_name = "x-path-test"
86+
header_value = "bar"
87+
replace = true
88+
}
89+
}
90+
91+
path_rule {
92+
paths = ["/home"]
93+
service = google_compute_region_backend_service.foobar.self_link
94+
}
95+
}
96+
97+
test {
98+
host = "mysite.com"
99+
path = "/home"
100+
service = google_compute_region_backend_service.foobar.self_link
101+
}
102+
}
103+
`, randomSuffix, randomSuffix, randomSuffix)
104+
}
105+
106+
func testAccComputeRegionUrlMap_headerAction2(randomSuffix string) string {
107+
return fmt.Sprintf(`
108+
resource "google_compute_region_backend_service" "foobar" {
109+
region = "us-central1"
110+
name = "regionurlmap-headeraction-%s"
111+
protocol = "HTTP"
112+
load_balancing_scheme = "INTERNAL_MANAGED"
113+
health_checks = [google_compute_region_health_check.zero.self_link]
114+
}
115+
116+
resource "google_compute_region_health_check" "zero" {
117+
region = "us-central1"
118+
name = "regionurlmap-headeraction-%s"
119+
http_health_check {
120+
port = 80
121+
}
122+
}
123+
124+
resource "google_compute_region_url_map" "foobar" {
125+
region = "us-central1"
126+
name = "regionurlmap-headeraction-%s"
127+
default_service = google_compute_region_backend_service.foobar.self_link
128+
129+
// root-level header_action updated
130+
header_action {
131+
request_headers_to_add {
132+
header_name = "x-root-test"
133+
header_value = "baz"
134+
replace = true
135+
}
136+
}
137+
138+
host_rule {
139+
hosts = ["mysite.com"]
140+
path_matcher = "with-headers"
141+
}
142+
143+
path_matcher {
144+
name = "with-headers"
145+
default_service = google_compute_region_backend_service.foobar.self_link
146+
147+
// path_matcher-level header_action updated
148+
header_action {
149+
request_headers_to_add {
150+
header_name = "x-path-test"
151+
header_value = "qux"
152+
replace = true
153+
}
154+
}
155+
156+
path_rule {
157+
paths = ["/home", "/alt"]
158+
service = google_compute_region_backend_service.foobar.self_link
159+
}
160+
}
161+
162+
test {
163+
host = "mysite.com"
164+
path = "/alt"
165+
service = google_compute_region_backend_service.foobar.self_link
166+
}
167+
}
168+
`, randomSuffix, randomSuffix, randomSuffix)
169+
}
170+
11171
func TestAccComputeRegionUrlMap_update_path_matcher(t *testing.T) {
12172
t.Parallel()
13173

0 commit comments

Comments
 (0)