Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update setup-peering.sh to be runnable outside of TF #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion peering/servers/setup-peering.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

set -x

# when the script is being run outside of Terraform, the tokens won't be set so we need to populate them
# from the Terraform state
if [ -z "${FOO_TOKEN}" ]; then
export FOO_TOKEN="$(terraform state show 'random_uuid.management_tokens[0]' | grep result | awk '{print $3}' | tr -d '\"')"
fi
if [ -z "${BAR_TOKEN}" ]; then
export BAR_TOKEN="$(terraform state show 'random_uuid.management_tokens[1]' | grep result | awk '{print $3}' | tr -d '\"')"
fi

# these may also not be set when running the script outside of Terraform, but they are 'well-known' (aka hard-coded in clusters.tf as locals)
if [ -z "${FOO_API}" ]; then
export FOO_API="http://localhost:8501"
fi
if [ -z "${BAR_API}" ]; then
export BAR_API="http://localhost:9501"
fi

# this may also not be set but we can determine it from what's running
if [ -z "${ENTERPRISE}" ]; then
if docker exec -it consul-alpha-0 consul version | head -n1 | grep +ent > /dev/null 2>&1 ; then
echo "Found Consul Enterprise"
export ENTERPRISE=true
else
echo "Found Consul OSS"
fi
fi

# Peer the default partitions
PEERING_TOKEN_RESP=$(curl -k -s "${ALPHA_API}/v1/peering/token" \
-X POST \
Expand Down Expand Up @@ -47,4 +74,3 @@ then
-H "X-Consul-Partition: bar" \
-d "{\"PeerName\": \"alpha-foo\", \"PeeringToken\": \"${PEERING_TOKEN}\"}"
fi