Skip to content

Commit ab58ebd

Browse files
add default_route_action to regional url map under path_matcher (#14081) (#1014)
[upstream:9d9055083097647aad88f731351ff9a8e91d1c2b] Signed-off-by: Modular Magician <[email protected]>
1 parent db02379 commit ab58ebd

File tree

4 files changed

+279
-0
lines changed

4 files changed

+279
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
resource "google_compute_region_url_map" "regionurlmap" {
2+
region = "us-central1"
3+
4+
name = "regionurlmap-${local.name_suffix}"
5+
description = "a description"
6+
default_service = google_compute_region_backend_service.home.id
7+
8+
host_rule {
9+
hosts = ["mysite.com"]
10+
path_matcher = "allpaths"
11+
}
12+
13+
path_matcher {
14+
name = "allpaths"
15+
16+
default_route_action {
17+
cors_policy {
18+
disabled = false
19+
allow_credentials = true
20+
allow_headers = [
21+
"foobar"
22+
]
23+
allow_methods = [
24+
"GET",
25+
"POST",
26+
]
27+
allow_origins = [
28+
"example.com"
29+
]
30+
expose_headers = [
31+
"foobar"
32+
]
33+
max_age = 60
34+
}
35+
fault_injection_policy {
36+
abort {
37+
http_status = 500
38+
percentage = 0.5
39+
}
40+
delay {
41+
fixed_delay {
42+
nanos = 500
43+
seconds = 0
44+
}
45+
percentage = 0.5
46+
}
47+
}
48+
request_mirror_policy {
49+
backend_service = google_compute_region_backend_service.home.id
50+
}
51+
retry_policy {
52+
num_retries = 3
53+
per_try_timeout {
54+
nanos = 500
55+
seconds = 0
56+
}
57+
retry_conditions = [
58+
"5xx",
59+
"gateway-error",
60+
]
61+
}
62+
timeout {
63+
nanos = 500
64+
seconds = 0
65+
}
66+
url_rewrite {
67+
host_rewrite = "dev.example.com"
68+
path_prefix_rewrite = "/v1/api/"
69+
}
70+
weighted_backend_services {
71+
backend_service = google_compute_region_backend_service.home.id
72+
header_action {
73+
request_headers_to_add {
74+
header_name = "foo-request-1"
75+
header_value = "bar"
76+
replace = true
77+
}
78+
request_headers_to_add {
79+
header_name = "foo-request-2"
80+
header_value = "bar"
81+
replace = true
82+
}
83+
request_headers_to_remove = ["fizz"]
84+
response_headers_to_add {
85+
header_name = "foo-response-1"
86+
header_value = "bar"
87+
replace = true
88+
}
89+
response_headers_to_add {
90+
header_name = "foo-response-2"
91+
header_value = "bar"
92+
replace = true
93+
}
94+
response_headers_to_remove = ["buzz"]
95+
}
96+
weight = 100
97+
}
98+
weighted_backend_services {
99+
backend_service = google_compute_region_backend_service.login.id
100+
header_action {
101+
request_headers_to_add {
102+
header_name = "foo-request-1"
103+
header_value = "bar"
104+
replace = true
105+
}
106+
request_headers_to_add {
107+
header_name = "foo-request-2"
108+
header_value = "bar"
109+
replace = true
110+
}
111+
request_headers_to_remove = ["fizz"]
112+
response_headers_to_add {
113+
header_name = "foo-response-1"
114+
header_value = "bar"
115+
replace = true
116+
}
117+
response_headers_to_add {
118+
header_name = "foo-response-2"
119+
header_value = "bar"
120+
replace = true
121+
}
122+
response_headers_to_remove = ["buzz"]
123+
}
124+
weight = 200
125+
}
126+
}
127+
128+
path_rule {
129+
paths = ["/home"]
130+
service = google_compute_region_backend_service.home.id
131+
}
132+
133+
path_rule {
134+
paths = ["/login"]
135+
service = google_compute_region_backend_service.login.id
136+
}
137+
}
138+
139+
test {
140+
service = google_compute_region_backend_service.home.id
141+
host = "hi.com"
142+
path = "/home"
143+
}
144+
}
145+
146+
resource "google_compute_region_backend_service" "login" {
147+
region = "us-central1"
148+
149+
name = "login-${local.name_suffix}"
150+
protocol = "HTTP"
151+
load_balancing_scheme = "INTERNAL_MANAGED"
152+
timeout_sec = 10
153+
154+
health_checks = [google_compute_region_health_check.default.id]
155+
}
156+
157+
resource "google_compute_region_backend_service" "home" {
158+
region = "us-central1"
159+
160+
name = "home-${local.name_suffix}"
161+
protocol = "HTTP"
162+
load_balancing_scheme = "INTERNAL_MANAGED"
163+
timeout_sec = 10
164+
165+
health_checks = [google_compute_region_health_check.default.id]
166+
}
167+
168+
resource "google_compute_region_health_check" "default" {
169+
region = "us-central1"
170+
171+
name = "health-check-${local.name_suffix}"
172+
check_interval_sec = 1
173+
timeout_sec = 1
174+
http_health_check {
175+
port = 80
176+
request_path = "/"
177+
}
178+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Region Url Map Path Matcher Default Route Action - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="region_url_map_path_matcher_default_route_action" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```

0 commit comments

Comments
 (0)