Terraform registry - prerelease ordering invalid?

When releasing pre-release versions suffixed with a number (e.g. v1.0.0-pre5), the ordering seems to fail when the number suffix goes beyond single digits, e.g. v1.0.0-pre10. This results in v1.0.0-pre9 remaining as the latest release in this example.

I’m sure this is an invalid expectation of how tags are expected with the registry, but just wanted to double check incase this is actually a bug :slight_smile:

One thing that the semver spec does state is the prerelease version should be prefixed with a period:

Hi @0x4c6565,

Indeed, the registry and Terraform itself both aim to use the semver precedence algorithm to decide which is the “newest” matching version, which specifies that only prerelease portions consisting entirely of digits get compared numerically.

  • Identifiers consisting of only digits are compared numerically.
  • Identifiers with letters or hyphens are compared lexically in ASCII sort order.

So if you intend to release more than nine prereleases of the same main version then you’d need to either use the period-separated version you noted, like v1.0.0-pre.5, or to preemptively zero-pad your numeric part like v1.0.0-pre05.

Semver doesn’t include any rules for deciding whether a particular version matches a version constraint, so it’s also worth noting that Terraform has a special treatment of prerelease versions, where it’ll select them only for exact versions and never for bounded version sets. Specifically, >= 1.0.0 can’t match v1.1.0-beta.1 even though it the beta has a higher precedence, because Terraform excludes the prerelease version from consideration unless the calling module specifies exactly version = "1.0.0-beta.1".

1 Like