Firebase is an app development platform that helps build and grow apps and games. Backed by Google.

Creating Firebase project

The level of possible automation

GCP TF provider has next firebase resources:

Example of creating these resources via TF:
resource "google_firebase_project" "env" {
  provider = google-beta.applications
}

resource "google_firebase_web_app" "env_applications_fb_webapp" {
    provider        = google-beta.applications
    display_name    = format("%s %s Web-app", local.prefix, var.env_name)
    # deletion_policy = "DELETE"

    depends_on      = [google_firebase_project.env]
}

data "google_firebase_web_app_config" "env_applications_fb_webapp_config" {
  provider   = google-beta.applications
  web_app_id = google_firebase_web_app.env_applications_fb_webapp.app_id
}

resource "google_storage_bucket" "test_tf_fb_webapp_bucket" {
    provider = google-beta.applications
    name     = format("%s-env-%s-fb-webapp-bucket", local.prefix, var.env_name)
    location = "ASIA"
}

resource "google_storage_bucket_object" "default" {
    provider                = google-beta.applications
    bucket                  = google_storage_bucket.test_tf_fb_webapp_bucket.name
    name                    = "firebase-config.json"

    content                 = jsonencode({
        appId              = google_firebase_web_app.env_applications_fb_webapp.app_id
        apiKey             = data.google_firebase_web_app_config.env_applications_fb_webapp_config.api_key
        authDomain         = data.google_firebase_web_app_config.env_applications_fb_webapp_config.auth_domain
        databaseURL        = lookup(data.google_firebase_web_app_config.env_applications_fb_webapp_config, "database_url", "")
        storageBucket      = lookup(data.google_firebase_web_app_config.env_applications_fb_webapp_config, "storage_bucket", "")
        messagingSenderId  = lookup(data.google_firebase_web_app_config.env_applications_fb_webapp_config, "messaging_sender_id", "")
        measurementId      = lookup(data.google_firebase_web_app_config.env_applications_fb_webapp_config, "measurement_id", "")
    })
}

resource "google_firebase_android_app" "test_tf_fb_androidapp" {
    provider = google-beta
    display_name = format("%s %s Android-app", local.prefix, var.env_name)
    package_name = "ph.safibank.app"
}

resource "google_firebase_apple_app" "default" {
    provider = google-beta
    project = "my-project-name"
    display_name = "Display Name Basic"
    bundle_id = format("ph.safibank.app.%s", var.env_name)
}

Manual part of resources

  • Integration with Google Analytics

    • Currently GA Account cannot be created neither via terraform nor via REST API.
      The result of conversation with Google Analytics API team about the way to create GA account automatically (via the REST API):
      | Firebase Support <firebase-support@google.com>

      | … that it's not possible to create a Google Analytics account without the end user accepting a Terms of Service first
      In more detailed - here

      Available options:

      • Manually link via firebase GUI console:

        • Go to Project settings -> IntegrationsGoogle Analytics => Enable

        This will automatically create GA account. Example of result-page:

    • Create GA Account manually via GA dashboard - https://analytics.google.com/ - and then link firebase project with this GA account via REST API request:

      curl -X POST -H "Authorization: Bearer \"$(gcloud auth print-access-token)\"" \                                                                                                                                                                                ✔  at 22:30:53  
                               -H "Content-Type: application/json; charset=utf-8" \
                               -H "x-goog-user-project: safi-sandbox-firebasetest" \
                               --compressed \
                               --data '{"analyticsAccountId":"249078171"}' \
                               "https://firebase.googleapis.com/v1beta1/projects/safi-sandbox-firebasetest:addGoogleAnalytics"

You will need GA account ID - get it in GA dashboard:
Go to AdminAccount settings :

  • BigQuery Integration:

    • It’s possible to create BiqQuery resources via terraform but currently there is no way to link it with firebase project neither via terraform nor via REST API.
      The result of conversation with Firebase API Support team about the way to link Firebase project to BigQuery (via REST API):
      | Firebase Support <firebase-support@google.com>
      | … there currently is no way to do this directly via API
      In more detailed - here

      Available options:

      • Manually link via firebase GUI console:

        • Go to Project settings -> IntegrationsBigQuery => Link :

        • Next :

        • Configure integrations:
          - Export settings: Integrations :
          - Google Analytics
          - Crashlytics
          - Performance Monitoring
          - Cloud Messaging
          - Import from BigQuery :
          - Imported segments (Beta)

          => Then Link to BigQuery
          This will create BigQuery resource which will be available via GCP dashboard (in the same GCP project as Firebase project name)