Skip to content

Commit

Permalink
F update vagrantfile (hashicorp#46)
Browse files Browse the repository at this point in the history
* Update Vagrantfile

* Update output

* Fix output

* Update Vagrantfile

* Don't run tests
  • Loading branch information
bensojona authored Jun 10, 2018
1 parent a97921e commit 3744762
Showing 1 changed file with 35 additions and 43 deletions.
78 changes: 35 additions & 43 deletions operations/provision-vault/dev/vagrant-local/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

# Networking
private_ip = ENV['PRIVATE_IP'] || "192.168.50.152"
consul_host_port = ENV['CONSUL_HOST_PORT'] || 8500
vault_host_port = ENV['VAULT_HOST_PORT'] || 8200

# Base box selection
base_box = ENV['BASE_BOX'] || "bento/ubuntu-16.04"

# Consul variables
consul_install = ["true", "1"].include?((ENV['CONSUL_INSTALL'] || true).to_s.downcase)
consul_host_port = ENV['CONSUL_HOST_PORT'] || 8500
consul_version = ENV['CONSUL_VERSION'] || "1.0.6"
consul_ent_url = ENV['CONSUL_ENT_URL']
consul_group = "consul"
Expand All @@ -18,25 +18,20 @@ consul_comment = "Consul"
consul_home = "/srv/consul"

# Vault variables
vault_host_port = ENV['VAULT_HOST_PORT'] || 8200
vault_version = ENV['VAULT_VERSION'] || "0.10.0"
vault_ent_url = ENV['VAULT_ENT_URL']
vault_group = "vault"
vault_user = "vault"
vault_comment = "Vault"
vault_home = "/srv/vault"

# Tests & cleanup
run_tests = ENV['RUN_TESTS']
cleanup = ENV['CLEANUP']

Vagrant.configure("2") do |config|
# Use vagrant insecure public key, comment this out to restrict access
config.ssh.insert_key = false

# Setup networking
config.vm.network :private_network, ip: private_ip
config.vm.network :forwarded_port, guest: 8500, host: consul_host_port, auto_correct: true
config.vm.network :forwarded_port, guest: 8200, host: vault_host_port, auto_correct: true
config.vm.network "private_network", type: "dhcp"

# Use base_box set at the top of this file
Expand All @@ -46,25 +41,33 @@ Vagrant.configure("2") do |config|
# Bootstrap the vm
config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/shared/scripts/base.sh | bash"

# Setup Consul user
config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/shared/scripts/setup-user.sh | bash",
env: {
"GROUP" => consul_group,
"USER" => consul_user,
"COMMENT" => consul_comment,
"HOME" => consul_home,
}

# Install Consul
config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/consul/scripts/install-consul.sh | bash",
env: {
"VERSION" => consul_version,
"URL" => consul_ent_url,
"USER" => consul_user,
"GROUP" => consul_group,
}
if (consul_install)
# Forward Consul port
config.vm.network :forwarded_port, guest: 8500, host: consul_host_port, auto_correct: true

# Setup Consul user
config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/shared/scripts/setup-user.sh | bash",
env: {
"GROUP" => consul_group,
"USER" => consul_user,
"COMMENT" => consul_comment,
"HOME" => consul_home,
}

# Install Consul
config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/consul/scripts/install-consul.sh | bash",
env: {
"VERSION" => consul_version,
"URL" => consul_ent_url,
"USER" => consul_user,
"GROUP" => consul_group,
}

config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/consul/scripts/install-consul-systemd.sh | bash"
end

config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/consul/scripts/install-consul-systemd.sh | bash"
# Forward Vault port
config.vm.network :forwarded_port, guest: 8200, host: vault_host_port, auto_correct: true

# Setup Vault user
config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/shared/scripts/setup-user.sh | bash",
Expand All @@ -86,19 +89,6 @@ Vagrant.configure("2") do |config|

config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/vault/scripts/install-vault-systemd.sh | bash"

# Setup tests
config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/shared/scripts/setup-testing.sh | bash"

# Run tests if `RUN_TESTS` env var is provided
if (run_tests)
config.vm.provision "shell", inline: "cd /tmp && rake vault:spec"
end

# Cleanup if `CLEANUP` env var is provided
if (cleanup)
config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/shared/scripts/cleanup.sh | bash"
end

# Increase memory for Parallels Desktop
config.vm.provider "parallels" do |p, o|
p.memory = "1024"
Expand All @@ -123,9 +113,11 @@ To SSH into a Vault host, run the below command.
$ vagrant ssh
You can interact with Vault using any of the CLI (https://www.vaultproject.io/docs/commands/index.html) or API (https://www.vaultproject.io/api/index.html) commands.
You can interact with Vault using any of the CLI (https://www.vaultproject.io/docs/commands/index.html)
or API (https://www.vaultproject.io/api/index.html) commands.
# The Root token for your Vault -dev instance is set to `root` and placed in /srv/vault/.vault-token, the `VAULT_TOKEN` environment variable has already been set for you
# The Root token for your Vault -dev instance is set to `root` and placed in /srv/vault/.vault-token,
# the `VAULT_TOKEN` environment variable has already been set for you
$ echo $VAULT_TOKEN
$ sudo cat /srv/vault/.vault-token
Expand All @@ -137,8 +129,8 @@ You can interact with Vault using any of the CLI (https://www.vaultproject.io/do
$ curl -H \"X-Vault-Token: $VAULT_TOKEN\" -X POST -d '{\"data\": {\"bar\":\"baz\"}}' http://127.0.0.1:8200/v1/secret/data/api | jq '.'
$ curl -H \"X-Vault-Token: $VAULT_TOKEN\" http://127.0.0.1:8200/v1/secret/data/api | jq '.'
Visit the Consul UI: http://#{private_ip}:#{consul_host_port}/
Visit the Vault UI: http://#{private_ip}:#{vault_host_port}/
Visit the Vault UI: http://#{private_ip}:#{vault_host_port}
#{consul_install ? 'Visit the Consul UI: http://'+ private_ip + ':' + consul_host_port.to_s : ''}
Don't forget to tear your VM down after.
Expand Down

0 comments on commit 3744762

Please sign in to comment.