rorono
11/1/2015 - 4:51 PM

aws をmacから起動するvagrantfile

aws をmacから起動するvagrantfile

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

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"


Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "dummy"
  config.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
  access_key = ENV['AWS_ACCESS_KEY']
  access_secret = ENV['AWS_SECRET_KEY']
  config.ssh.pty = false

  config.vm.provider :aws do |aws, override|
    aws.keypair_name = "vagrant"
    aws.instance_type = "t2.micro"
    aws.region = "ap-northeast-1"
    aws.availability_zone =  "ap-northeast-1c"
    aws.ami = "ami-9a2fb89a"
    aws.security_groups = [ 'vagrant' ]
    aws.tags = {
      "Name" => "vagrant-test",
      "Description" => "vagrant test"
    }

    # enable sudo without tty
    # NOTE: setting [ ssh.pty = true ] causes file provisioner fail
    aws.user_data = <<-USER_DATA
      #!/bin/sh
      echo "Defaults    !requiretty" > /etc/sudoers.d/vagrant-init
      chmod 440 /etc/sudoers.d/vagrant-init
    USER_DATA

    # disable synced_folder:
    override.vm.synced_folder "./", "/vagrant", disabled: true

    override.ssh.username = "ec2-user"
    override.ssh.private_key_path = "~/.ssh/vagrant.pem"
  end
end