 # -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  # All Vagrant configuration is done here. The most common configuration
  # options are documented and commented below. For a complete reference,
  # please see the online documentation at vagrantup.com.

  config.vm.hostname = "pgbouncer-test"

  # Every Vagrant virtual environment requires a box to build off of.
  config.vm.box = "precise64"

  # The url from where the 'config.vm.box' box will be fetched if it
  # doesn't already exist on the user's system.
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"

  # This uses the vagrant-chefzero plugin built by Whitepages, which can
  # be found here: https://github.com/whitepages/vagrant-chefzero/
  #
  chef_zero_ip = '33.33.33.9'
  target_ip = '33.33.33.10'
  chef_zero_port = 8889

  config.vm.define :chefzero do |chefzero|
    chefzero.vm.box = 'precise64'
    chefzero.vm.network :private_network, ip: chef_zero_ip

    chefzero.vm.provision :chefzero do |cz|
      cz.ip = chef_zero_ip
      cz.port = chef_zero_port
      cz.setup do |p|
        p.import_berkshelf_cookbooks
      end
    end
  end

  # Enable provisioning with chef server, specifying the chef server URL,
  # and the path to the validation key (relative to this Vagrantfile).
  #
  # The Opscode Platform uses HTTPS. Substitute your organization for
  # ORGNAME in the URL and validation key.
  #
  # If you have your own Chef Server, use the appropriate URL, which may be
  # HTTP instead of HTTPS depending on your configuration. Also change the
  # validation key to validation.pem.
  #
  config.vm.define :target do |target|
    target.vm.network :private_network, ip: target_ip
    target.vm.provision :chef_client do |chef|
      chef.chef_server_url = "http://#{chef_zero_ip}:#{chef_zero_port}"
      chef.validation_key_path = ".chef/test.pem"

      chef.add_recipe "pgbouncer::example"
    end
  end
end
