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

  • 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": "lamp.sh"
        }
    ]
}

  • Lets upgrade
  • 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 https://packer.io/docs/templates/hcl_templates/variables#custom-validation-rules , https://www.packer.io/docs/templates/hcl_templates/functions/string/replace or https://www.packer.io/docs/templates/hcl_templates/functions/string/regex_replace 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 = ["source.amazon-ebs.autogenerated_1"]

  provisioner "shell" {
    script = "lamp.sh"
  }

}

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

Leave a ReplyCancel reply

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

Please turn AdBlock off
Social Network Integration by Acurax Social Media Branding Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%