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.
- Create an organization token in Terraform Cloud.
- Create the token variable
$Token
in PowerShell.
$Token = "abcd"
PowerShell- Create the API parameters variable in PowerShell.
You need to replaceZHENGWU
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- Retrieve the API return and list the user’s email address.
$Test = Invoke-RestMethod @params
$Test.data.attributes.email
PowerShell