Skip to content

Instantly share code, notes, and snippets.

@gitrgoliveira
Last active March 22, 2023 13:58
Show Gist options
  • Save gitrgoliveira/ce22f408ef6ea5564411491f966de9a1 to your computer and use it in GitHub Desktop.
Save gitrgoliveira/ce22f408ef6ea5564411491f966de9a1 to your computer and use it in GitHub Desktop.
import os
from terrasnek.api import TFC as TFP
# do `pip install terrasnek` before running this script
TFE_TOKEN = os.getenv("TFE_TOKEN", None)
TFE_URL = os.getenv("TFE_URL", "https://app.terraform.io") # ex: https://app.terraform.io
api = TFP(TFE_TOKEN, url=TFE_URL)
orgs = api.orgs.list()['data']
print (f"Found {len(orgs)} Organizations")
total_rum = 0
total_workspaces = 0
for org in orgs:
api.set_org(org['id'])
print (f".: looking up Organization {org['id']}",)
all_workspaces = api.workspaces.list_all()['data']
print (f"Found {len(all_workspaces)} Workspaces")
total_workspaces += len (all_workspaces)
rum = 0
for workspace in all_workspaces:
# to add details per workspace
# print(workspace['attributes']['name'], workspace['attributes']['resource-count'])
rum += int(workspace['attributes']['resource-count'])
print(f"RUM for org {org['id']}: {rum}")
total_rum += rum
print("\n")
print(f"Total number of RUMs: {total_rum}")
print(f"Total number of Workspace: {total_workspaces}")
print(f"Total number of Organizations: {len(orgs)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment