Skip to content
Merged
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
6 changes: 5 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ module "database" {
postgres_ro_username = var.postgres_ro_username
database_version = var.database_version
database_edition = var.database_edition
common_tags = var.common_tags

point_in_time_recovery_enabled = var.point_in_time_recovery_enabled
transaction_log_retention_days = var.transaction_log_retention_days

common_tags = var.common_tags

depends_on = [module.project_factory_project_services]
}
Expand Down
15 changes: 13 additions & 2 deletions modules/database/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
locals {
# PITR (continuous WAL archiving) defaults to on for ENTERPRISE_PLUS and off
# otherwise (including when the edition is null/auto-determined). An explicit
# value for point_in_time_recovery_enabled always wins.
point_in_time_recovery_enabled = (
var.point_in_time_recovery_enabled != null
? var.point_in_time_recovery_enabled
: coalesce(var.database_edition, "") == "ENTERPRISE_PLUS"
)
}

# https://registry.terraform.io/modules/GoogleCloudPlatform/sql-db/google/latest/submodules/private_service_access
module "db_private_service_access" {
source = "GoogleCloudPlatform/sql-db/google//modules/private_service_access"
Expand Down Expand Up @@ -49,8 +60,8 @@ module "db" {
enabled = true
start_time = "20:00"
location = null
point_in_time_recovery_enabled = false
transaction_log_retention_days = null
point_in_time_recovery_enabled = local.point_in_time_recovery_enabled
transaction_log_retention_days = var.transaction_log_retention_days
retained_backups = 7
retention_unit = "COUNT"
}
Expand Down
21 changes: 21 additions & 0 deletions modules/database/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ variable "database_edition" {
}
}

variable "point_in_time_recovery_enabled" {
type = bool
default = null
description = <<-EOT
Enable point-in-time recovery (continuous WAL archiving) for the PostgreSQL
instance. When null, defaults to true for ENTERPRISE_PLUS edition and false
otherwise. Note: changing this triggers an instance restart, and on
ENTERPRISE edition transaction logs consume the data disk.
EOT
}

variable "transaction_log_retention_days" {
type = number
default = null
description = <<-EOT
Number of days to retain transaction logs for point-in-time recovery.
Null uses the provider/edition default (1-7 days for ENTERPRISE, up to 35
for ENTERPRISE_PLUS).
EOT
}

variable "common_tags" {
type = map(string)
}
21 changes: 21 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,27 @@ variable "database_edition" {
}
}

variable "point_in_time_recovery_enabled" {
type = bool
default = null
description = <<-EOT
Enable point-in-time recovery (continuous WAL archiving) for the PostgreSQL
instance. When null, defaults to true for ENTERPRISE_PLUS edition and false
otherwise. Note: changing this triggers an instance restart, and on
ENTERPRISE edition transaction logs consume the data disk.
EOT
}

variable "transaction_log_retention_days" {
type = number
default = null
description = <<-EOT
Number of days to retain transaction logs for point-in-time recovery.
Null uses the provider/edition default (1-7 days for ENTERPRISE, up to 35
for ENTERPRISE_PLUS).
EOT
}

# ┏━╸╻ ╻┏━╸╻┏ ╻ ╻┏━┓╻ ╻┏━┓┏━╸
# ┃ ┃ ┃┃ ┣┻┓┣━┫┃ ┃┃ ┃┗━┓┣╸
# ┗━╸┗━╸╹┗━╸╹ ╹╹ ╹┗━┛┗━┛┗━┛┗━╸
Expand Down
Loading