A single Terraform module that allows you to build out the following Firebase components:
- Firebase project
- Firebase web app
and provides you with a formatted typescript environment file to use for Firebase intialisation in your javascript/typescript webapp.
Create an infrastructure folder with a terraform (.tf) file, pasting the following code):
module "firebase" {
source = "github.com/AndyBrownlie/terraform-firebase"
org_id = <your GCP registered organisation ID>
project_name = <project name>
region = <region>
service_account_user = <service account with Firebase creator privileges>
firebase_admin_users = [<array of user email addresses to be granted Firebase admin rights>, <..>]
firebase_config_file_path = <path/and/filename of generated Firebase options initialisation file>
env = <environment this infrastructure is for. Options are dev, test, stage or prod>
}
Run:
>terraform init
>terraform validate
>teraform plan
>terraform apply
Terraform User is the google user account used to authenticate with GCP and Firebase. To ensure you are already logged in using this google account as your GOOGLE_DEFAULT_CREDENTIALS, ensure you have run the following command
gcloud auth application-default login
- gcloud CLI
- Firebase CLI
- Terraform
- Organisation exists
- Terraform admin GCP project exists in organisation
- Terraform admin service account exists on the Terraform admin GCP project, but also added to the organisation IAM.
- Terraform User has been granted Service Account Token Creator role on the afore-mentioned Service Account IAM Binding
- creates both a GCP & Firebase project
- assigns Firebase Admin permissions to Terraform User
- creates a Firebase web app in the Firebase project
- creates a Firebase web app config
- creates a environment configuration file for js/ts Firebase app initialisation
You only need to link web app to Firebase hosting if you are using Firebase libraries direct from script, and not loaded via app package managers (eg NPM or yarn).