Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Tutorials
    • All tutorials
    • Basic internet service architecture and protection
    • Cost analysis by resource using Object Storage
      • Getting started with Terraform
      • Terraform data sources
      • Uploading Terraform states to Object Storage
      • Getting started with Packer
      • Building a VM image with infrastructure tools using Packer
      • Locking Terraform states using Managed Service for YDB
      • Using Yandex Cloud modules in Terraform
      • Creating a VM and an instance group with a Container Optimized Image using Terraform
      • Transferring logs through Unified Agent HTTP input to Cloud Logging

In this article:

  • Get your cloud ready
  • Configure the environment and infrastructure
  • Required paid resources
  • Install and configure Packer
  • From a mirror
  • From the HashiCorp website
  • Configure the Yandex Compute Builder plugin
  • Prepare the image configuration
  • Create an image
  • Check the image
  • Delete the resources you created
  1. Basic infrastructure
  2. Tools
  3. Getting started with Packer

Getting started with Packer

Written by
Yandex Cloud
Updated at May 7, 2025
  • Get your cloud ready
    • Configure the environment and infrastructure
    • Required paid resources
  • Install and configure Packer
    • From a mirror
    • From the HashiCorp website
    • Configure the Yandex Compute Builder plugin
  • Prepare the image configuration
  • Create an image
  • Check the image
    • Delete the resources you created

Packer enables you to create VM disk images and set their properties in a configuration file. This guide describes how to create a disk image in Yandex Compute Cloud using Packer.

In this scenario, Packer will create and launch a Debian 11 virtual machine from Cloud Marketplace, with a nginx web server installed on it. Following that, it will delete the VM and create an image of its boot disk. After that, it will also delete the disk.

To create an image:

  1. Get your cloud ready.
  2. Install Packer.
  3. Prepare the image configuration.
  4. Create an image.
  5. Check the image.

If you no longer need the image you created, delete it.

Get your cloud readyGet your cloud ready

Sign up in Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or register a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can navigate to the cloud page to create or select a folder for your infrastructure to operate in.

Learn more about clouds and folders.

Configure the environment and infrastructureConfigure the environment and infrastructure

  1. Install the Yandex Cloud command line interface (CLI).

    Tip

    If you access the cloud with a federated account and want to use the CLI from within your VM, get authenticated in the CLI as a service account.

  2. Create a cloud network with a single subnet in your folder.

  3. Get an OAuth token for a Yandex account or an IAM token for a federated account.

Required paid resourcesRequired paid resources

The cost of creating a disk image using Packer includes:

  • Fee for storing created images (see Yandex Compute Cloud pricing).
  • Fee for VM computing resources (see Yandex Compute Cloud pricing).

Install and configure PackerInstall and configure Packer

Warning

Yandex Cloud requires Packer 1.5 or higher.

Do not use popular package managers, such as Homebrew or APT, to install Packer. Their repositories may contain obsolete versions.

You can install Packer from a mirror or the HashiCorp website:

From a mirrorFrom a mirror

Install a Packer distribution kit for your platform from a mirror:

Linux
Windows
macOS
  1. Download a Packer distribution kit from the mirror and extract it into the packer directory:

    mkdir packer
    wget https://hashicorp-releases.yandexcloud.net/packer/1.11.2/packer_1.11.2_linux_amd64.zip -P ~/packer
    unzip ~/packer/packer_1.11.2_linux_amd64.zip -d ~/packer
    

    This example uses version 1.11.2. For the latest Packer version, see the mirror.

  2. Add Packer to the PATH variable:

    1. Add the following line to the .profile file:

      export PATH="$PATH:/home/<username>/packer"
      
    2. Save your changes.

    3. Restart the shell:

      exec -l $SHELL
      
  3. Make sure you installed Packer:

    packer --version
    

    Result:

    Packer v1.11.2
    
  1. Create the packer folder.

  2. Download a Packer distribution kit from the mirror and extract it into the packer folder:

  3. Add packer to the PATH variable:

    1. Click Start and type Change system environment variables in the Windows search bar.
    2. Click Environment Variables... at the bottom right.
    3. In the window that opens, find the PATH parameter and click Edit.
    4. Add the packer folder path to the list.
    5. Click OK.
  4. Run a new command line session and make sure you installed Packer:

    packer --version
    

    Result:

    Packer v1.11.2
    
  1. Download a Packer distribution kit from the mirror and extract it into the packer directory:

    mkdir packer
    curl --location --output ~/packer/packer_1.11.2_darwin_amd64.zip https://hashicorp-releases.yandexcloud.net/packer/1.11.2/packer_1.11.2_darwin_amd64.zip
    unzip ~/packer/packer_1.11.2_darwin_amd64.zip -d ~/packer
    

    This example uses version 1.11.2. For the latest Packer version, see the mirror.

  2. Add Packer to the PATH variable:

    echo 'export PATH="$PATH:$HOME/<username>/packer"' >> ~/.bash_profile
    source ~/.bash_profile
    
  3. Restart the shell:

    exec -l $SHELL
    
  4. Make sure you installed Packer:

    packer --version
    

    Result:

    Packer v1.11.2
    

