Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI Studio
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex Compute Cloud
  • Yandex Container Solution
    • All tutorials
    • Configuring time synchronization using NTP
    • Autoscaling an instance group to process messages from a queue
    • Updating an instance group under load
    • Deploying Remote Desktop Gateway
    • Getting started with Packer
    • Transferring logs from a VM to Yandex Cloud Logging
    • Building a VM image with infrastructure tools using Packer
    • Migrating data to Yandex Cloud using Hystax Acura
    • Fault protection with Hystax Acura
    • VM backups using Hystax Acura
    • Deploying a fault-tolerant architecture with preemptible VMs
    • Configuring a fault-tolerant architecture in Yandex Cloud
    • Creating a budget trigger that invokes a function to stop a VM
    • Creating triggers that invoke a function to stop a VM and send a Telegram notification
    • Creating a Python web application with Flask
    • Creating an SAP program in Yandex Cloud
    • Deploying a Minecraft server in Yandex Cloud
    • Automating image builds using Jenkins and Packer
    • Creating test VMs via GitLab CI
    • High-performance computing on preemptible VMs
    • Configuring an SFTP server based on CentOS 7
    • Deploying GlusterFS in high availability mode
    • Deploying GlusterFS in high performance mode
    • Backing up to Object Storage with Bacula
    • Building a CI/CD pipeline in GitLab using serverless products
    • Implementing a secure high-availability network infrastructure with a dedicated DMZ based on the Check Point NGFW
    • Cloud infrastructure segmentation with the Check Point next-generation firewall
    • Configuring a secure GRE tunnel over IPsec
    • Creating a bastion host
    • Implementing fault-tolerant scenarios for NAT VMs
    • Creating a tunnel between two subnets using OpenVPN Access Server
    • Creating an external table from a Object Storage bucket table using a configuration file
    • Setting up network connectivity between BareMetal and Virtual Private Cloud subnets
    • Working with snapshots in Managed Service for Kubernetes
    • Running the DeepSeek-R1 language model in a GPU cluster
    • Running a vLLM library with the Gemma 3 language model on a VM with GPU
    • Delivering USB devices to a virtual machine or BareMetal server
    • Yandex Object Storage integration with Nextcloud
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes

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. Tutorials
  2. Getting started with Packer

Getting started with Packer

Written by
Yandex Cloud
Updated at July 14, 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 linked billing account with an 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. Create a cloud network with a single subnet in your folder.

  2. Depending on the type of account you are working under, you will get:

    • OAuth token for a Yandex account.
    • IAM token for federated or service accounts.
  3. Make sure your account has enough permissions to create resources in Compute Cloud. The minimum role you need for the folder is compute.editor.

    If working under a service account, assign the compute.editor role for the folder to it.

    If you want to create resources in other Yandex Cloud services, e.g., subnets in VPC, assign the relevant service roles.

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 your 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. 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": "<catalog_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:

    • token: OAuth token for a Yandex account or an IAM token for a federated or service account.
    • folder_id: ID of the folder where you are going to create the VM and its image.
    • zone: Availability zone the VM will be created in, e.g., ru-central1-d.
    • 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 installed yet, install and initialize it.

By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command 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

To stop paying for the resources you created:

  • Delete the image you created.
  • Delete the subnet and cloud network if created specifically for the purpose of this tutorial.

Was the article helpful?

Previous
Deploying Remote Desktop Gateway
Next
Transferring logs from a VM to Yandex Cloud Logging
© 2025 Direct Cursus Technology L.L.C.