Create Terraform-managed Postgres DB secret for pal-e-docs namespace #22
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/pal-e-platform#22
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Plan
plan-2026-02-26-tf-modularize-postgres-- Phase 3, Part A (traceability only)Repo
forgejo_admin/pal-e-platformUser Story
As a platform operator
I want the pal-e-docs Postgres connection string managed by Terraform
So that the app can connect to the CNPG cluster without manual kubectl secrets
Context
A CNPG Postgres cluster (
pal-e-postgres) is running in thepostgresnamespace with apaledocsdatabase and user. The pal-e-docs app runs in thepal-e-docsnamespace and needs a secret containing the DATABASE_URL to connect cross-namespace.This follows the established pattern: Terraform creates
kubernetes_secret_v1resources in app namespaces, just likeharbor-credsinservices.tfandcnpg-s3-credsinmain.tf.The existing credentials (already in the cluster):
paledocs-db-credentialsinpostgresnamespacepaledocspal-e-postgres-rw.postgres.svc.cluster.local:5432paledocsFile Targets
Files to modify:
terraform/variables.tf-- addpaledocs_db_passwordvariable (sensitive string)terraform/main.tf-- addkubernetes_secret_v1.paledocs_db_urlresourceFiles NOT to touch:
terraform/k3s.tfvars-- gitignored, Lucas adds the value manuallysalt/-- not in scopeAcceptance Criteria
terraform/variables.tfhas a newvariable "paledocs_db_password"withsensitive = trueandtype = stringterraform/main.tfhas a newkubernetes_secret_v1.paledocs_db_urlresource that:pal-e-docsnamespace (reference existing namespace data source or hardcode"pal-e-docs")DATABASE_URLwith valuepostgresql://paledocs:${var.paledocs_db_password}@pal-e-postgres-rw.postgres.svc.cluster.local:5432/paledocstofu validatepassestofu planshows only the new secret resource being created (no unrelated drift)Test Expectations
tofu fmt -checkpassestofu validatepassestofu planoutput included in PR description showing the new resourceConstraints
main.tfforkubernetes_secret_v1resources (seecnpg_s3_credsaround line 1086)set_sensitivepattern if the value appears in plan output -- seetype = "string"lesson in CLAUDE.mdmain.tf(after the existing CNPG resources, before the next section)pal-e-docsnamespace already exists (created by pal-e-services Terraform). Do NOT create it. Use a hardcoded namespace string"pal-e-docs".Checklist
tofu planoutput in PR descriptionRelated
pal-e-docsproject -- this secret enables the Postgres migrationPR #23 Review
BLOCKERS
1. Namespace
pal-e-docsdoes not exist in Terraform state and is hardcoded as a string literal.The new resource at
/home/ldraney/pal-e-platform/terraform/main.tf(line ~1100 in the branch) uses:This namespace is not created anywhere in this codebase. Every other secret in main.tf references a Terraform-managed namespace via
kubernetes_namespace_v1.<name>.metadata[0].name(e.g.,cnpg_s3_credsuseskubernetes_namespace_v1.postgres.metadata[0].name). The PR body claims it "follows the established pattern used bycnpg_s3_creds" but the namespace handling does not follow that pattern.If the namespace does not already exist in the cluster,
tofu applywill fail. If it does exist (created outside Terraform), this is still an inconsistency -- all other namespaces are Terraform-managed. Either:kubernetes_namespace_v1.paledocsresource and reference it, orThis is a blocker because it will either fail on apply or silently create a pattern inconsistency without justification.
NITS
1. No password length validation. Other password variables in
variables.tfinclude validation blocks (e.g.,harbor_admin_passwordrequires >= 8 chars,minio_root_passwordrequires >= 8 chars). The newpaledocs_db_passwordvariable has no validation. Consider adding a minimum length constraint for consistency and to catch empty/short passwords early.2. DATABASE_URL string contains hardcoded hostname. The connection string hardcodes
pal-e-postgres-rw.postgres.svc.cluster.local:5432. This is correct for the current CNPG cluster setup, but if the service name or namespace ever changes, this string will silently break. A comment noting the dependency on the CNPG cluster service name would help future maintainers. Non-blocking.SOP COMPLIANCE
22-paledocs-db-secretreferences issue #22)plan-2026-02-26-tf-modularize-postgres)sensitive = true)tofu planoutput included in PR bodyVERDICT: NOT APPROVED
One blocker: the
pal-e-docsnamespace is not Terraform-managed in this repo and the hardcoded string breaks the established pattern without explanation. Resolve the namespace question (create it in Terraform or document why it is external) before merge.PR #23 Review (Re-review)
BLOCKERS
None. The previously identified blocker (hardcoded namespace string) has been resolved.
Fix verification: The dev added a
data "kubernetes_namespace_v1" "pal_e_docs"data source to look up the externally managedpal-e-docsnamespace, and the secret resource now references it viadata.kubernetes_namespace_v1.pal_e_docs.metadata[0].name. This is the correct approach -- sincepal-e-docsis managed by pal-e-services (not this bootstrap repo), adatasource (read-only lookup) is more appropriate than aresource(which would imply ownership). Good design decision.NITS
paledocs_db_passwordvariable has no length validation, unlikeharbor_admin_passwordandminio_root_passwordwhich enforce minimum lengths. Consider adding a minimum length constraint for consistency. Non-blocking.SOP COMPLIANCE
22-paledocs-db-secretreferences issue #22)plan-2026-02-26-tf-modularize-postgres)VERDICT: APPROVED