From the HashiCorp websiteFrom the HashiCorp website

Download and install a Packer distribution kit following this guide on the Packer website.

Configure the Yandex Compute Builder pluginConfigure the Yandex Compute Builder plugin

To configure the plugin:

  1. Create a file named config.pkr.hcl with the following contents:

    packer {
      required_plugins {
        yandex = {
          version = ">= 1.1.2"
          source  = "github.com/hashicorp/yandex"
        }
      }
    }
    
  2. Install the plugin:

    packer init <path_to_config.pkr.hcl>
    

    Result:

    Installed plugin github.com/hashicorp/yandex v1.1.2 in ...
    

Prepare the image configurationPrepare the image configuration

  1. Get the folder ID.

  2. Get the subnet ID and the availability zone it resides in.

  3. Prepare the subnet ID by running the yc vpc subnet list command.

  4. Create a JSON file with any name, e.g., image.json. Add this configuration to it:

    {
      "builders": [
        {
          "type":      "yandex",
          "token":     "<OAuth_token_or_IAM_token>",
          "folder_id": "<folder_ID>",
          "zone":      "<availability_zone>",
    
          "image_name":        "debian-11-nginx-{{isotime | clean_resource_name}}",
          "image_family":      "debian-web-server",
          "image_description": "my custom debian with nginx",
    
          "source_image_family": "debian-11",
          "subnet_id":           "<subnet_ID>",
          "use_ipv4_nat":        true,
          "disk_type":           "network-ssd",
          "ssh_username":        "debian"
        }
      ],
      "provisioners": [
        {
          "type": "shell",
          "inline": [
            "echo 'updating APT'",
            "sudo apt-get update -y",
            "sudo apt-get install -y nginx",
            "sudo su -",
            "sudo systemctl enable nginx.service",
            "curl localhost"
          ]
        }
      ]
    }
    

    Where:

    • <availability_zone>: Availability zone where you are going to create the VM, e.g., ru-central1-d.
    • token: OAuth token for a Yandex account or an IAM token for a federated account.
    • folder_id: ID of the folder where you are going to create the VM and its image.
    • subnet_id: ID of the subnet where you are going to create the VM and its image.

Warning

You cannot use both the provisioner "shell" and metadata parameters in the configuration file at the same time.

You can learn more about image configuration properties in this Yandex Compute Builder overview article.

Create an imageCreate an image

  1. Build the image using the configuration properties:

    packer build image.json
    
  2. Wait for the build to complete:

    ...
    ==> Wait completed after 2 minutes 43 seconds
    ==> Builds finished. The artifacts of successful builds are:
    --> yandex: A disk image was created: debian-11-nginx-2024-08-26t15-30-39z (id: fd82d63b9bgc********) with family name debian-web-server
    

Check the imageCheck the image

Make sure you created the image:

Management console
CLI
  1. Navigate to the management console.
  2. Select Compute Cloud.
  3. Open the Images section. Make sure the new disk image is there.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

Run this command:

yc compute image list

Result:

+----------------------+--------------------------------------+-------------------+----------------------+--------+
|          ID          |                 NAME                 |      FAMILY       |     PRODUCT IDS      | STATUS |
+----------------------+--------------------------------------+-------------------+----------------------+--------+
| fd82d63b9bgc******** | debian-11-nginx-2024-08-26t15-30-39z | debian-web-server | f2eerqfup7lg******** | READY  |
+----------------------+--------------------------------------+-------------------+----------------------+--------+

Delete the resources you createdDelete the resources you created

If you no longer need the image you created, delete it.

Delete the subnet and cloud network if you created them specifically to follow this tutorial.

Was the article helpful?

Previous
Uploading Terraform states to Object Storage
Next
Building a VM image with infrastructure tools using Packer
© 2025 Direct Cursus Technology L.L.C.