Introduction
Certain Terraform Enterprise configurations can encounter a bug that fails to create a required database schema, which prevents parts of the application from working correctly.
Problem
After upgrading a mounted disk instance of Terraform Enterprise to version v202212-x or newer, a bug may prevent the creation of a required database schema. This issue can cause multiple errors, including Failed to enqueue cost estimate for cost estimation or failures in Sentinel policy checks.
Prerequisites
- An existing mounted disk instance of Terraform Enterprise.
- The instance was upgraded to version
v202212-xor newer.
Cause
A review of a support bundle may show an error similar to the following example in the tfe-task-worker.stdout log file.
"error","@message":"error running database migrations", 3"@module":"tfe-task-worker","@timestamp":"2022-12-15T17:02:37.498823Z","err":"database driver: sql: Scan error on column index 0, name \"current_schema\": converting NULL to string is unsupported in 5line 0: SELECT CURRENT_SCHEMA()"}
This error indicates that the task_worker schema is missing from the database.
Solution
This procedure details how to manually create the missing database schema to resolve the issue.
Procedure
- Connect to your Terraform Enterprise instance using SSH.
Connect to the PostgreSQL container to access the database shell.
$ docker exec -it tfe-postgres psql -U hashicorp
List the current schemas to confirm that
task_workeris missing.hashicorp=# \dn
Create the missing
task_workerschema.hashicorp=# CREATE SCHEMA IF NOT EXISTS task_worker AUTHORIZATION hashicorp;
Verify that the
task_workerschema now exists by listing the schemas again.hashicorp=# \dn
The output should now include the
task_workerschema.List of schemas Name | Owner --------------+----------- rails | hashicorp registry | hashicorp task_worker | hashicorp vault | hashicorp (4 rows)Exit the PostgreSQL session.
hashicorp=# \q
- Restart the Terraform Enterprise application for the changes to take effect.
Outcome
After you create the task_worker schema and restart the Terraform Enterprise application, the application's functionality should be restored.