I am working on using Terraform to create a Firestore DB with a custom name and populate it with a few documents.
If I don't specify a custom name or specify "(default)" everything works perfectly. But if I try to create with a custom db name, I get the following error in Terraform Cloud:
Error: Error creating Document: googleapi: Error 400: Missing routing header.
Please fill in the request header with format
x-goog-request-params:project_id=my-project1234&database_id=my-db.
Please refer to https://firebase.google.com/docs/firestore/manage-databases#access_a_named_database_with_a_client_library for more details.
The doc could not be less helpful:
A named database includes any database not named (default). By default, the Firebase SDKs and Google API Client Libraries connect to the (default) Cloud Firestore database in a project. To create a client connected to a named database, set the database ID when you instantiate a client.
My code:
Terraform:
resource "google_project_service" "firestore" {
project = var.project_id
service = "firestore.googleapis.com"
timeouts {
create = "30m"
update = "40m"
}
disable_dependent_services = false
disable_on_destroy = false
}
resource "google_firestore_database" "database" {
project = var.project_id
name = var.database_name
location_id = var.region
type = "FIRESTORE_NATIVE"
depends_on = [google_project_service.firestore]
}
locals {
DOC1 = jsondecode(file("${path.module}/collections/${var.collection1}/${var.document1}.json"))
}
resource "google_firestore_document" "document" {
project = var.project_id
database = google_firestore_database.database.name
collection = var.collection1
document_id = var.document1
fields = jsonencode(local.DOC1)
}
Question:
How do I add a request header in terraform or what else can I do to get past this error?