Skip to content

Commit 5524f13

Browse files
author
Kevin Phuong
committed
Prepare a Media CDN custom headers sample for inclusion in C.G.C. documentation
1 parent 5a7506e commit 5524f13

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

media_cdn/custom_headers/main.tf

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# Terraform Registry: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/network_services_edge_cache_service
18+
# Google Cloud Documentation
19+
# 1. https://cloud.google.com/media-cdn/docs/quickstart#create-service
20+
# 2. https://cloud.google.com/media-cdn/docs/origins#cloud-storage-origins
21+
22+
# [START mediacdn_custom_headers_parent_tag]
23+
resource "random_id" "unique_suffix" {
24+
byte_length = 8
25+
}
26+
27+
resource "google_storage_bucket" "default" {
28+
name = "my-bucket-${random_id.unique_suffix.hex}"
29+
location = "US"
30+
force_destroy = true
31+
uniform_bucket_level_access = true
32+
}
33+
34+
resource "google_network_services_edge_cache_origin" "default" {
35+
name = "cloud-storage-origin"
36+
origin_address = "gs://my-bucket-${random_id.unique_suffix.hex}"
37+
}
38+
39+
resource "google_network_services_edge_cache_service" "default" {
40+
name = "cloud-media-service"
41+
routing {
42+
host_rule {
43+
hosts = ["googlecloudexample.com"]
44+
path_matcher = "routes"
45+
}
46+
path_matcher {
47+
name = "routes"
48+
route_rule {
49+
description = "a default route rule with low priority"
50+
priority = 10
51+
match_rule {
52+
prefix_match = "/"
53+
}
54+
origin = google_network_services_edge_cache_origin.default.name
55+
route_action {
56+
cdn_policy {
57+
cache_mode = "CACHE_ALL_STATIC"
58+
default_ttl = "3600s"
59+
}
60+
}
61+
header_action {
62+
response_header_to_add {
63+
header_name = "x-cache-status"
64+
header_value = "{cdn_cache_status}"
65+
}
66+
}
67+
}
68+
# [START mediacdn_custom_headers_route]
69+
route_rule {
70+
description = "video routes"
71+
priority = 1
72+
match_rule {
73+
prefix_match = "/video/"
74+
}
75+
origin = google_network_services_edge_cache_origin.default.name
76+
header_action {
77+
response_header_to_add {
78+
# Return the country (or region) associated with the client's IP address.
79+
header_name = "client-geo"
80+
header_value = "{client_region}"
81+
replace = true
82+
}
83+
request_header_to_add {
84+
# Inform the upstream origin server that the request is from Media CDN.
85+
header_name = "x-downstream-cdn"
86+
header_value = "Media CDN"
87+
}
88+
response_header_to_remove {
89+
header_name = "X-User-ID"
90+
}
91+
response_header_to_remove {
92+
header_name = "X-Other-Internal-Header"
93+
}
94+
}
95+
}
96+
# [END mediacdn_custom_headers_route]
97+
}
98+
}
99+
}
100+
# [END mediacdn_custom_headers_parent_tag]

media_cdn/custom_headers/test.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: blueprints.cloud.google.com/v1alpha1
16+
kind: BlueprintTest
17+
metadata:
18+
name: media_cdn_custom_headers
19+
spec:
20+
skip: true

0 commit comments

Comments
 (0)