~damien/infrastructure

ref: a39e1211c4092155dd789f234c1a75f275612391 infrastructure/tools/set-cluster-env -rwxr-xr-x 1.5 KiB
a39e1211 — Damien Radtke Add todo list 9 months ago
                                                                                
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
35
36
#!/usr/bin/env bash
#
# This script sets the environment variables necessary for Consul, Nomad, and Vault
# CLI tools. It queries Terraform state for node addresses, so this script will need
# to be re-invoked after switching workspaces.
#
# In order for CLI tools to work immediately, add something like this to your .bashrc:
#
#     $ source "$(which set-cluster-env)" "${HOME}/infrastructure/terraform/terraform.tfstate"
#

state_file="${1:-terraform.tfstate}"

if [[ ! -f "${state_file}" ]]; then
	echo "state file '${state_file}' not found, are you in the right directory?"
	exit 1
fi

consul_server="$(terraform output -json -state "${state_file}" consul_server_ips | jq -r '.[0]')"
nomad_server="$(terraform output -json -state "${state_file}" nomad_server_ips | jq -r '.[0]')"
vault_server="$(terraform output -json -state "${state_file}" vault_server_ips | jq -r '.[0]')"

export CONSUL_HTTP_ADDR="https://[${consul_server}]:8501"
export CONSUL_CACERT="/etc/ssl/consul/ca.pem"
export CONSUL_CLIENT_CERT="${HOME}/consul-cli.pem"
export CONSUL_CLIENT_KEY="${HOME}/consul-cli-key.pem"

export NOMAD_ADDR="https://[${nomad_server}]:4646"
export NOMAD_CACERT="/etc/ssl/nomad/ca.pem"
export NOMAD_CLIENT_CERT="${HOME}/nomad-cli.pem"
export NOMAD_CLIENT_KEY="${HOME}/nomad-cli-key.pem"

export VAULT_ADDR="https://[${vault_server}]:8200"
export VAULT_CACERT="/etc/ssl/vault/ca.pem"
export VAULT_CLIENT_CERT="${HOME}/vault-cli.pem"
export VAULT_CLIENT_KEY="${HOME}/vault-cli-key.pem"