Last active
August 21, 2023 20:43
-
-
Save ericreeves/8451833d00c42d0e271c5bd351c37afd to your computer and use it in GitHub Desktop.
Revisions
-
ericreeves revised this gist
Aug 21, 2023 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,6 +15,17 @@ # TFE_TOKEN="YOUR_TFE_API_TOKEN" # TFE_URL="https://app.terraform.io/api/v2" # Ensure required configuration variables have values if [ -z ${TFE_TOKEN} ]; then echo "TFE_TOKEN is unset." exit 1 fi if [ -z ${TFE_URL} ]; then echo "TFE_URL is unset." exit 1 fi # Function to list workspaces for an organization list_workspaces() { org_name="$1" -
ericreeves created this gist
Aug 21, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ #!/bin/bash # # Terraform Enterprise/Cloud - List All Workspaces in All Organizations # #------------------------------------------ # DESCRIPTION #------------------------------------------ # This script will list all workspaces in all organizations visible to the user for which the TFE_TOKEN was generated # #------------------------------------------ # CONFIGURATION #------------------------------------------ # These variables can either be hard-coded in this script, or exported prior to execution of the script. # # TFE_TOKEN="YOUR_TFE_API_TOKEN" # TFE_URL="https://app.terraform.io/api/v2" # Function to list workspaces for an organization list_workspaces() { org_name="$1" workspace_data=$(curl -s -H "Authorization: Bearer $TFE_TOKEN" "$TFE_URL/organizations/$org_name/workspaces") workspaces=$(echo "$workspace_data" | jq -r '.data[] | .attributes.name') echo "$workspaces" } # Get all organizations org_data=$(curl -s -H "Authorization: Bearer $TFE_TOKEN" "$TFE_URL/organizations") while IFS= read -r org_name; do workspace_list=$(list_workspaces "$org_name") for workspace_name in $workspace_list; do echo "$org_name/$workspace_name" done done < <(echo "$org_data" | jq -r '.data[] | .attributes.name')