Skip to content

Commit 005a495

Browse files
committed
Prepared name-of-snippet for inclusion in C.G.C. documentation
1 parent 096cf20 commit 005a495

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* Copyright 2022 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_dynamic_compression_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, priority=10 (low)"
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_dynamic_compression_route]
69+
route_rule {
70+
description = "a route rule with dynamic compression, priority=2 (high)"
71+
priority = 2
72+
match_rule {
73+
path_template_match = "/**.m3u8" # HLS playlists
74+
}
75+
match_rule {
76+
path_template_match = "/**.mpd" # DASH manifests
77+
}
78+
origin = google_network_services_edge_cache_origin.default.name
79+
route_action {
80+
cdn_policy {
81+
cache_mode = "FORCE_CACHE_ALL"
82+
client_ttl = "300s"
83+
}
84+
compression_mode = "AUTOMATIC"
85+
}
86+
header_action {
87+
response_header_to_add {
88+
header_name = "x-cache-status"
89+
header_value = "{cdn_cache_status}"
90+
}
91+
}
92+
}
93+
# [END mediacdn_dynamic_compression_route]
94+
}
95+
}
96+
}
97+
# [END mediacdn_dynamic_compression_parent_tag]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2022 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_quickstart
19+
spec:
20+
skip: true

media_cdn/quickstart/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ resource "google_network_services_edge_cache_service" "default" {
4949
path_matcher {
5050
name = "routes"
5151
route_rule {
52-
description = "a route rule to match against"
53-
priority = 1
52+
description = "a default route rule, priority=10 (low)"
53+
priority = 10
5454
match_rule {
5555
prefix_match = "/"
5656
}

0 commit comments

Comments
 (0)