woman writing on whiteboard

Terraform Cloud – How to List All Users

Terraform Cloud has a rich API. However, the API documentation does not mention how to list all users. We can leverage the organization membership API and the PowerShell command Invoke-RestMethod to get a user list.

  1. Create an organization token in Terraform Cloud.
  2. Create the token variable $Token in PowerShell.
$Token = "abcd"
PowerShell
  1. Create the API parameters variable in PowerShell.
    You need to replace ZHENGWU with your own organization name. And I used 100 at the end of the URI to retrieve the first 100 users. It can be any number.
$params = @{
  Uri = "https://app.terraform.io/api/v2/organizations/ZHENGWU/organization-memberships?page%5Bsize%5D=100"
  Authentication = "Bearer"
  Token = $Token
  ContentType = "application/vnd.api+json"
}
PowerShell
  1. Retrieve the API return and list the user’s email address.
$Test = Invoke-RestMethod @params
$Test.data.attributes.email
PowerShell