How to Generate a Report of All Drifted Workspaces in an HCP Terraform Organization
Introduction
This guide describes two methods for generating a report of all workspaces with detected configuration drift within an HCP Terraform organization.
Procedure
You can generate a drift report using either the HCP Terraform user interface or its API.
Option 1: Use the Explorer Feature
The Explorer feature in the HCP Terraform UI provides a direct way to filter for and export a list of drifted workspaces.
- Log in to your HCP Terraform organization.
- Navigate to the Explorer tab.
- Select the Drifted workspaces filter. The UI will display all workspaces with detected drift.
- Click the export button to download the report.
Option 2: Use the HCP Terraform API
You can retrieve a list of drifted workspaces programmatically using the HCP Terraform API.
Execute the following curl command. You must replace YOUR_ORG_NAME with your organization's name and provide a valid user or team API token for the $TOKEN variable.
$ curl \ --header "Authorization: Bearer $TOKEN" \ 'https://app.terraform.io/api/v2/organizations/YOUR_ORG_NAME/explorer?type=workspaces&filter%5B0%5D%5Bdrifted%5D%5Bis%5D%5B0%5D=true'
Additional Information
- For more details on the API, refer to the official HCP Terraform API documentation.
- To learn more about the Explorer feature, consult the Workspaces Explorer documentation.