A Version
is a configuration which determine how a site is displayed. Static files are not supported at the moment.
To get more information about Version, see:
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "my-project-name"
site_id = "site-id"
}
resource "google_firebase_hosting_version" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
config {
redirects {
glob = "/google/**"
status_code = 302
location = "https://www.google.com"
}
}
}
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 = "Redirect to Google"
}
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "my-project-name"
site_id = "site-id"
}
resource "google_firebase_hosting_version" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
config {
rewrites {
glob = "**"
path = "/index.html"
}
}
}
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 = "Path Rewrite"
}
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "my-project-name"
site_id = "site-id"
}
resource "google_cloud_run_v2_service" "default" {
provider = google-beta
project = "my-project-name"
name = "cloud-run-service-via-hosting"
location = "us-central1"
# Warning: allows all public traffic
ingress = "INGRESS_TRAFFIC_ALL"
template {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
}
}
resource "google_firebase_hosting_version" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
config {
rewrites {
glob = "/hello/**"
run {
service_id = google_cloud_run_v2_service.default.name
region = google_cloud_run_v2_service.default.location
}
}
}
}
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 = "Cloud Run Integration"
}
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "my-project-name"
site_id = "site-id"
}
resource "google_storage_bucket" "bucket" {
provider = google-beta
project = "my-project-name"
name = "site-id-function-source" # Every bucket name must be globally unique
location = "US"
uniform_bucket_level_access = true
}
resource "google_storage_bucket_object" "object" {
provider = google-beta
name = "function-source.zip"
bucket = google_storage_bucket.bucket.name
source = "function-source.zip" # Add path to the zipped function source code
}
resource "google_cloudfunctions_function" "function" {
provider = google-beta
project = "my-project-name"
name = "cloud-function-via-hosting"
description = "A Cloud Function connected to Firebase Hosing"
runtime = "nodejs16"
available_memory_mb = 128
source_archive_bucket = google_storage_bucket.bucket.name
source_archive_object = google_storage_bucket_object.object.name
trigger_http = true
entry_point = "helloHttp"
}
resource "google_firebase_hosting_version" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
config {
rewrites {
glob = "/hello/**"
function = google_cloudfunctions_function.function.name
}
}
}
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 = "Cloud Functions Integration"
}
The following arguments are supported:
site_id
-
(Required)
Required. The ID of the site in which to create this Version.config
-
(Optional)
The configuration for the behavior of the site. This configuration exists in the firebase.json
file.
Structure is documented below.rewrites
-
(Optional)
An array of objects (called rewrite rules), where each rule specifies a URL pattern that, if matched to the
request URL path, triggers Hosting to respond as if the service were given the specified destination URL.
Structure is documented below.
redirects
-
(Optional)
An array of objects (called redirect rules), where each rule specifies a URL pattern that, if matched to the request URL path,
triggers Hosting to respond with a redirect to the specified destination path.
Structure is documented below.
glob
-
(Optional)
The user-supplied glob to match against the request URL path.
regex
-
(Optional)
The user-supplied RE2 regular expression to match against the request URL path.
path
-
(Optional)
The URL path to rewrite the request to.
function
-
(Optional)
The function to proxy requests to. Must match the exported function name exactly.
run
-
(Optional)
The request will be forwarded to Cloud Run.
Structure is documented below.
service_id
-
(Required)
User-defined ID of the Cloud Run service.
region
-
(Optional)
Optional. User-provided region where the Cloud Run service is hosted. Defaults to us-central1
if not supplied.
glob
-
(Optional)
The user-supplied glob to match against the request URL path.
regex
-
(Optional)
The user-supplied RE2 regular expression to match against the request URL path.
status_code
-
(Required)
The status HTTP code to return in the response. It must be a valid 3xx status code.
location
-
(Required)
The value to put in the HTTP location header of the response.
The location can contain capture group values from the pattern using a : prefix to identify
the segment and an optional * to capture the rest of the URL. For example:
redirects {
glob = "/:capture*"
status_code = 302
location = "https://example.com/foo/:capture"
}
In addition to the arguments listed above, the following computed attributes are exported:
id
- an identifier for the resource with format sites/{{site_id}}/versions/{{version_id}}
name
-
The fully-qualified resource name for the version, in the format:
sites/SITE_ID/versions/VERSION_ID
version_id
-
The ID for the version as in sites/SITE_ID/versions/VERSION_ID
This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.delete
- Default is 20 minutes.Version can be imported using any of these accepted formats:
sites/{{site_id}}/versions/{{version_id}}
{{site_id}}/{{version_id}}
In Terraform v1.5.0 and later, use an import
block to import Version using one of the formats above. For example:
import {
id = "sites/{{site_id}}/versions/{{version_id}}"
to = google_firebase_hosting_version.default
}
When using the terraform import
command, Version can be imported using one of the formats above. For example:
$ terraform import google_firebase_hosting_version.default sites/{{site_id}}/versions/{{version_id}}
$ terraform import google_firebase_hosting_version.default {{site_id}}/{{version_id}}