Hashicorp Atlas workflow with Vagrant, Packer and Terraform

I have used and loved Vagrant for a long time and I recently used Consul and I was very impressed by both these Devops tools. Recently, I saw some of the videos of Hashiconf and I learnt that Hashicorp has an ecosystem of tools addressing Devops needs and that these tools can be chained together to create complete application delivery platform from development to production. Atlas is Hashicorp’s product that combines its open source tools into a platform and it has a commercial version as well. In this blog, I will cover a development to production workflow for a LAMP application stack using Atlas, Vagrant, Packer and Terraform.

Overview of Vagrant, Packer, Terraform and Atlas


Vagrant provides a repeatable VM development environment. Vagrant integrates well with major hypervisors like Virtualbox, VMWare, HyperV. “Vagrantfile” describes the VM settings as well as initial bootstrap provisioning that needs to be done on the VM. Vagrant also integrates well with other provisioning tools like Chef, Ruby and Ansible to describe the provisioning. Simply by doing “vagrant up”, the complete VM environment is exactly reproduced. The typical problems like “it does not work for me even though its working in your machine” goes away.


Packer is a tool to create machine images for providers like Virtualbox, VMWare, AWS, Google cloud. Packer configuration is described as a JSON file and images for multiple providers can be created in parallel. The typical workflow is for developer to create development environment in Vagrant and once it becomes stable, the production image can be built from Packer. Since the provisioning part is baked into the image, the deployment of production images becomes much faster. Following link describes how Vagrant and Packer fits well together.


Terraform allows us to describe the whole data center as a configuration file and it takes care of deploying the infrastructure on either VM, baremetal or cloud. Once the configuration file is under source code, Infrastructure can be treated as Software. Terraform is like Openstack Heat or AWS Cloudformation, the great thing about Terraform is that it is provider agnostic and it can integrate with any provider. Terraform has nice features like “Plan” which shows the changes needed before any change is done and “Graph” which shows the dependencies within infrastructure components.


Atlas provides a Devops workflow integrating different Hashicorp tools. Atlas provides a way to run Hashicorp tools in the cloud and create a workflow between the tools. Atlas also provides a way to share Vagrant boxes and Vagrantfile across developers, this is like Dockerhub for Containers. Following picture from Hashicorp shows a workflow from development to production. Developer has a development environment in Vagrant where he/she develops code. Atlas takes care of building the production image using Packer, storing it in artifact repository and deploying using Terraform.


LAMP Application

To try the Atlas workflow, I have built a LAMP stack and deployed it using Hashicorp tools. The complete code is available here. Following is the workflow:

  • For Vagrant, create a Vagrantfile with installation script to install apache2, php and mysql and the necessary dependencies.
  • Once the environment is tested in Vagrant, create a Packer configuration file to create images for Amazon and Google cloud. Push the created artifacts to Atlas.
  • Create a Terraform configuration file and push it to Atlas to deploy the LAMP stack in AWS cloud.
  • As of now, my Packer file builds Amazon and Google cloud images, but the Terraform deployment does only for AWS.
  • We can setup Atlas to automatically do the deployment when new artifacts are uploaded to Atlas. For example, when I push a new LAMP stack using Packer, Atlas triggers Terraform to do the new deployment without any user intervention.


  • Install latest versions of Vagrant, Packer and Terraform.
  • Have AWS and Google cloud accounts. If it is not in free-tier, it will cost money..
  • Need to have Atlas account.

Detailed Steps


Base image used for Vagrant is ubuntu/trusty64. “script.sh” contains the provisioning commands for installing Apache, php, mysql and related dependencies.
To get VM environment, we can do

vagrant up


Following are some relevant points regarding Packer configuration file:

  • There are 2 builders, 1 for AWS and another for Google cloud.
  • There is 1 provisioner section for installing Apache, php, mysql and related dependencies. This is common to both builders.
  • There are 2 post-processors, 1 for creating AWS AMI image and another for creating Google cloud image. By specifying image type as “Atlas”, we are requesting Packer to push the image to Atlas.

Following command creates AWS image in Atlas:

packer build -var 'aws_access_key=<>' 'aws_secret_key=<>' -var 'atlas_token=<>' -only=amazon-ebs lamp.json

If we skip “-only” option, both Google and AWS images will be pushed to Atlas.


Following are some relevant points regarding Terraform configuration file:

  • There are 3 files: “variables.tf” has the variables used in main terraform file, “main.tf” contains all infrastructure that needs to be created, “output.tf” contains the relevant outputs that can be used for quick reference.
  • “main.tf” specifies provider as AWS, creates security group to allow traffic to port 22 and 80, creates instance with LAMP stack.
  • We specify AMI as “ami = “${atlas_artifact.lamp.metadata_full.region-us-west-2}”. This tells Terraform to pick the VM image from Atlas that was created using Packer.

Following command pushes Terraform configuration to Atlas.

terraform push -name='smakam/awslamp' -var 'key_name=<>' -var 'ssh_key=<>' -var 'aws_secret_key=<>' -token='<>' -vcs=false

From Atlas GUI settings section, we can select “Plan on Artifact reload” to allow new Artifact to trigger Terraform build and “autoapply” to allow for Terraform apply without user intervention.

Following video shows the recording of this workflow.


Hashicorp’s tools are very easy to use and each tool targets a specific set of use cases. The fact that the tools are Open source gives flexibility for the user to add any specific enhancements if needed. Hashicorp’s tools were initially oriented towards VMs but they have added integrations with Docker and Containers recently. For example, Hashicorp introduced Docker provider for Vagrant recently. I also found this discussion in the net interesting that compares Vagrant and Docker. Atlas is Hashicorp’s integrated platform also available as a commercial solution. Docker has quite a few Container management tools managed as a single platform using UCP similar to Hashicorp’s Atlas. It will be interesting to see how Hashicorp’s tools will integrate with Docker tools and how customers would be using both of these together. I will try to cover other Hashicorp tools like Consul, Otto, Nomad, Vault in my later blogs.



5 thoughts on “Hashicorp Atlas workflow with Vagrant, Packer and Terraform

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s