Files
solution_architecture_agent/skills/google-cloud-iac-patterns/references/firestore.md
Jonathan Boniface c84dbdea20 feat: the solution architecture agent on the shared Execution engine
The reference agent's subject, cloud solution architecture, as an agent in
the operating model agent's pattern: the Execution engine (from
orchestration_engine) and one Workflow in app/solution_architecture,
built for the settings and provider bundle by assembly.workflow_for.

Copied from gcp_solution_architecture_agent at 8b397cd without its own
engine: its role files, Skills, provider bundle, ADRs, vocabulary, scripts
and evaluation datasets. The image takes the engine from a named build
context and installs Terraform. It is called through the Orchestration
engine, and its files are what the operating model agent digests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 19:49:28 +01:00

2.5 KiB

Firestore

A Firestore database in Native mode, with point-in-time recovery, a scheduled backup, a composite index and the grant a workload needs.

  • A project's first database is named (default). Any other name creates an additional database, which clients must name when they connect.
  • location_id is a region or a multi-region such as eur3, and cannot be changed afterwards.
  • type is FIRESTORE_NATIVE or DATASTORE_MODE, and cannot be changed once the database holds data.
  • delete_protection_state is the guard in the API; deletion_policy = "DELETE" is needed before Terraform will remove a database at all.
  • point_in_time_recovery_enablement keeps seven days of versions. A backup schedule is separate and keeps whole backups for retention, in seconds with an s.
  • A workload reads and writes with roles/datastore.user, granted on the project. There is no per-database role; restrict with an IAM condition on the database name.
variable "project_id" {
  type        = string
  description = "Project to deploy into."
}

variable "region" {
  type        = string
  description = "Region for regional resources."
}

variable "app_service_account_email" {
  type        = string
  description = "Service account of the workload that uses the database."
}

resource "google_firestore_database" "app" {
  project     = var.project_id
  name        = "app"
  location_id = var.region
  type        = "FIRESTORE_NATIVE"

  concurrency_mode                  = "OPTIMISTIC"
  point_in_time_recovery_enablement = "POINT_IN_TIME_RECOVERY_ENABLED"
  delete_protection_state           = "DELETE_PROTECTION_ENABLED"
  deletion_policy                   = "ABANDON"
}

resource "google_firestore_backup_schedule" "daily" {
  project   = var.project_id
  database  = google_firestore_database.app.name
  retention = "1209600s"

  daily_recurrence {}
}

resource "google_firestore_index" "orders_by_customer" {
  project    = var.project_id
  database   = google_firestore_database.app.name
  collection = "orders"

  fields {
    field_path = "customer_id"
    order      = "ASCENDING"
  }

  fields {
    field_path = "created_at"
    order      = "DESCENDING"
  }
}

resource "google_project_iam_member" "app_uses_firestore" {
  project = var.project_id
  role    = "roles/datastore.user"
  member  = "serviceAccount:${var.app_service_account_email}"

  condition {
    title      = "only-the-app-database"
    expression = "resource.name == \"${google_firestore_database.app.id}\" || resource.name.startsWith(\"${google_firestore_database.app.id}/\")"
  }
}