HCP Terraform(Terraform Cloud)の Workspace ごとの RUM(Resources Under Management)数は、Explorer API で取得できます。
取得方法(Explorer API)
/api/v2/organizations/:organization/explorer に対して、type=workspaces を指定して取得し、レスポンス内の current-rum-count を参照します。
公式ドキュメント(Explorer API):
実行例
$ curl -s \
--header "Authorization: Bearer $TOKEN" \
"https://app.terraform.io/api/v2/organizations/$ORGANIZATION/explorer?type=workspaces" \
| jq -r '.data[] | "\(.attributes["workspace-name"]) \(.attributes["current-rum-count"])"'
workspace_1 10
workspace_2 20
workspace_3 30
ページングに注意
Explorer API にはページングがあり、page[size] は 1〜100 の範囲で指定します(最大 100 件)
$ curl \
--header "Authorization: Bearer $TOKEN" \
"https://app.terraform.io/api/v2/organizations/$ORGANIZATION/explorer?type=workspaces&page\[size\]=101"
{"errors":[{"status":"422","title":"invalid attribute","detail":"page[size] must be between 1 and 100"}]}
Workspace 数が 100 を超える場合は、page[number] を使って複数ページを取得してください。