From 93c2b6e54aed3c54aed94e92875dd06b863d49f2 Mon Sep 17 00:00:00 2001 From: Lingkai Shen Date: Tue, 10 Dec 2024 14:51:32 -0500 Subject: [PATCH] Add headers to Hosting Version (#12527) --- mmv1/products/firebasehosting/Version.yaml | 95 ++++++++++++++----- .../firebasehosting_version_headers.tf.tmpl | 26 +++++ ...ebasehosting_version_headers_regex.tf.tmpl | 26 +++++ 3 files changed, 122 insertions(+), 25 deletions(-) create mode 100644 mmv1/templates/terraform/examples/firebasehosting_version_headers.tf.tmpl create mode 100644 mmv1/templates/terraform/examples/firebasehosting_version_headers_regex.tf.tmpl diff --git a/mmv1/products/firebasehosting/Version.yaml b/mmv1/products/firebasehosting/Version.yaml index d25cfb666b9c..3e67be096cdf 100644 --- a/mmv1/products/firebasehosting/Version.yaml +++ b/mmv1/products/firebasehosting/Version.yaml @@ -25,7 +25,7 @@ base_url: 'sites/{{site_id}}/versions' self_link: 'sites/{{site_id}}/versions/{{version_id}}' create_url: 'sites/{{site_id}}/versions' exclude_delete: true - # not updatable +# not updatable immutable: true import_format: - 'sites/{{site_id}}/versions/{{version_id}}' @@ -46,6 +46,20 @@ examples: site_id: 'site-id' test_env_vars: project_id: 'PROJECT_NAME' + - name: 'firebasehosting_version_headers' + primary_resource_id: 'default' + min_version: 'beta' + vars: + site_id: 'site-id' + test_env_vars: + project_id: 'PROJECT_NAME' + - name: 'firebasehosting_version_headers_regex' + primary_resource_id: 'default' + min_version: 'beta' + vars: + site_id: 'site-id' + test_env_vars: + project_id: 'PROJECT_NAME' - name: 'firebasehosting_version_path' primary_resource_id: 'default' min_version: 'beta' @@ -126,45 +140,45 @@ properties: description: The user-supplied glob to match against the request URL path. min_version: 'beta' - exactly_one_of: - - 'glob' - - 'regex' + # exactly_one_of: + # - 'glob' + # - 'regex' - name: 'regex' type: String description: The user-supplied RE2 regular expression to match against the request URL path. min_version: 'beta' - exactly_one_of: - - 'glob' - - 'regex' + # exactly_one_of: + # - 'glob' + # - 'regex' - name: 'path' type: String description: The URL path to rewrite the request to. min_version: 'beta' - exactly_one_of: - - 'path' - - 'function' - - 'run' + # exactly_one_of: + # - 'path' + # - 'function' + # - 'run' - name: 'function' type: String description: The function to proxy requests to. Must match the exported function name exactly. min_version: 'beta' - exactly_one_of: - - 'path' - - 'function' - - 'run' + # exactly_one_of: + # - 'path' + # - 'function' + # - 'run' - name: 'run' type: NestedObject description: The request will be forwarded to Cloud Run. min_version: 'beta' - exactly_one_of: - - 'path' - - 'function' - - 'run' + # exactly_one_of: + # - 'path' + # - 'function' + # - 'run' properties: - name: 'serviceId' type: String @@ -194,18 +208,18 @@ properties: description: The user-supplied glob to match against the request URL path. min_version: 'beta' - exactly_one_of: - - 'glob' - - 'regex' + # exactly_one_of: + # - 'glob' + # - 'regex' - name: 'regex' type: String description: The user-supplied RE2 regular expression to match against the request URL path. min_version: 'beta' - exactly_one_of: - - 'glob' - - 'regex' + # exactly_one_of: + # - 'glob' + # - 'regex' - name: 'statusCode' type: Integer description: @@ -229,3 +243,34 @@ properties: ``` min_version: 'beta' required: true + - name: 'headers' + type: Array + description: | + An array of objects, where each object specifies a URL pattern that, if matched to the request URL path, + triggers Hosting to apply the specified custom response headers. + item_type: + description: | + A Header specifies a URL pattern that, if matched to the request URL path, triggers Hosting + to apply the specified custom response headers. + type: NestedObject + properties: + - name: 'glob' + type: String + description: + The user-supplied glob to match against the request URL path. + # exactly_one_of: + # - 'glob' + # - 'regex' + - name: 'regex' + type: String + description: + The user-supplied RE2 regular expression to match against the + request URL path. + # exactly_one_of: + # - 'glob' + # - 'regex' + - name: 'headers' + type: KeyValuePairs + description: | + The additional headers to add to the response. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }. + required: true diff --git a/mmv1/templates/terraform/examples/firebasehosting_version_headers.tf.tmpl b/mmv1/templates/terraform/examples/firebasehosting_version_headers.tf.tmpl new file mode 100644 index 000000000000..1e21287b9d6d --- /dev/null +++ b/mmv1/templates/terraform/examples/firebasehosting_version_headers.tf.tmpl @@ -0,0 +1,26 @@ +resource "google_firebase_hosting_site" "default" { + provider = google-beta + project = "{{index $.TestEnvVars "project_id"}}" + site_id = "{{index $.Vars "site_id"}}" +} + +resource "google_firebase_hosting_version" "default" { + provider = google-beta + site_id = google_firebase_hosting_site.default.site_id + config { + headers { + # Also okay to use regex + glob = "/headers/**" + headers = { + my-header = "my-value" + } + } + } +} + +resource "google_firebase_hosting_release" "default" { + provider = google-beta + site_id = google_firebase_hosting_site.default.site_id + version_name = google_firebase_hosting_version.default.name + message = "With custom headers" +} \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/firebasehosting_version_headers_regex.tf.tmpl b/mmv1/templates/terraform/examples/firebasehosting_version_headers_regex.tf.tmpl new file mode 100644 index 000000000000..89d9ebe06502 --- /dev/null +++ b/mmv1/templates/terraform/examples/firebasehosting_version_headers_regex.tf.tmpl @@ -0,0 +1,26 @@ +resource "google_firebase_hosting_site" "default" { + provider = google-beta + project = "{{index $.TestEnvVars "project_id"}}" + site_id = "{{index $.Vars "site_id"}}" +} + +resource "google_firebase_hosting_version" "default" { + provider = google-beta + site_id = google_firebase_hosting_site.default.site_id + config { + headers { + # Also okay to use glob + regex = "^~/headers$" + headers = { + my-header = "my-value" + } + } + } +} + +resource "google_firebase_hosting_release" "default" { + provider = google-beta + site_id = google_firebase_hosting_site.default.site_id + version_name = google_firebase_hosting_version.default.name + message = "With custom headers" +} \ No newline at end of file