Created
August 23, 2020 07:14
-
-
Save hongkongkiwi/daf9c2a59e9131fcacec7349a0c93187 to your computer and use it in GitHub Desktop.
An incomplete script to import terraform cloud variables.
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/sh | |
ORGANIZATION_NAME=`cat backend.tf | grep "organization" | cut -f2 -d'=' | tr -d ' ' | tr -d '"'` | |
WORKSPACE_NAME=`cat backend.tf | grep ' name = "' | cut -f2 -d'=' | tr -d ' ' | tr -d '"'` | |
TERRAFORM_CLOUD_TOKEN=${TERRAFORM_CLOUD_TOKEN:-""} | |
while IFS= read -r VARIABLE; do | |
PAYLOAD='' read -r -d '' String <<"EOF" | |
{ | |
"data": { | |
"type":"vars", | |
"attributes": { | |
"key":"some_key", | |
"value":"some_value", | |
"description":"some description", | |
"category":"terraform", | |
"hcl":false, | |
"sensitive":false | |
}, | |
"relationships": { | |
"workspace": { | |
"data": { | |
"id":"ws-4j8p6jX1w33MiDC7", | |
"type":"workspaces" | |
} | |
} | |
} | |
} | |
} | |
EOF | |
curl \ | |
--header "Authorization: Bearer $TERRAFORM_CLOUD_TOKEN" \ | |
--header "Content-Type: application/vnd.api+json" \ | |
--request POST \ | |
--data "$PAYLOAD" \ | |
"https://app.terraform.io/api/v2/vars" | |
done <<< "$VARIABLES" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment