Skip to content

Latest commit

 

History

History
56 lines (33 loc) · 2.25 KB

File metadata and controls

56 lines (33 loc) · 2.25 KB

Packer Docker Example

This folder contains a Packer template to demonstrate how you can use Terratest to write automated tests for your Packer templates. The template creates an Ubuntu AMI with a simple web app (built on top of Ruby / Sinatra) installed. This template also creates a Docker image with the same web app installed, and contains a docker-compose.yml file for running that Docker image. These allow you to test your Packer template completely locally, without having to deploy to AWS.

Check out test/packer_docker_example_test.go to see how you can write automated tests for this simple template.

The Docker-based tests in this folder are in some sense "unit tests" for the Packer template. To see an example of "integration tests" that deploy the AMI to AWS, check out the terraform-packer-example.

Building a Docker image for local testing

  1. Install Packer and make sure it's on your PATH.
  2. Install Docker and make sure it's on your PATH.
  3. Run packer build -only=ubuntu-docker build.json.
  4. Run docker-compose up.
  5. You should now be able to access the sample web app at http://localhost:8080

Building an AMI for testing in AWS

  1. Sign up for AWS.
  2. Configure your AWS credentials using one of the supported methods for AWS CLI tools, such as setting the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.
  3. Install Packer and make sure it's on your PATH.
  4. Run packer build -only=ubuntu-ami build.json.

Running automated tests locally against this Packer template

  1. Install Packer and make sure it's on your PATH.
  2. Install Docker and make sure it's on your PATH.
  3. Install Golang and make sure this code is checked out into your GOPATH.
  4. cd test
  5. dep ensure
  6. go test -v -run TestPackerDockerExampleLocal

Running automated tests in AWS against this Packer template

See terraform-packer-example.