Unable to delete Terraform module from the infrastructure registry via API
I need to be able to delete specific versions of specific Terraform modules from the Infrastructure Registry via the API. Documentation states that this is possible but there are no examples and guesswork hasn't been productive so far.
I originally asked a question on the forum: https://forum.gitlab.com/t/deleting-modules-packages-from-terraform-registry-via-the-api/62980
I will duplicate the information there since I have not received any answers there. This might very well just be a matter of improving the documentation.
I'm able to upload a Terraform module via the API using the following command:
❯ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" --upload-file file.tgz "https://gitlab.mydomain.com/api/v4/projects/123/packages/terraform/modules/my-module/my-system/0.0.1/file"
{"message":"201 Created"}%
However, I need to be able to delete it and that is not working for me:
❯ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" --request DELETE "https://gitlab.mydomain.com/api/v4/projects/123/packages/terraform/modules/my-module/my-system/0.0.1/file"
{"error":"404 Not Found"}%
❯ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" --request DELETE "https://gitlab.mydomain.com/api/v4/projects/123/packages/terraform/modules/my-module/my-system/0.0.1/"
{"error":"404 Not Found"}%
❯ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" --request DELETE "https://gitlab.mydomain.com/api/v4/projects/123/packages/terraform/modules/my-module/my-system/0.0.1"
{"error":"404 Not Found"}%
According to the documentation here, I should be able to remove certain versions of a package through the API but it doesn't explain what the format of the package URL should be for the Terraform infrastructure registry packages.
Can you possibly explain this to me and perhaps update the documentation to include that information?
UPDATE: The underlying issue is that there is no way to get the package ID for the package you've uploaded. The following request returns the empty list, even though there are packages that have been uploaded to the Infrastructure Registry:
❯ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "https://gitlab.mydomain.com/api/v4/projects/123/packages"
[]%
So I guess a better issue would be to get the GET request for the packages endpoint to work properly.
UPDATE: I've created an issue to fix the GET request for packages: #348957 (closed) As well as a suggestion to support overwriting existing versions in the packages registry: #348955