diff --git a/consul-resources/templates/template-config.hcl.ctmpl b/consul-resources/templates/template-config.hcl.ctmpl index c9560f5..a6c5818 100644 --- a/consul-resources/templates/template-config.hcl.ctmpl +++ b/consul-resources/templates/template-config.hcl.ctmpl @@ -1,7 +1,7 @@ consul = "{{ env "CONSUL_HOSTNAME" }}:{{ env "CONSUL_PORT" }}" vault { - address = "http://{{ env "CONSUL_HOSTNAME" }}:8200" + address = "http://{{ env "VAULT_HOSTNAME" }}:{{ env "VAULT_PORT" }}" token = "{{ env "VAULT_TOKEN" }}" renew = false } diff --git a/init.sh b/init.sh index 6f19416..2f40a3a 100644 --- a/init.sh +++ b/init.sh @@ -6,6 +6,7 @@ export DOCK_INIT_BASE=/opt/runnable/dock-init export HOST_IP=$(hostname -i) +source "${DOCK_INIT_BASE}/lib/util/log.sh" if [ -z "${CONSUL_PORT+x}" ]; then export CONSUL_PORT=8500 @@ -14,11 +15,24 @@ else fi if [ -z "${CONSUL_HOSTNAME+x}" ]; then - export CONSUL_HOSTNAME=10.4.5.144 + log::fatal "CONSUL_HOSTNAME is not defined" + exit 1 else export CONSUL_HOSTNAME fi +if [ -z "${VAULT_PORT+x}" ]; then + export VAULT_PORT=8200 +else + export VAULT_PORT +fi + +if [ -z "${VAULT_HOSTNAME+x}" ]; then + export VAULT_HOSTNAME=$CONSUL_HOSTNAME +else + export VAULT_HOSTNAME +fi + export DOCKER_NETWORK=172.17.0.0/16 source "${DOCK_INIT_BASE}/lib/consul.sh" @@ -26,7 +40,6 @@ source "${DOCK_INIT_BASE}/lib/aws.sh" source "${DOCK_INIT_BASE}/lib/dock.sh" source "${DOCK_INIT_BASE}/lib/container.sh" source "${DOCK_INIT_BASE}/lib/iptables.sh" -source "${DOCK_INIT_BASE}/lib/util/log.sh" # Initializes the dock main() { diff --git a/lib/vault.sh b/lib/vault.sh index dbe23c3..74aff74 100644 --- a/lib/vault.sh +++ b/lib/vault.sh @@ -16,7 +16,7 @@ vault::create_s3_policy() { "Dock-Init: Cannot create policy template for ${bucket}" \ "Attempting to create s3 policy template. ${OUTPUT}" - export VAULT_ADDR="http://${CONSUL_HOSTNAME}:8200" + export VAULT_ADDR="http://${VAULT_HOSTNAME}:${VAULT_PORT}" log::info "Attempting to create s3 policy template for bucket ${bucket}" local policy_template="${DOCK_INIT_BASE}/vault-resources/s3.policy" @@ -35,7 +35,7 @@ vault::set_s3_keys() { "Dock-Init: Cannot create policy template" \ "Attempting to create s3 policy template. ${OUTPUT}" - export VAULT_ADDR="http://${CONSUL_HOSTNAME}:8200" + export VAULT_ADDR="http://${VAULT_HOSTNAME}:${VAULT_PORT}" log::info "Attempting get s3 creds" # Key Value # lease_id aws/creds/deploy/7cb8df71-782f-3de1-79dd-251778e49f58