#!/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