google_firebase_hosting_version

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:

Example Usage - Firebasehosting Version Redirect

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"
}

Example Usage - Firebasehosting Version Path

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"
}

Example Usage - Firebasehosting Version Cloud Run

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"
}

Example Usage - Firebasehosting Version Cloud Functions

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"
}

Argument Reference

The following arguments are supported:


The config block supports:

The rewrites block supports:

The run block supports:

The redirects block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

Version can be imported using any of these accepted formats:

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}}