Listing all Terraform modules published under group via API


I’m trying to list all Terraform modules that were ever published under my group - and then I’d like to delete some of them according to some criteria.

All I was able to do, was to list versions of modules, specifying their names.

curl --header "Authorization: Bearer glpat-XXX"  "{group_name}/{module_name}/aws/versions" | jq -r .

I also know how to publish modules

curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${modulename}-${TERRAFORM_MODULE_SYSTEM}-${NEXT_VERSION}.tgz ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/terraform/modules/${modulename}/${TERRAFORM_MODULE_SYSTEM}/${NEXT_VERSION}/file

And there’s also an endpoint to list the packages under a group or projet; but guess what, does not support Terraform modules…

curl --header "Authorization: Bearer glpat-XXX"  "{group_id}/packages"

But I can’t list the Terraform modules that exist in a project or under a namespace - and I don’t even know how to delete them either - features that are both available from the Gitlab UI.

Thanks for your help!

My colleague @aandre-wise found the solution!

module_publish_id=$(curl --header "Authorization: Bearer ${CI_TOKEN}" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages?package_type=terraform_module" | jq -r .[-1].id)            
curl --request DELETE --header "Authorization: Bearer ${CI_TOKEN}" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/$module_publish_id"            

1 Like