DevOps Classroom Series – 14/Mar/2021

Using Packer with Azure

  • Lets use packer json templates to create azure vm with lamp stack

  • Refer Here for the official microsoft docs on using packer to create a linux vm image

  • Refer Here for the changes done

  • Now lets apply packer build Preview Preview Preview Preview

  • Refer Here for the changeset with multiple builders in packer

  • Lets upgrade existing template into hcl format

    "builders": [
            "type": "amazon-ebs",
            "ami_name": "lampfrompacker-{{isotime | clean_resource_name}}",
            "ami_description": "This is lamp stack",
            "region": "us-west-2",
            "instance_type": "t2.micro",
            "source_ami" : "ami-02701bcdc5509e57b",
            "ssh_username": "ubuntu",
            "communicator": "ssh"

    "description": "Create a lamp stack",
    "provisioners": [
            "type": "shell",
            "script": ""


  • Lets upgrade Preview
  • The script looks as shown below

locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }

# template: hcl2_upgrade:4:48: executing "hcl2_upgrade" at <clean_resource_name>: error calling clean_resource_name: unhandled "clean_resource_name" call:
# there is no way to automatically upgrade the "clean_resource_name" call.
# Please manually upgrade to use custom validation rules, `replace(string, substring, replacement)` or `regex_replace(string, substring, replacement)`
# Visit , or for more infos.

source "amazon-ebs" "autogenerated_1" {
  ami_description = "This is lamp stack"
  ami_name        = "lampfrompacker-{{isotime | clean_resource_name}}"
  communicator    = "ssh"
  instance_type   = "t2.micro"
  region          = "us-west-2"
  source_ami      = "ami-02701bcdc5509e57b"
  ssh_username    = "ubuntu"

build {
  description = "Create a lamp stack"

  sources = [""]

  provisioner "shell" {
    script = ""


  • Refer Here for the changeset containing both old and new style
  • Refer Here for the new hcl2 format written in the class

Leave a Reply

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

About learningthoughtsadmin