DO block dollar-quote collides with HCL $$ escape (Job fails with syntax error) #317
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
ldraney/pal-e-platform#317
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?
Type
Bug
Lineage
Discovered scope from operator-side
make tofu-apply(2026-04-30 by Ava). PR #304 added a SQL Job usingDO $$ ... $$;for an anonymous block. HCL strings interpret$$as an escape for$(to avoid Terraform's${...}interpolation), so the rendered SQL wasDO $ ... $;(single dollar each). Postgres rejected withsyntax error at or near "$" at character 4. Job hit BackoffLimitExceeded after 4 retries.Repo
forgejo_admin/pal-e-platform
What Broke
module.database.kubernetes_job_v1.admin_app_user_provisionruns psql against basketball-api postgres with this SQL:But Postgres logs show:
The double-dollar dollar-quote
$$got collapsed to single$by HCL string templating. HCL uses$$as the literal-$escape (to prevent Terraform's${expression}interpolation from triggering). SoDO $$in the HCL source renders asDO $in the final Job spec.Job retried 4× (BackoffLimitExceeded), all failed with same syntax error. Apply errored.
Repro Steps
cd ~/pal-e-platform/terraform && tofu apply -lock=false -target=module.databasekubectl logs -n basketball-api postgres-9b5b87b5-* --tail=10showssyntax error at or near "$" at character 4Expected Behavior
Job runs the SQL successfully, creates
admin_approle, grants permissions. Apply completes.Environment
terraform/modules/database/main.tflines 193, 201$$→$(single dollar in output)$tag$ ... $tag$dollar-quoting (where tag can be empty$$ ... $$)User Story
story:admin-row-crud — As the operator running
make tofu-apply, I need the admin_app provisioning Job's SQL to actually parse so the role gets created and the deploy chain proceeds.Architecture
arch:postgres
Context
Two valid fixes:
DO $$$$ ... $$$$;— HCL renders asDO $$ ... $$;correctly, but visually confusingDO $body$ ... $body$;— postgres treats any matched$tag$as dollar-quote delimiter;$body$has no$$so HCL doesn't escape; visually clearerGoing with #2 — self-documenting and avoids the HCL escape collision entirely.
This is the third post-merge runtime gap during this bootstrap (after salt master crash + #310 label
/). Reinforces the lesson captured asfeedback_tofu_validate_not_k8s_api: tofu validate doesn't catch HCL string-templating semantic errors that surface at runtime.File Targets
terraform/modules/database/main.tflines 193 + 201 — change$$to$body$Acceptance Criteria
DO $body$and$body$;replaceDO $$and$$;in the SQL heredoctofu apply -target=module.databasecompletes without Job failurekubectl logsof the Job pod shows==> admin_app role provisioned successfullypsql ... -c "\du admin_app"from the postgres pod shows the role existsTest Expectations
Succeeded)admin_approle exists in basketball-api Postgres with login + passwordadmin-app-db-urlsecret created in both basketball-api AND westside-admin namespacesConstraints
Checklist
Closes #THISRelated
pal-e-platform#315(label value/rejected by k8s API)feedback_tofu_validate_not_k8s_api,feedback_verification_before_completion