2019-06-12 08:49:28 -04:00
---
description: |
2020-03-23 20:02:12 -04:00
The yandex Packer builder is able to create images for use with
2020-03-18 18:46:47 -04:00
Yandex.Cloud based on existing images.
2019-06-12 08:49:28 -04:00
layout: docs
2020-03-18 18:46:47 -04:00
page_title: Yandex Compute - Builders
2020-04-02 19:39:47 -04:00
sidebar_title: Yandex.Cloud
2019-06-12 08:49:28 -04:00
---
# Yandex Compute Builder
Type: `yandex`
The `yandex` Packer builder is able to create
[images](https://cloud.yandex.com/docs/compute/concepts/images) for use with
[Yandex Compute Cloud](https://cloud.yandex.com/docs/compute/)
based on existing images.
## Authentication
2020-06-17 10:02:55 -04:00
Builder can authenticate with Yandex.Cloud using one of the following methods:
2019-06-12 08:49:28 -04:00
2020-03-18 18:46:47 -04:00
- OAuth token
2020-10-23 07:07:37 -04:00
- IAM token
2020-03-18 18:46:47 -04:00
- File with Service Account Key
2020-06-17 10:02:55 -04:00
- Service Account assigned to Compute Instance
2019-06-12 08:49:28 -04:00
### Authentication Using Token
2020-10-23 11:01:52 -04:00
To authenticate with an OAuth token or IAM token only `token` config key is needed.
2020-10-23 04:47:28 -04:00
Or use the `YC_TOKEN` environment variable with proper value.
Token you could get [here](https://oauth.yandex.ru/authorize?response_type=token&client_id=1a6990aa636648e9b2ef855fa7bec2fb).
2020-10-23 07:08:08 -04:00
Check [documentation](https://cloud.yandex.ru/docs/iam/operations/iam-token/create) about how to create IAM token.
2019-06-12 08:49:28 -04:00
### Authentication Using Service Account Key File
To authenticate with a service account credential, only `service_account_key_file` is needed.
Or use the `YC_SERVICE_ACCOUNT_KEY_FILE` environment variable.
2020-07-13 06:33:16 -04:00
The parameter expects a value path to the service account file in json format. Check [documentation](https://cloud.yandex.com/docs/cli/operations/authentication/service-account#auth-as-sa)
2020-06-17 10:02:55 -04:00
about how to create SA and its key.
### Authentication Using a Compute Instance Service Account
Authentication with a Service Account on an instance happens when neither the `token` nor the `service_account_key_file` parameter is set.
To get more information about this kind of authentication check [documentaion](https://cloud.yandex.com/docs/compute/operations/vm-connect/auth-inside-vm).
-> **NB** Do not forget to assigne proper roles to Service Account, if you use this type of auth.
2019-06-12 08:49:28 -04:00
## Basic Example
2020-03-12 10:05:08 -04:00
```json
2019-06-12 08:49:28 -04:00
{
"type": "yandex",
"token": "YOUR OAUTH TOKEN",
"folder_id": "YOUR FOLDER ID",
"source_image_family": "ubuntu-1804-lts",
"ssh_username": "ubuntu",
"use_ipv4_nat": "true"
}
```
## Configuration Reference
Configuration options are organized below into two categories: required and
optional. Within each category, the available options are alphabetized and
described.
2020-03-31 17:40:07 -04:00
In addition to the options listed here, a [communicator](/docs/templates/communicator)
2020-09-09 11:33:38 -04:00
can be configured for this builder. In addition to the options defined there, a private key file
can also be supplied to override the typical auto-generated key:
@include 'helper/communicator/SSH-Private-Key-File-not-required.mdx'
2019-06-12 08:49:28 -04:00
### Required:
2020-08-31 09:29:20 -04:00
@include 'builder/yandex/AccessConfig-required.mdx'
2020-03-23 20:02:12 -04:00
@include 'builder/yandex/Config-required.mdx'
2019-06-12 08:49:28 -04:00
### Optional:
2020-08-31 09:29:20 -04:00
@include 'builder/yandex/AccessConfig-not-required.mdx'
2020-07-09 10:43:11 -04:00
2020-08-31 09:29:20 -04:00
@include 'builder/yandex/Config-not-required.mdx'
2020-07-09 10:43:11 -04:00
## Build template data
In configuration directives the following variables are available:
- `ImageID` - ID of the built image.
- `ImageName` - Name of the built image.
- `ImageFamily` - Family of the built image.
- `ImageDescription` - Description of the built image.
- `ImageFolderID` - Folder ID where the built image is stored.
- `SourceImageID` - The source image ID (for example `fd8fjtn3mj2kfe7h6f0r`) used to build the image.
- `SourceImageName` - The source image name (for example `ubuntu-1604-lts-1579200746`) used to build the image.
- `SourceImageDescription` - The source image description (for example `ubuntu 16.04 lts`).
- `SourceImageFamily` - The source image family (for example `ubuntu-1604-lts`).
- `SourceImageFolderID` - The folder ID where source image located (for example `standard-images`).
## Build Shared Information Variables
This builder generates data that are shared with provisioner and post-processor via build function of
[template engine](/docs/templates/engine) for JSON and [contextual variables](/docs/from-1.5/contextual-variables)
for HCL2.
The generated variables available for this builder see above
Usage example:
<Tabs>
<Tab heading="JSON">
```json
"post-processors": [
{
"type": "manifest",
"output": "manifest.json",
"strip_path": true,
"custom_data": {
"source_image_id": "{{ build `SourceImageID` }}"
}
}
]
```
</Tab>
<Tab heading="HCL2">
```hcl
post-processor "manifest" {
output = "manifest.json"
strip_path = true
custom_data = {
source_image_id = "${build.SourceImageID}"
}
}
```
</Tab>
</Tabs>