Skip to content

engineyard/kitchen-ec2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kitchen::Ec2: A Test Kitchen Driver for Amazon EC2

Gem Version Build Status Code Climate

A Test Kitchen Driver for Amazon EC2.

This driver uses the fog gem to provision and destroy EC2 instances. Use Amazon's cloud for your infrastructure testing!

Requirements

There are no external system requirements for this driver. However you will need access to an AWS account.

Installation and Setup

Please read the Driver usage page for more details.

Default Configuration

This driver can determine AMI and username login for a select number of platforms in each region. Currently, the following platform names are supported:

---
platforms:
  - name: ubuntu-10.04
  - name: ubuntu-12.04
  - name: ubuntu-12.10
  - name: ubuntu-13.04
  - name: ubuntu-13.10
  - name: ubuntu-14.04
  - name: centos-6.4
  - name: debian-7.1.0

This will effectively generate a configuration similar to:

---
platforms:
  - name: ubuntu-10.04
    driver:
      image_id: ami-1ab3ce73
      username: ubuntu
  - name: ubuntu-12.04
    driver:
      image_id: ami-2f115c46
      username: ubuntu
  # ...
  - name: centos-6.4
    driver:
      image_id: ami-bf5021d6
      username: root
  # ...

For specific default values, please consult amis.json.

Configuration

associate_public_ip

AWS does not automatically allocate public IP addresses for instances created within non-default subnets. Set this option to true to force allocation of a public IP and associate it with the launched instance.

If you set this option to false when launching into a non-default subnet, Test Kitchen will be unable to communicate with the instance unless you have a VPN connection to your Virtual Private Cloud.

The default is true if you have configured a subnet_id, or false otherwise.

availability_zone

Required The AWS availability zone to use.

The default is "us-east-1b".

aws_access_key_id

Required The AWS access key id to use.

The default will be read from the AWS_ACCESS_KEY environment variable if set, or nil otherwise.

aws_secret_access_key

Required The AWS secret access key to use.

The default will be read from the AWS_SECRET_KEY environment variable if set, or nil otherwise.

aws_ssh_key_id

Required The EC2 SSH key id to use.

The default will be read from the AWS_SSH_KEY_ID environment variable if set, or nil otherwise.

aws_session_token

The AWS session token to use.

The default will be read from the AWS_SESSION_TOKEN environment variable if set, or nil otherwise.

ebs_volume_size

Required Size of ebs volume in GB.

ebs_delete_on_termination

Required true if you want ebs volumes to get deleted automatically after instance is terminated, false otherwise

ebs_device_name

Required name of your ebs device, for example: /dev/sda

endpoint

The API endpoint for executing EC2 commands.

The default will be computed from the AWS region name for the instance.

flavor_id

The EC2 instance type (also known as size) to use.

The default is "m1.small".

ebs_optimized

Option to launch EC2 instance with optimized EBS volume. See Amazon EC2 Instance Types to find out more about instance types that can be launched as EBS-optimized instances.

The default is false.

security_group_ids

An Array of EC2 security groups which will be applied to the instance.

The default is ["default"].

image_id

Required The EC2 AMI id to use.

The default will be determined by the aws_region chosen and the Platform name, if a default exists (see [amis.json][ami_json]). If a default cannot be computed, then the default is nil.

port

The SSH port number to be used when communicating with the instance.

The default is 22.

interface

The place from which to derive the hostname for communicating with the instance. May be dns, public or private. If this is unset, the driver will derive the hostname by failing back in the following order:

  1. DNS Name
  2. Public IP Address
  3. Private IP Address

The default is unset.

region

Required The AWS region to use.

The default is "us-east-1".

ssh_key

Path to the private SSH key used to connect to the instance.

The default is unset, or nil.

ssh_timeout

The number of seconds to sleep before trying to SSH again.

The default is 1.

ssh_retries

The number of times to retry SSH-ing into the instance.

The default is 3.

subnet_id

The EC2 subnet to use.

The default is unset, or nil.

tags

The Hash of EC tag name/value pairs which will be applied to the instance.

The default is { "created-by" => "test-kitchen" }.

username

The SSH username that will be used to communicate with the instance.

The default will be determined by the Platform name, if a default exists (see amis.json). If a default cannot be computed, then the default is "root".

iam_profile_name

The EC2 IAM profile name to use.

The default is nil.

price

The price you bid in order to submit a spot request. An additionnal step will be required during the spot request process submission. If no price is set, it will use an on-demand instance.

The default is nil.

Example

The following could be used in a .kitchen.yml or in a .kitchen.local.yml to override default configuration.

---
driver:
  name: ec2
  aws_access_key_id: KAS...
  aws_secret_access_key: 3UK...
  aws_ssh_key_id: id_rsa-aws
  ssh_key: /path/to/id_rsa-aws
  security_group_ids: ["sg-1a2b3c4d"]
  region: us-east-1
  availability_zone: us-east-1b
  require_chef_omnibus: true
  subnet_id: subnet-6d6...
  iam_profile_name: chef-client
  ssh_timeout: 10
  ssh_retries: 5
  ebs_volume_size: 6,
  ebs_delete_on_termination: 'true'
  ebs_device_name: '/dev/sda'

platforms:
  - name: ubuntu-12.04
    driver:
      image_id: ami-fd20ad94
      username: ubuntu
  - name: centos-6.3
    driver:
      image_id: ami-ef5ff086
      username: ec2-user

suites:
# ...

Both .kitchen.yml and .kitchen.local.yml files are pre-processed through ERB which can help to factor out secrets and credentials. For example:

---
driver:
  name: ec2
  aws_access_key_id: <%= ENV['AWS_ACCESS_KEY'] %>
  aws_secret_access_key: <%= ENV['AWS_SECRET_KEY'] %>
  aws_ssh_key_id: <%= ENV['AWS_SSH_KEY_ID'] %>
  ssh_key: <%= File.expand_path('~/.ssh/id_rsa') %>
  security_group_ids: ["sg-1a2b3c4d"]
  region: us-east-1
  availability_zone: us-east-1b
  require_chef_omnibus: true

platforms:
  - name: ubuntu-12.04
    driver:
      image_id: ami-fd20ad94
      username: ubuntu
  - name: centos-6.3
    driver:
      image_id: ami-ef5ff086
      username: ec2-user

suites:
# ...

Development

Pull requests are very welcome! Make sure your patches are well tested. Ideally create a topic branch for every separate change you make. For example:

  1. Fork the repo
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Authors

Created and maintained by Fletcher Nichol (fnichol@nichol.ca)

License

Apache 2.0 (see LICENSE)

About

A Test Kitchen Driver for Amazon EC2

Resources

License

Stars

Watchers

Forks

Packages

No packages published