How to List All Users in Terraform Cloud

Terraform 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 = "abcde"

3. Create the API parameters variable in PowerShell.

$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"
}

Note: 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. 

4. Retrieve the API return and list the user's email address.


$Test = Invoke-RestMethod @params
$Test.data.attributes.email

Popular posts from this blog

Moving to Blogger.com

How to Use Proxy on WSL 2

Connect-NsxtServer shows "Unable to connect to the remote server"