Hi, i’m trying to setup vault, consul, nomad cluster combo, that is heavily based on:
This setup uses Packer to create an image that already has docker
, docker-compose
, vault
, consul
, nomad
and consul-template
installed and copies a few files for vault, consul, nomad, etc. into the image to be ran later.
Everything goes pretty smooth until initializaing vault:
digitalocean_droplet.server[0] (remote-exec): Error initializing: Put "http://127.0.0.1:8200/v1/sys/init": dial tcp 127.0.0.1:8200: connect: connection refused
digitalocean_droplet.server[0] (remote-exec): Unseal Key (will be hidden):
However i’m not sure why this is happening. Here is my vault-config.hcl
:
storage "consul" {
address = "127.0.0.1:8500"
path = "vault"
}
listener "tcp" {
address = "127.0.0.1:8200"
tls_disable = 1
}
api_addr = "http://127.0.0.1:8200"
ui = true
Here’s the script that is ran to initialize vault:
#! /bin/bash
echo "Initialize Vault on server\n"
export VAULT_ADDR=http://127.0.0.1:8200
if [ $1 == "0" ]; then
vault operator init -address=http://127.0.0.1:8200 > /root/startupOutput.txt
vault operator unseal -address=http://127.0.0.1:8200 `grep "Unseal Key 1" /root/startupOutput.txt | cut -d' ' -f4`
vault operator unseal -address=http://127.0.0.1:8200 `grep "Unseal Key 2" /root/startupOutput.txt | cut -d' ' -f4`
vault operator unseal -address=http://127.0.0.1:8200 `grep "Unseal Key 3" /root/startupOutput.txt | cut -d' ' -f4`
fi
echo "Initialized Vault complete\n"
exit 0
My terraform setup runs it like so:
provisioner "remote-exec" {
inline = [
"sleep 30",
"export VAULT_ADDR=http://127.0.0.1:8200",
"chmod +x /root/init_vault.sh",
"/root/init_vault.sh ${count.index}",
]
}
Can anyone help me figure out why Vault might be failing here?