Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
  • Loading branch information
jonludlam committed May 19, 2014
0 parents commit 0753150
Show file tree
Hide file tree
Showing 13 changed files with 453 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,3 @@
# 0.1.0 (Unreleased)

* Initial release.
14 changes: 14 additions & 0 deletions Gemfile
@@ -0,0 +1,14 @@
source "https://rubygems.org"

gemspec

group :development do
# We depend on Vagrant for development, but we don't add it as a
# gem dependency because we expect to be installed within the
# Vagrant environment itself using `vagrant plugin`.
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
end

group :plugins do
gem "vagrant-xenserver", :path => "."
end
8 changes: 8 additions & 0 deletions LICENSE
@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright (c) 2014 Mitchell Hashimoto

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
251 changes: 251 additions & 0 deletions README.md
@@ -0,0 +1,251 @@
# Vagrant AWS Provider

<span class="badges">
[![Gem Version](https://badge.fury.io/rb/vagrant-aws.png)][gem]
[![Dependency Status](https://gemnasium.com/mitchellh/vagrant-aws.png)][gemnasium]
</span>

[gem]: https://rubygems.org/gems/vagrant-aws
[gemnasium]: https://gemnasium.com/mitchellh/vagrant-aws

This is a [Vagrant](http://www.vagrantup.com) 1.2+ plugin that adds an [AWS](http://aws.amazon.com)
provider to Vagrant, allowing Vagrant to control and provision machines in
EC2 and VPC.

**NOTE:** This plugin requires Vagrant 1.2+,

## Features

* Boot EC2 or VPC instances.
* SSH into the instances.
* Provision the instances with any built-in Vagrant provisioner.
* Minimal synced folder support via `rsync`.
* Define region-specifc configurations so Vagrant can manage machines
in multiple regions.

## Usage

Install using standard Vagrant 1.1+ plugin installation methods. After
installing, `vagrant up` and specify the `aws` provider. An example is
shown below.

```
$ vagrant plugin install vagrant-aws
...
$ vagrant up --provider=aws
...
```

Of course prior to doing this, you'll need to obtain an AWS-compatible
box file for Vagrant.

## Quick Start

After installing the plugin (instructions above), the quickest way to get
started is to actually use a dummy AWS box and specify all the details
manually within a `config.vm.provider` block. So first, add the dummy
box using any name you want:

```
$ vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
...
```

And then make a Vagrantfile that looks like the following, filling in
your information where necessary.

```
Vagrant.configure("2") do |config|
config.vm.box = "dummy"
config.vm.provider :aws do |aws, override|
aws.access_key_id = "YOUR KEY"
aws.secret_access_key = "YOUR SECRET KEY"
aws.keypair_name = "KEYPAIR NAME"
aws.ami = "ami-7747d01e"
override.ssh.username = "ubuntu"
override.ssh.private_key_path = "PATH TO YOUR PRIVATE KEY"
end
end
```

And then run `vagrant up --provider=aws`.

This will start an Ubuntu 12.04 instance in the us-east-1 region within
your account. And assuming your SSH information was filled in properly
within your Vagrantfile, SSH and provisioning will work as well.

Note that normally a lot of this boilerplate is encoded within the box
file, but the box file used for the quick start, the "dummy" box, has
no preconfigured defaults.

If you have issues with SSH connecting, make sure that the instances
are being launched with a security group that allows SSH access.

## Box Format

Every provider in Vagrant must introduce a custom box format. This
provider introduces `aws` boxes. You can view an example box in
the [example_box/ directory](https://github.com/mitchellh/vagrant-aws/tree/master/example_box).
That directory also contains instructions on how to build a box.

The box format is basically just the required `metadata.json` file
along with a `Vagrantfile` that does default settings for the
provider-specific configuration for this provider.

## Configuration

This provider exposes quite a few provider-specific configuration options:

* `access_key_id` - The access key for accessing AWS
* `ami` - The AMI id to boot, such as "ami-12345678"
* `availability_zone` - The availability zone within the region to launch
the instance. If nil, it will use the default set by Amazon.
* `instance_ready_timeout` - The number of seconds to wait for the instance
to become "ready" in AWS. Defaults to 120 seconds.
* `instance_type` - The type of instance, such as "m1.small". The default
value of this if not specified is "m1.small".
* `keypair_name` - The name of the keypair to use to bootstrap AMIs
which support it.
* `private_ip_address` - The private IP address to assign to an instance
within a [VPC](http://aws.amazon.com/vpc/)
* `region` - The region to start the instance in, such as "us-east-1"
* `secret_access_key` - The secret access key for accessing AWS
* `security_groups` - An array of security groups for the instance. If this
instance will be launched in VPC, this must be a list of security group
IDs.
* `iam_instance_profile_arn` - The Amazon resource name (ARN) of the IAM Instance
Profile to associate with the instance
* `iam_instance_profile_name` - The name of the IAM Instance Profile to associate
with the instance
* `subnet_id` - The subnet to boot the instance into, for VPC.
* `associate_public_ip` - If true, will associate a public IP address to an instance in a VPC.
* `tags` - A hash of tags to set on the machine.
* `use_iam_profile` - If true, will use [IAM profiles](http://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html)
for credentials.

These can be set like typical provider-specific configuration:

```ruby
Vagrant.configure("2") do |config|
# ... other stuff

config.vm.provider :aws do |aws|
aws.access_key_id = "foo"
aws.secret_access_key = "bar"
end
end
```

In addition to the above top-level configs, you can use the `region_config`
method to specify region-specific overrides within your Vagrantfile. Note
that the top-level `region` config must always be specified to choose which
region you want to actually use, however. This looks like this:

```ruby
Vagrant.configure("2") do |config|
# ... other stuff

config.vm.provider :aws do |aws|
aws.access_key_id = "foo"
aws.secret_access_key = "bar"
aws.region = "us-east-1"

# Simple region config
aws.region_config "us-east-1", :ami => "ami-12345678"

# More comprehensive region config
aws.region_config "us-west-2" do |region|
region.ami = "ami-87654321"
region.keypair_name = "company-west"
end
end
end
```

The region-specific configurations will override the top-level
configurations when that region is used. They otherwise inherit
the top-level configurations, as you would probably expect.

## Networks

Networking features in the form of `config.vm.network` are not
supported with `vagrant-aws`, currently. If any of these are
specified, Vagrant will emit a warning, but will otherwise boot
the AWS machine.

## Synced Folders

There is minimal support for synced folders. Upon `vagrant up`,
`vagrant reload`, and `vagrant provision`, the AWS provider will use
`rsync` (if available) to uni-directionally sync the folder to
the remote machine over SSH.

This is good enough for all built-in Vagrant provisioners (shell,
chef, and puppet) to work!

## Other Examples

### Tags

To use tags, simply define a hash of key/value for the tags you want to associate to your instance, like:

```ruby
Vagrant.configure("2") do |config|
# ... other stuff

config.vm.provider "aws" do |aws|
aws.tags = {
'Name' => 'Some Name',
'Some Key' => 'Some Value'
}
end
end
```

### User data

You can specify user data for the instance being booted.

```ruby
Vagrant.configure("2") do |config|
# ... other stuff

config.vm.provider "aws" do |aws|
# Option 1: a single string
aws.user_data = "#!/bin/bash\necho 'got user data' > /tmp/user_data.log\necho"

# Option 2: use a file
aws.user_data = File.read("user_data.txt")
end
end
```

## Development

To work on the `vagrant-aws` plugin, clone this repository out, and use
[Bundler](http://gembundler.com) to get the dependencies:

```
$ bundle
```

Once you have the dependencies, verify the unit tests pass with `rake`:

```
$ bundle exec rake
```

If those pass, you're ready to start developing the plugin. You can test
the plugin without installing it into your Vagrant environment by just
creating a `Vagrantfile` in the top level of this directory (it is gitignored)
and add the following line to your `Vagrantfile`
```ruby
Vagrant.require_plugin "vagrant-aws"
```
Use bundler to execute Vagrant:
```
$ bundle exec vagrant up --provider=aws
```
21 changes: 21 additions & 0 deletions Rakefile
@@ -0,0 +1,21 @@
require 'rubygems'
require 'bundler/setup'
require 'rspec/core/rake_task'

# Immediately sync all stdout so that tools like buildbot can
# immediately load in the output.
$stdout.sync = true
$stderr.sync = true

# Change to the directory of this file.
Dir.chdir(File.expand_path("../", __FILE__))

# This installs the tasks that help with gem creation and
# publishing.
Bundler::GemHelper.install_tasks

# Install the `spec` task so that we can run tests.
RSpec::Core::RakeTask.new

# Default task is to run the unit tests
task :default => "spec"
16 changes: 16 additions & 0 deletions lib/vagrant-xenserver.rb
@@ -0,0 +1,16 @@
require "pathname"

require "vagrant-xenserver/plugin"

module VagrantPlugins
module XenServer
lib_path = Pathname.new(File.expand_path("../vagrant-xenserver", __FILE__))
autoload :Action, lib_path.join("action")
autoload :Errors, lib_path.join("errors")

def self.source_root
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
end
end
end

21 changes: 21 additions & 0 deletions lib/vagrant-xenserver/action.rb
@@ -0,0 +1,21 @@
require 'vagrant/action/builder'
require 'log4r'

module VagrantPlugins
module XenServer
module Action
include Vagrant::Action::Builtin
@logger = Log4r::Logger.new('vagrant_xenserver::action')

def self.action_up
Vagrant::Action::Builder.new.tap do |b|
b.use DummyMessage
end
end

action_root = Pathname.new(File.expand_path('../action', __FILE__))
autoload :DummyMessage, action_root.join('dummy')
end
end
end

16 changes: 16 additions & 0 deletions lib/vagrant-xenserver/action/dummy.rb
@@ -0,0 +1,16 @@
module VagrantPlugins
module XenServer
module Action
class DummyMessage
def initialize(app, env)
@app = app
end

def call(env)
env[:ui].info("dummy")
end
end
end
end
end

17 changes: 17 additions & 0 deletions lib/vagrant-xenserver/config.rb
@@ -0,0 +1,17 @@
require "vagrant"

module VagrantPlugins
module AWS
class Config < Vagrant.plugin("2", :config)
attr_accessor :dummy

def initialize
@dummy = UNSET_VALUE
end

def finalize!
@dummy = 0 if @dummy == UNSET_VALUE
end
end
end
end

0 comments on commit 0753150

Please sign in to comment.