Skip to content

Instantly share code, notes, and snippets.

@srkiNZ84
Last active July 30, 2023 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srkiNZ84/12deda31f3ac834a96ff23ad094bcbe3 to your computer and use it in GitHub Desktop.
Save srkiNZ84/12deda31f3ac834a96ff23ad094bcbe3 to your computer and use it in GitHub Desktop.
Get TF Cloud vars
#!/bin/bash
curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
"https://app.terraform.io/api/v2/workspaces/$WORKSPACE_ID/vars" > temp_vars_file.json
cat temp_vars_file.json | jq -r '.data[].attributes | "\(.key)=\(.value)"' > myvars.tfvars
# Ensure we have quotes around values
sed -ei 's/=\([^"]*\)$/="\1"/g' myvars.tfvars
terraform fmt myvars.tfvars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment