blob: 2bb57f3f39337ecbc109c7e2d883acf1d20265c0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
|