diff options
Diffstat (limited to 'setup-env.sh')
| -rwxr-xr-x | setup-env.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/setup-env.sh b/setup-env.sh new file mode 100755 index 0000000..2bb57f3 --- /dev/null +++ b/setup-env.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# +# DESCRIPTION: +# Sets up a `.env` file that may be sourced via `source .env` to populate the +# credentials to authenticate with the Backblaze B2 backend state bucket. This +# is setup by retrieving the credentials from 1Password. +# +# PREREQUISITES: +# - `op` (1password CLI) +# - `jq` +# +# The `op` CLI must already be authenticated via `op signin`. +# +# USAGE: +# ./bootstrap-state-bucket.sh +# ./setup-env.sh +# source .env +set -o errexit + +OP_ITEM="Backblaze B2 Terraform State Key" + +main() { + KEY_ID=$(get_op_label_value "$OP_ITEM" "key_id") + KEY_VALUE=$(get_op_label_value "$OP_ITEM" "key_value") + printf "export AWS_ACCESS_KEY_ID=%s\nexport AWS_SECRET_ACCESS_KEY=%s\n" "$KEY_ID" "$KEY_VALUE" >>.env +} + +get_op_label_value() { + _item="$1" + _label="$2" + op item get "$_item" --format json | jq --raw-output ".fields[] | select(.label == \"$_label\") | .value" +} + +main |