Search code examples
amazon-ec2vagrantamazon-vpctest-kitchen

Test Kitchen (chefdk), Vagrant and Amazon VPC


I'm trying to get KitchenCI to build test instances inside my Amazon VPC. I have this working, however when Vagrant goes to attempt to connect to the ec2 instance, it uses the instance's external (public) IP vs it's internal (VPC) IP. Is there any way to change this in Vagrant?

.kitchen.yml:

---
provisioner:
   name: chef_solo

platforms:
  - name: centos-6.5
    driver:
      name: vagrant
  - name: amazon
    driver:
      name: ec2
      image_id: ami-ed8e9284
      flavor_id: t2.medium
      aws_ssh_key_id: DevOps
      ssh_key: /Users/djimenez/.ssh/devops_rsa.pub
      availability_zone: us-east-1a
      subnet_id: subnet-1903a976
      require_chef_omnibus: true
      iam_profile_name: atc
      ebs_delete_on_termination: true
      security_group_ids: sg-7461ae1b

suites:
 <snip>

Solution

  • Looks like I needed to add the following to my .kitchen.yml:

    driver:
      name: ec2
      interface: private
    

    The docs say:

    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.