aboutsummaryrefslogtreecommitdiffstats
path: root/setup-env.sh
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2026-10-12 18:11:21 -0700
committerEugene Triguba <hello@eugenetriguba.com>2026-10-12 18:11:21 -0700
commitf6a43b7479fad02d3163da52f55f5feb3f78d9c9 (patch)
treede25a7ee7b774da12fd79024caf586e3d9746c7a /setup-env.sh
parentAdd license (diff)
downloadsite-infra-f6a43b7479fad02d3163da52f55f5feb3f78d9c9.zip
Migrate terraform state into backblaze b2 bucket
Diffstat (limited to 'setup-env.sh')
-rwxr-xr-xsetup-env.sh34
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