Skip to content

Instantly share code, notes, and snippets.

@ericreeves
Last active May 11, 2023 18:22
Show Gist options
  • Save ericreeves/f35d551730941e24bb6b803e7d751906 to your computer and use it in GitHub Desktop.
Save ericreeves/f35d551730941e24bb6b803e7d751906 to your computer and use it in GitHub Desktop.
Quick Bash Script Wrapper for TFX to List All Remote Source Sharing for All Workspaces in an Organization
#!/bin/bash
#
# Quick and dirty script that wraps around the TFX CLI tool to list all Workspaces within an Orgainzation, and then list all remote state
# sharing for each Workspace.
#
# Acquire tfx here: https://tfx.rocks/
# TFX can be configured using environment variables TFE_HOSTNAME, TFE_ORGANIZATION, TFE_TOKEN
#
export TFE_HOSTNAME="app.terraform.io"
export TFE_ORGANIZATION="ericreeves-demo"
#export TFE_TOKEN="<REDACTED>"
printf "+ %-50s + %s\n" $(printf -- '-%.0s' {1..50}) $(printf -- '-%.0s' {1..50})
printf "| %-50s | %s\n" "Source Workspace" "Sharing State With..."
printf "+ %-50s + %s\n" $(printf -- '-%.0s' {1..50}) $(printf -- '-%.0s' {1..50})
for WORKSPACE in $(tfx workspace list --json | jq -r '.[].Name'); do
REMOTE_STATE_SHARING_RAW=$(tfx workspace show --name $WORKSPACE --json | jq -r '.["Remote State Sharing"][]' 2>/dev/null)
if [ $? -eq 0 ]; then
REMOTE_STATE_SHARING=$(echo -n $REMOTE_STATE_SHARING_RAW | sed 's/\s/,/g')
printf "| %-50s | %s\n" $WORKSPACE $REMOTE_STATE_SHARING
fi
done
printf "+ %-50s + %s\n" $(printf -- '-%.0s' {1..50}) $(printf -- '-%.0s' {1..50})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment