Problem
When you create modules or publish new module versions in Terraform Enterprise, the operation may fail with the error message commit unexpectedly resulted in rollback. This message originates from the PostgreSQL database.
Prerequisites
- This issue affects Terraform Enterprise versions prior to
v202201-2.
Cause
To confirm this issue, investigate the logs from the ptfe_registry_worker container. A positive confirmation shows the following error:
/home/circleci/terraform-registry/ingress/push/ingress_version.go:239 ERROR: invalid byte sequence for encoding "UTF8": 0x00 (SQLSTATE 22021)
This log entry is typically followed by the SQL statement that failed, which may show the module's README.md file content with a NULL character between each original character.
This issue occurs because the module's README.md file is UTF-16 encoded. Affected versions of Terraform Enterprise do not correctly handle UTF-16 encoded files.
Solutions
There are two approaches to resolve this issue.
Solution 1: Convert the README file to UTF-8
As a temporary workaround until you can upgrade Terraform Enterprise, you can convert the README.md file to UTF-8 encoding. Choose one of the following commands based on your environment.
Linux
Use the iconv command to convert the file encoding.
$ iconv -f utf-16le -t utf-8 README.md -o README-UTF8.md && mv README-UTF8.md README.md
PowerShell
Use the Get-Content and Set-Content cmdlets to re-encode the file.
$ Get-Content README.md | Set-Content -Encoding utf8 README-UTF8.txt ; Move-Item -Path README-UTF8.md -Destination README.md
Visual Studio Code
In the bottom right of the footer, select the encoding button to change the file's encoding to UTF-8.
Solution 2: Upgrade Terraform Enterprise
The permanent solution is to upgrade your Terraform Enterprise instance to version v202201-2 or a later version, which includes the fix for this encoding issue.
Additional Information
For more information on upgrading Terraform Enterprise, refer to the official upgrade documentation.