Terraform registry: "Latest version for a specific module" endpoint does not provide the latest version for multi-digits major, minor and patch versions
Summary
There appears to be an issue with the GitLab Terraform Module API when handling versions with multiple digits in the major, minor or patch segments. Using versions such as 0.0.10 and 0.10.0 10.0.0 (and above) are not being correctly recognized as latest.
Steps to reproduce
export PROJECT_ID=xxxx
export PROJECT_NAME=xxxx
# Upload a new module version (e.g., 0.0.9), prior to this versions 0.0.1 to 0.0.8 can been uploaded or not - the behavior is the same. In this case versions 0.0.1 to 0.0.8 have not been uploaded.
curl --fail-with-body --location --header "PRIVATE-TOKEN: $(cat ~/.ssh/tokens/gitlab-personal-api-acess)" --upload-file ./test-module-0.0.9.tgz --url "https://gitlab.com/api/v4/projects/$PROJECT_ID/packages/terraform/modules/test-module/test/0.0.9/file"
# > {"message":"201 Created"}
#Retrieve the current module version:
curl --header "Authorization: Bearer $(cat ~/.ssh/tokens/gitlab-personal-api-acess)" https://gitlab.com/api/v4/packages/terraform/modules/v1/$PROJECT_NAME/test-module/test
#> {"name":"test-module/test","provider":"test","providers":["test"],"root":{"dependencies":[]},"source":"<REDACTED>","submodules":[],"version":"0.0.9","versions":["0.0.9"]}
# LOOKS GOOD
#Upload another module version with multiple digits in the patch segment:
curl --fail-with-body --location --header "PRIVATE-TOKEN: $(cat ~/.ssh/tokens/gitlab-personal-api-acess)" --upload-file ./test-module-0.0.10.tgz --url "https://gitlab.com/api/v4/projects/$PROJECT_ID/packages/terraform/modules/test-module/test/0.0.10/file"
# > {"message":"201 Created"}%
#Retrieve the current module version again:
curl --header "Authorization: Bearer $(cat ~/.ssh/tokens/gitlab-personal-api-acess)" https://gitlab.com/api/v4/packages/terraform/modules/v1/$PROJECT_NAME/test-module/test
#> {"name":"test-module/test","provider":"test","providers":["test"],"root":{"dependencies":[]},"source":"<REDACTED>","submodules":[],"version":"0.0.9","versions":["0.0.9"]}
# THIS IS NOT WHAT IS EXPECTED. The latest version should be 0.0.10
#Verify the 0.0.10 version actually exists
curl --header "Authorization: Bearer $(cat ~/.ssh/tokens/gitlab-personal-api-acess)" https://gitlab.com/api/v4/packages/terraform/modules/v1/$PROJECT_NAME/test-module/test/versions
#> {"modules":[{"versions":[{"version":"0.0.10","submodules":[],"root":{"dependencies":[],"providers":[{"name":"test","version":""}]}},{"version":"0.0.9","submodules":[],"root":{"dependencies":[],"providers":[{"name":"test","version":""}]}}],"source":"<REDACTED>"}]}
Example Project
What is the current bug behavior?
The API provides non latest version 0.0.9 as the latest version. The same is issue is observed with versions such as 0.10.0 and 10.0.0 (and above).
What is the expected correct behavior?
The API should provide 0.0.10 as the latest version.
This bug happens on GitLab.com
GitLab Enterprise Edition 17.3.0-pre 82298a42