Skip to content

Instantly share code, notes, and snippets.

@vancluever
Last active June 3, 2021 20:39
Show Gist options
  • Select an option

  • Save vancluever/055d43898232e29a210ca0496cb7a79b to your computer and use it in GitHub Desktop.

Select an option

Save vancluever/055d43898232e29a210ca0496cb7a79b to your computer and use it in GitHub Desktop.
Get Terraform Registry providers, sort by most downloads (use --community to get community providers only)
#!/usr/bin/env bash
getproviders() {
for (( PAGE=1; ; PAGE++ )); do
if [ "$1" == "--community" ]; then
DATA="$(curl -fs "https://registry.terraform.io/v2/providers?filter[tier]=community&page[number]=$PAGE")"
else
DATA="$(curl -fs "https://registry.terraform.io/v2/providers?page[number]=$PAGE")"
fi
if [ "$(jq '.data' <<< "$DATA")" == "[]" ]; then
break
fi
jq '.data[] | {name: .attributes["full-name"], downloads: .attributes.downloads}' <<< "$DATA"
done
}
column -t <<< "$(jq --raw-output --slurp '
. | sort_by(.downloads) | reverse |
to_entries | map({
"#": (.key + 1),
"name": .value.name,
"downloads": .value.downloads
}) |
((.[0] | keys_unsorted), (.[] | . | map(.))) | @tsv' <<< "$(getproviders "$@")")"
@vancluever

Copy link
Copy Markdown
Author

Updated to provide rank with sorted output.

Note that the rank works off of index number only, hence ties are not listed as the same number.

@vancluever

Copy link
Copy Markdown
Author

Updated (again) to default to all providers with --community option now to do community only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment