Skarvion
Skarvion

Reputation: 82

How to set up different environment variable using Firebase App Hosting

I'm new to Firebase and I'm planning to create 2 Firebase projects, 1 for test environment and 1 for production environment. I want to deploy a NextJS web app and while I understand that I can use the same codebase and link it to 2 projects, I can only see that in this doc, it's reliant on apphosting.yaml for environment variables and secrets, but it will be checked in git. So that means we only have 1 set of values regardless of which Firebase project we're in.

How do I create different sets of env variables and secrets for each project? Or am I approaching this the wrong way?

I'm still in planning stage, only reading through the documents, so I don't know how to start.

Upvotes: 3

Views: 829

Answers (3)

Abhinav S
Abhinav S

Reputation: 71

Hi there, Firebaser here

We now have official support for multiple environments! You can find more information here https://firebase.google.com/docs/app-hosting/multiple-environments

This should address your use case, take a look and let us know what you think!

Upvotes: 1

Jason
Jason

Reputation: 359

I created an apphosting.yaml and created a secret in "secret manager" named "CURRENT_ENVIRONMENT" that would have either dev or prod

apphosting.yaml

env:
  - variable: CURRENT_ENV
    secret: CURRENT_ENVIRONMENT
    availability:
      - BUILD
      - RUNTIME

Next i ran this command on each enviroment (firebase use dev & firebase use prod) to make it available.

firebase --backend {your backend id} apphosting:secrets:grantaccess CURRENT_ENVIRONMENT

Upvotes: 2

Skarvion
Skarvion

Reputation: 82

Google Cloud Secret Manager, which apphosting.yaml reads value from, can store values independently in each Firebase project. So making it possible to have different config for the same codebase.

Upvotes: 0

Related Questions