Problem
When you attempt to publish a new version of a private module to the Terraform Enterprise registry, the operation fails with an error indicating an invalid version number. A log entry similar to the following may appear in the support bundle:
invalid version: 0.60.1-example-module-23.012 is not a valid SemVer string: numeric prerelease elements may not contain leading zeros
Cause
The error occurs because Terraform Enterprise enforces specific Semantic Versioning (SemVer) rules for module versions, particularly for pre-release identifiers.
Terraform Enterprise considers purely numeric pre-release identifiers with leading zeros to be invalid. This is because leading zeros can cause ambiguity in version comparison and interpretation.
-
Invalid Case: A version like
1.2.3-01is invalid because the pre-release identifier01is purely numeric and contains a leading zero. -
Valid Case: A version like
1.2.3-0alpha0is valid. The presence of non-numeric characters (alpha) makes the identifier alphanumeric. In this context, the leading zero is treated as part of a string, not as a numeric value, and is therefore acceptable.
Solutions
Solution 1: Correct the Module Version String
To resolve this issue, you must modify the module's version tag to comply with SemVer standards as interpreted by Terraform Enterprise. You can do this by either removing the leading zeros from numeric pre-release identifiers or by ensuring the identifier is alphanumeric.
Example Corrections:
- If your version is
0.60.1-example-module-23.012, change it to0.60.1-example-module-23.12by removing the leading zero. - Alternatively, you could make the pre-release identifier alphanumeric, such as
0.60.1-example-module-23-rev12.
After correcting the version tag in your version control system, attempt to publish the module to the private registry again. The module should now publish successfully.
Additional Information
For more details on versioning, refer to the official documentation on module versions and Semantic Versioning.