Last active
July 30, 2023 23:34
-
-
Save srkiNZ84/12deda31f3ac834a96ff23ad094bcbe3 to your computer and use it in GitHub Desktop.
Get TF Cloud vars
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 characters
#!/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