Packer Classroom Series – 13/Sep/2019

Packer Variables


  • Make packer template generic
  • This increases reusability

Packer Variable Types

  • User Variables
  • Environment Variables

Syntax for Creating Variables

    "variables": {
        "variable_name_1": "variable value"
    "builders": [{

    "provisioners": [



Syntax for using variable

  • User Variables: assume you have defined a user variable called as package
{{user `package`}}
  • Environment Variables: assume you want to use PATH
{{env `PATH`}}

First Version of Pet-clinic

    "variables": {
        "aws_access_key": "",
        "aws_secret_key": "",
        "aws_region": "us-west-2",
        "aws_source_ami":  "ami-06f2f779464715dc5"      
            "type": "amazon-ebs",
            "access_key": "{{user `aws_access_key`}}",
            "ami_name": "petclinic--{{isotime | clean_resource_name}}",
            "instance_type": "t2.micro",
            "region": "{{user `aws_region`}}",
            "secret_key": "{{user `aws_secret_key`}}",
            "source_ami": "{{user `aws_source_ami`}}",
            "ssh_username": "ubuntu"
            "type": "shell",
            "script": "./"


sudo apt-get update
sudo apt-get install openjdk-8-jdk -y
echo "Spring petclinic is copied at /home/ubuntu/spring-petclinic.jar"

Commands to use

packer build -var 'aws_access_key=<youraccesskey>' -var 'aws_secret_key=<yoursecretkey> ./aws.json


  1. Create a reusable packer template with tomcat installed
  2. create a reusable packer template with nginx installed

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner