Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/gcp/firestore/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ resource "google_project_service" "firestore" {
}

resource "google_firestore_database" "this" {
count = var.create_database ? 1 : 0

project = var.project_id
name = var.database_name
location_id = var.region
Expand Down
4 changes: 2 additions & 2 deletions modules/gcp/firestore/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
output "firestore_db_id" {
description = "The Firestore database resource name."
value = google_firestore_database.this.name
value = try(google_firestore_database.this[0].name, var.database_name)
}
Comment on lines 1 to 4

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When create_database = false, firestore_db_id falls back to var.database_name. That changes the output semantics from "resource attribute" to "input echo" and can be misleading (especially given the description says "resource name"). Consider returning null (or a clearly documented placeholder) when the resource isn't created, or updating the output description/name to reflect that it may simply return the configured database ID when unmanaged.

Copilot uses AI. Check for mistakes.

output "firestore_db_project" {
description = "The project that owns the Firestore database."
value = google_firestore_database.this.project
value = try(google_firestore_database.this[0].project, var.project_id)
}
6 changes: 6 additions & 0 deletions modules/gcp/firestore/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ variable "database_name" {
default = "payloadcms-poc-db"
}

variable "create_database" {
description = "Whether this module should create/manage the Firestore database. Set to false if the database already exists and is managed outside Terraform."
type = bool
default = true
}

variable "api_service_name" {
description = "The Google API service to enable before creating Firestore."
type = string
Expand Down
22 changes: 19 additions & 3 deletions workspaces/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,27 @@ module "gcp_budget" {
depends_on = [module.gcp_project_apis]
}

module "gcp_firestore" {
# production firestore instance (uncomment when needed)
# module "gcp_firestore" {
# source = "../../modules/gcp/firestore"
#
# project_id = var.gcp_project_id
# region = var.gcp_region
# database_name = "prod-payloadcms-db"
# create_database = var.create_database
# delete_protection_state = var.firestore_delete_protection_state
#
# depends_on = [module.gcp_project_apis]
# }

module "dev_gcp_firestore" {
source = "../../modules/gcp/firestore"

project_id = var.gcp_project_id
region = var.gcp_region
project_id = var.gcp_project_id
region = var.gcp_region
database_name = "dev-payloadcms-db"
create_database = var.create_database
delete_protection_state = "DELETE_PROTECTION_DISABLED"

Comment on lines +84 to 92

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_database is documented as controlling whether the prod workspace creates/manages the Firestore database, but it is also wired into the dev_gcp_firestore module. With the current wiring, turning create_database = false would skip creating the dev database as well. Consider splitting this into separate flags (e.g., dev vs prod) or updating the variable name/description so it accurately reflects that it gates both databases.

Copilot uses AI. Check for mistakes.
depends_on = [module.gcp_project_apis]
}
12 changes: 9 additions & 3 deletions workspaces/prod/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ output "gcp_budget_name" {
value = module.gcp_budget.budget_name
}

output "gcp_firestore_db_id" {
description = "ID of the Firestore database in prod."
value = module.gcp_firestore.firestore_db_id
# Production Firestore instance outputs (uncomment when needed, use a distinct name like gcp_prod_firestore_db_id).
#output "gcp_prod_firestore_db_id" {
# description = "ID of the Firestore database in prod."
# value = module.gcp_firestore.firestore_db_id
#}

output "dev_gcp_firestore_db_id" {
description = "ID of the Firestore database in dev."
value = module.dev_gcp_firestore.firestore_db_id
}

output "github_oidc_role_arn" {
Expand Down
10 changes: 6 additions & 4 deletions workspaces/prod/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Non-sensitive prod workspace defaults.
# Set prod_account_id and gcp_project_id as TFC workspace variables (sensitive for account ID).

aws_region = "ap-southeast-1"
gcp_project_id = "durianpy-cms"
gcp_region = "asia-southeast1"
gcp_budget_limit_usd = 1
aws_region = "ap-southeast-1"
gcp_project_id = "durianpy-cms"
gcp_region = "asia-southeast1"
gcp_budget_limit_usd = 1
create_database = true
firestore_delete_protection_state = "DELETE_PROTECTION_ENABLED"

budget_notification_email = "durianpy.davao+devops@gmail.com"
budget_limit_usd = 50
11 changes: 11 additions & 0 deletions workspaces/prod/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ variable "gcp_region" {
default = "asia-southeast1"
}

variable "create_database" {
description = "Whether the prod workspace should create/manage the Firestore database."
type = bool
default = true
}

variable "firestore_delete_protection_state" {
description = "Delete protection state for the prod Firestore database."
type = string
}

Comment on lines +20 to +29

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The create_database / firestore_delete_protection_state variables are now part of the prod workspace interface, but firestore_delete_protection_state is only referenced in commented-out code and create_database currently affects the dev DB module too. Consider aligning variable names/descriptions with actual behavior (or wiring the prod module via a conditional instead of commented code) to avoid confusing/unused workspace inputs.

Suggested change
description = "Whether the prod workspace should create/manage the Firestore database."
type = bool
default = true
}
variable "firestore_delete_protection_state" {
description = "Delete protection state for the prod Firestore database."
type = string
}
description = "Whether this workspace should create/manage the Firestore database resources it currently controls."
type = bool
default = true
}

Copilot uses AI. Check for mistakes.
variable "gcp_budget_limit_usd" {
description = "Monthly GCP spend limit in USD for the prod project."
type = number
Expand Down
7 changes: 0 additions & 7 deletions workspaces/root/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ module "amplify" {
source = "./amplify"
}

module "gcp_firestore" {
source = "../../modules/gcp/firestore"

project_id = var.gcp_project_id
region = var.gcp_region
}

module "vpc" {
source = "../../modules/aws/vpc"

Expand Down
4 changes: 0 additions & 4 deletions workspaces/root/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ output "amplify_app_ids" {
value = module.amplify.app_ids
}

output "gcp_firestore_db_id" {
description = "ID of the Firestore database in root."
value = module.gcp_firestore.firestore_db_id
}
output "vpc_id" {
description = "ID of the root account VPC."
value = module.vpc.vpc_id
Expand Down
Loading