'Error when creating the firebase project using terraform
I am trying to create a create a firebase project using terraform. I am new in it and need some guidance in setting up the firebase project. I am facing an issue
Error creating Project: googleapi: Error 403: Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the firebase.googleapis.com. We recommend configuring the billing/quota_project setting in gcloud or using a service account through the auth/impersonate_service_account setting. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.
terraform code
resource "google_project" "test-project" {
provider = google-beta
project_id = "test-project"
name = "Test Project"
}
resource "google_firebase_project" "test-project" {
provider = google-beta
project = google_project.test-project.project_id
}
provider "google" {
project = "test-project"
region = var.region
}
Solution 1:[1]
Creating the service account in the Terraform admin project, e. g.
gcloud iam service-accounts create terraform \
--display-name "Terraform admin account"
gcloud iam service-accounts keys create ${TF_CREDS} \
--iam-account terraform@${TF_ADMIN}.iam.gserviceaccount.com
and granting permissions to this service account should solve it. An example of providing permissions from the documentation:
gcloud projects add-iam-policy-binding ${TF_ADMIN} \
--member serviceAccount:terraform@${TF_ADMIN}.iam.gserviceaccount.com \
--role roles/viewer
gcloud projects add-iam-policy-binding ${TF_ADMIN} \
--member serviceAccount:terraform@${TF_ADMIN}.iam.gserviceaccount.com \
--role roles/storage.admin
You can follow the instructions about creating Google Cloud projects in Terraform
Projects you create in GCP are the same as you create in Firebase.
Solution 2:[2]
I found another solution to create a firebase project with terraform in the firestore documentation:
To provision a Cloud Firestore database with Terraform, use the google_app_engine_application resource. Set the database_type to CLOUD_FIRESTORE or CLOUD_DATASTORE_COMPATIBILITY.
For example, the following Terraform configuration file creates a new project and provisions a Cloud Firestore database:
provider "google" {
credentials = file("credentials-file")
}
resource "google_project" "my_project" {
name = "My Project"
project_id = "project-id"
}
resource "google_app_engine_application" "app" {
project = google_project.my_project.project_id
location_id = "location"
database_type = "CLOUD_FIRESTORE"
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Farid Shumbar |
Solution 2 | ThdK |