What is the IBM Packer Plugin, and how can you create a custom image on IBM Cloud – VPC Infrastructure?

Packer is HashiCorp’s open-source tool for creating custom machine images from a single source configuration. This means users can customize an image with a pre-configured operating system and installed software for a specific use-case and then use it to quickly launch completely provisioned and configured instances.

What is the IBM Packer Plugin?

On the other hand, a Packer Plugin allows new functionality to be added to Packer without modifying the Packer core. The IBM Packer Plugin is a separate, standalone application; the core of Packer starts and communicates with it, and the plugin enables Packer to connect to and work with IBM Cloud resources. 

IBM Packer Plugin adds on two Builders — one for Classic and one for VPC. A Builder is a Packer component responsible for creating a machine image. First, the Builder reads in a Packer Template — a configuration file that defines the image you want to build and how to build it. From this configuration file, the Builder takes a source OS (Linux- or Windows-based) and provisions a Virtual Server Instance (VSI) on IBM Cloud. Then, the Builder installs software for a specific use-case and generates an image out of the VSI. This generated image can be reused to launch new completely provisioned and configured VSIs instances within IBM Cloud. 

Therefore, by using the IBM Packer Plugin, you can quickly create identical machine images from a single source configuration on both Classic and VPC infrastructure.


  • Classic: The classic builder supports the creation of custom images (.VHD) on IBM Cloud – Classic Infrastructure.
  • VPC: The vpc builder supports the creation of custom images on IBM Cloud – VPC Infrastructure.

IBM Packer Plugin workflow


Prepare your end to run the plugin:

  • Install Packer >= 1.7
  • Install Ansible >= 2.10, if Ansible is your preferred Provisioner (recommended)
  • Install Go >= 1.17, if you want to use manual installation
    • Environment variables for golang setup:
      export GOPATH=$HOME/go
      export GOROOT=/usr/local/go
      export PATH=$PATH:$GOPATH/bin:$GOROOT/bin
      export PACKERPATH=/usr/local/packer
    • For Windows image, install the Python package for winrm:
       pip3 install --ignore-installed "pywinrm>=0.2.2" --user


Create configuration files and folders

From the IBM Packer Plugin repo:

  • Create your preferred folder (i.e., mkdir $HOME/packer-plugin-ibmcloud/).
  • Create the .env file and set IBM Cloud Credentials. Also, set Packer and Ansible environment variables:
    # VPC
    export IBM_API_KEY=""
    # Classic
    export SL_USERNAME=""
    export SL_API_KEY=""
    export ANSIBLE_INVENTORY_FILE="provisioner/hosts"
    export PACKER_LOG=1
    export PACKER_LOG_PATH="packerlog/packerlog.txt"
  • Copy the Packer Templates examples folder: cp -r examples $HOME/packer-plugin-ibmcloud/. This folder will store Packer Template examples for different OS and Provisioners.
  • Copy the Windows-based VSI config scripts folder: cp -r scripts $HOME/packer-plugin-ibmcloud/. This folder will store required config scripts to setup WinRM communication with Windows VSIs.
  • Copy the Ansible playbooks folder: cp -r provisioner $HOME/packer-plugin-ibmcloud/. This folder will store Provisioner’s scripts.
  • Create the Packer log folder (recall env variable PACKER_LOG_PATH) cp -r packerlog $HOME/packer-plugin-ibmcloud/.

Use the packer init command

Starting with version 1.7, Packer supports third-party plugin installation using the packer init command (read the Packer documentation for more information). packer init downloads the Packer Plugin binaries required in your Packer Template. To install a Packer Plugin, just copy and paste the required_plugins block inside your Packer Template:

packer {
    required_plugins {
        ibmcloud = {
            version = ">=v3.0.0"
            source = "github.com/IBM/ibmcloud"

Then, run packer init -upgrade <packer-template-name>.

Note: Be aware that packer init does not work with legacy JSON templates. Upgrade your JSON config files to HCL. The IBM Packer plugin will be installed on $HOME/.packer.d/plugins.

Run the Packer Plugin

  • Run the source command to read and execute commands from the .env file: source .env.
  • Finally, run the Packer plugin commands:
    • packer validate examples/build.vpc.centos.pkr.hcl
    • packer build examples/build.vpc.centos.pkr.hcl


Packer Plugins allow new functionality to be added to Packer without modifying the Packer core. The IBM Packer Plugin is a completely separate, standalone application that can be used to create custom images on IBM Cloud – VPC Infrastructure and then use those images to quickly launch completely provisioned and configured instances. Moreover, the automation to use this tool will help you reduce the amount of time spent on manual processes and configuration and let you use IBM Packer Plugin right away.

If you have feedback, suggestions or questions about this post, please reach out to me here


More from Cloud

IBM Tech Now: October 2, 2023

< 1 min read - ​Welcome IBM Tech Now, our video web series featuring the latest and greatest news and announcements in the world of technology. Make sure you subscribe to our YouTube channel to be notified every time a new IBM Tech Now video is published. IBM Tech Now: Episode 86 On this episode, we're covering the following topics: AI on IBM Z IBM Maximo Application Suite 8.11 IBM NS1 Connect Stay plugged in You can check out the IBM Blog Announcements for a…

IBM Cloud inactive identities: Ideas for automated processing

4 min read - Regular cleanup is part of all account administration and security best practices, not just for cloud environments. In our blog post on identifying inactive identities, we looked at the APIs offered by IBM Cloud Identity and Access Management (IAM) and how to utilize them to obtain details on IAM identities and API keys. Some readers provided feedback and asked on how to proceed and act on identified inactive identities. In response, we are going lay out possible steps to take.…

IBM Cloud VMware as a Service introduces multitenant as a new, cost-efficient consumption model

4 min read - Businesses often struggle with ongoing operational needs like monitoring, patching and maintenance of their VMware infrastructure or the added concerns over capacity management. At the same time, cost efficiency and control are very important. Not all workloads have identical needs and different business applications have variable requirements. For example, production applications and regulated workloads may require strong isolation, but development/testing, training environments, disaster recovery sites or other applications may have lower availability requirements or they can be ephemeral in nature,…

IBM accelerates enterprise AI for clients with new capabilities on IBM Z

5 min read - Today, we are excited to unveil a new suite of AI offerings for IBM Z that are designed to help clients improve business outcomes by speeding the implementation of enterprise AI on IBM Z across a wide variety of use cases and industries. We are bringing artificial intelligence (AI) to emerging use cases that our clients (like Swiss insurance provider La Mobilière) have begun exploring, such as enhancing the accuracy of insurance policy recommendations, increasing the accuracy and timeliness of…