Problem
When attempting to publish a module in the HCP Terraform Private Module Registry (PMR), you may encounter the following error:
Module is usable, but some versions have errors. Error: 1 error occurred: * pq: Could not complete operation in a failed transaction.
Cause
This error typically occurs when text files within the module, such as README.md, are not encoded in UTF-8 or ASCII format. The registry requires one of these standard encoding formats to process the module files correctly.
Solution
To resolve this issue, you must verify the encoding of your module's text files, convert them to UTF-8 if necessary, and publish a new version of the module.
Step 1: Verify File Encoding
Check the encoding of your module's text files. On a Linux or macOS system, you can use the file command to inspect a file's character set.
$ file README.md
The output should indicate UTF-8 Unicode text or ASCII text. If it shows a different encoding, proceed to the next step.
Step 2: Convert File to UTF-8 Encoding
Convert any incorrectly encoded files to UTF-8. You can use various text editors or command-line tools to change the file encoding. For example, using iconv:
$ iconv -f <CURRENT_ENCODING> -t UTF-8 README.md -o README.md.utf8 && mv README.md.utf8 README.md
Step 3: Commit and Tag a New Version
After correcting the file encoding, commit the changes to your version control system (VCS) and create a new tag. HCP Terraform ingests new module versions based on VCS tags, so this step is required for the registry to recognize the fix.
Outcome
After you push the new tag to your VCS, HCP Terraform will re-ingest the module, and it should publish successfully without the transaction error.
Additional Information
For more details on publishing modules, please refer to the official HCP Terraform documentation on the Private Module Registry.