2016-12-30 16:21:23 -05:00
---
2020-03-18 18:46:47 -04:00
description: >
The amazon-ebssurrogate Packer builder is like the chroot builder, but does
not
require running inside an EC2 instance.
2016-12-30 16:21:23 -05:00
layout: docs
2020-03-18 18:46:47 -04:00
page_title: Amazon EBS Surrogate - Builders
2020-04-02 19:39:47 -04:00
sidebar_title: EBS Surrogate
2017-03-25 18:13:52 -04:00
---
2016-12-30 16:21:23 -05:00
# EBS Surrogate Builder
Type: `amazon-ebssurrogate`
2017-03-25 18:13:52 -04:00
The `amazon-ebssurrogate` Packer builder is able to create Amazon AMIs by
running a source instance with an attached volume, provisioning the attached
volume in such a way that it can be used as the root volume for the AMI, and
then snapshotting and creating the AMI from that volume.
2016-12-30 16:21:23 -05:00
2017-03-25 18:13:52 -04:00
This builder can therefore be used to bootstrap scratch-build images - for
example FreeBSD or Ubuntu using ZFS as the root file system.
2016-12-30 16:21:23 -05:00
2018-10-26 20:02:51 -04:00
This is all done in your own AWS account. This builder will create temporary
key pairs, security group rules, etc., that provide it temporary access to the
2016-12-30 16:21:23 -05:00
instance while the image is being created.
## Configuration Reference
2019-06-18 12:00:49 -04:00
There are many configuration options available for the builder. In addition to
the items listed here, you will want to look at the general configuration
references for [AMI](#ami-configuration),
[BlockDevices](#block-devices-configuration),
2019-11-06 04:15:19 -05:00
[Access](#access-configuration),
2019-06-18 12:00:49 -04:00
[Run](#run-configuration) and
[Communicator](#communicator-configuration)
configuration references, which are
necessary for this build to succeed and can be found further down the page.
2016-12-30 16:21:23 -05:00
### Required:
2020-03-23 20:02:12 -04:00
@include 'builder/amazon/ebssurrogate/Config-required.mdx'
2017-03-15 15:09:07 -04:00
2016-12-30 16:21:23 -05:00
### Optional:
2020-03-23 20:02:12 -04:00
@include 'builder/amazon/ebssurrogate/Config-not-required.mdx'
2019-06-18 12:00:49 -04:00
### AMI Configuration
2019-08-26 10:56:57 -04:00
#### Required:
2020-03-23 20:02:12 -04:00
@include 'builder/amazon/common/AMIConfig-required.mdx'
2019-08-26 10:56:57 -04:00
2019-06-18 12:00:49 -04:00
#### Optional:
2020-03-18 18:46:47 -04:00
2020-03-23 20:02:12 -04:00
@include 'builder/amazon/common/AMIConfig-not-required.mdx'
2019-06-18 12:00:49 -04:00
2019-11-06 04:15:19 -05:00
### Access Configuration
2019-06-18 12:00:49 -04:00
#### Required:
2020-03-23 20:02:12 -04:00
@include 'builder/amazon/common/AccessConfig-required.mdx'
2019-06-18 12:00:49 -04:00
#### Optional:
2020-03-23 20:02:12 -04:00
@include 'builder/amazon/common/AccessConfig-not-required.mdx'
2019-06-18 12:00:49 -04:00
2020-09-22 19:58:56 -04:00
### Assume Role Configuration
@include 'builder/amazon/common/AssumeRoleConfig.mdx'
@include 'builder/amazon/common/AssumeRoleConfig-not-required.mdx'
2020-08-17 11:09:19 -04:00
### Polling Configuration
@include 'builder/amazon/common/AWSPollingConfig.mdx'
@include 'builder/amazon/common/AWSPollingConfig-not-required.mdx'
2019-06-18 12:00:49 -04:00
### Run Configuration
#### Required:
2020-03-23 20:02:12 -04:00
@include 'builder/amazon/common/RunConfig-required.mdx'
2019-06-18 12:00:49 -04:00
#### Optional:
2020-03-23 20:02:12 -04:00
@include 'builder/amazon/common/RunConfig-not-required.mdx'
2019-06-18 12:00:49 -04:00
2020-05-15 08:58:10 -04:00
@include 'builders/aws-session-manager.mdx'
2019-06-18 12:00:49 -04:00
### Block Devices Configuration
Block devices can be nested in the
[ami_block_device_mappings](#ami_block_device_mappings) array.
2020-03-23 20:02:12 -04:00
@include 'builder/amazon/common/BlockDevice.mdx'
2019-06-18 12:00:49 -04:00
2020-01-06 15:01:30 -05:00
#### Optional only for [launch_block_device_mappings](#launch_block_device_mappings)
2019-06-18 12:00:49 -04:00
2020-03-23 20:02:12 -04:00
@include 'builder/amazon/ebssurrogate/BlockDevice-not-required.mdx'
2019-06-18 12:00:49 -04:00
#### Optional:
2020-03-23 20:02:12 -04:00
@include 'builder/amazon/common/BlockDevice-not-required.mdx'
2019-06-18 12:00:49 -04:00
### Communicator Configuration
#### Optional:
2020-03-23 20:02:12 -04:00
@include 'helper/communicator/Config-not-required.mdx'
2020-03-24 19:48:37 -04:00
2020-03-23 20:02:12 -04:00
@include 'helper/communicator/SSH-not-required.mdx'
2016-12-30 16:21:23 -05:00
2020-07-02 08:50:45 -04:00
@include 'helper/communicator/SSH-Temporary-Key-Pair-not-required.mdx'
@include 'helper/communicator/SSH-Key-Pair-Name-not-required.mdx'
@include 'helper/communicator/SSH-Private-Key-File-not-required.mdx'
@include 'helper/communicator/SSH-Agent-Auth-not-required.mdx'
2020-07-01 08:32:26 -04:00
2016-12-30 16:21:23 -05:00
## Basic Example
2020-06-16 10:45:53 -04:00
<Tabs>
<Tab heading="JSON">
2020-03-12 10:05:08 -04:00
```json
2016-12-30 16:21:23 -05:00
{
2020-03-18 18:46:47 -04:00
"type": "amazon-ebssurrogate",
"secret_key": "YOUR SECRET KEY HERE",
"access_key": "YOUR KEY HERE",
"region": "us-east-1",
"ssh_username": "ubuntu",
"instance_type": "t2.medium",
"source_ami": "ami-40d28157",
"launch_block_device_mappings": [
{
"volume_type": "gp2",
"device_name": "/dev/xvdf",
"delete_on_termination": false,
"volume_size": 10
}
],
"ami_root_device": {
"source_device_name": "/dev/xvdf",
"device_name": "/dev/xvda",
"delete_on_termination": true,
"volume_size": 16,
"volume_type": "gp2"
}
2016-12-30 16:21:23 -05:00
}
```
2020-06-16 10:45:53 -04:00
</Tab>
<Tab heading="HCL2">
```hcl
source "amazon-ebssurrogate" "basic-example" {
region = "us-east-1"
ssh_username = "ubuntu"
instance_type = "t2.medium"
source_ami = "ami-40d28157"
ami_name = "packer-test-adrien"
ami_virtualization_type = "paravirtual"
launch_block_device_mappings {
volume_type = "gp2"
device_name = "/dev/xvdf"
delete_on_termination = false
volume_size = 10
}
ami_root_device {
source_device_name = "/dev/xvdf"
device_name = "/dev/xvda"
delete_on_termination = true
volume_size = 16
volume_type = "gp2"
}
}
build {
sources = ["sources.amazon-ebssurrogate.basic-example"]
provisioner "shell" {
inline = ["..."]
}
}
```
</Tab>
</Tabs>
2020-03-23 20:02:12 -04:00
-> **Note:** Packer can also read the access key and secret access key from
2016-12-30 16:21:23 -05:00
environmental variables. See the configuration reference in the section above
for more information on what environmental variables Packer will look for.
Further information on locating AMI IDs and their relationship to instance
2018-10-26 20:02:51 -04:00
types and regions can be found in the AWS EC2 Documentation [for
Linux](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html)
or [for
Windows](http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/finding-an-ami.html).
2016-12-30 16:21:23 -05:00
## Accessing the Instance to Debug
2018-10-18 19:09:49 -04:00
If you need to access the instance to debug for some reason, run this builder
2016-12-30 16:21:23 -05:00
with the `-debug` flag. In debug mode, the Amazon builder will save the private
key in the current directory and will output the DNS or IP information as well.
You can use this information to access the instance as it is running.
2018-04-02 13:32:14 -04:00
## Build template data
2018-10-26 20:02:51 -04:00
In configuration directives marked as a template engine above, the following
variables are available:
2018-04-02 13:32:14 -04:00
2020-03-18 18:46:47 -04:00
- `BuildRegion` - The region (for example `eu-central-1`) where Packer is
building the AMI.
- `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build
the AMI.
2020-05-22 07:17:38 -04:00
- `SourceAMICreationDate` - The source AMI creation date (for example `"2020-05-14T19:26:34.000Z"`).
2020-03-18 18:46:47 -04:00
- `SourceAMIName` - The source AMI Name (for example
`ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to
build the AMI.
- `SourceAMIOwner` - The source AMI owner ID.
- `SourceAMIOwnerName` - The source AMI owner alias/name (for example `amazon`).
- `SourceAMITags` - The source AMI Tags, as a `map[string]string` object.
2018-04-02 13:32:14 -04:00
2020-06-29 07:44:57 -04:00
## Build Shared Information Variables
2020-01-16 06:04:03 -05:00
2020-06-29 07:44:57 -04:00
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 are:
2020-01-16 06:04:03 -05:00
2020-08-12 04:43:15 -04:00
- `BuildRegion` - The region (for example `eu-central-1`) where Packer is
building the AMI.
- `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build
the AMI.
- `SourceAMICreationDate` - The source AMI creation date (for example `"2020-05-14T19:26:34.000Z"`).
2020-03-18 18:46:47 -04:00
- `SourceAMIName` - The source AMI Name (for example
`ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to
build the AMI.
2020-08-12 04:43:15 -04:00
- `SourceAMIOwner` - The source AMI owner ID.
- `SourceAMIOwnerName` - The source AMI owner alias/name (for example `amazon`).
2020-01-16 06:04:03 -05:00
2020-06-29 07:44:57 -04:00
Usage example:
<Tabs>
<Tab heading="JSON">
```json
"post-processors": [
{
"type": "manifest",
"output": "manifest.json",
"strip_path": true,
"custom_data": {
"source_ami_name": "{{ build `SourceAMIName` }}"
}
}
]
```
</Tab>
<Tab heading="HCL2">
```hcl
2020-10-22 03:42:45 -04:00
// When accessing one of these variables from inside the builder, you need to
// use the golang templating syntax. This is due to an architectural quirk that
// won't be easily resolvable until legacy json templates are deprecated:
{
source "amazon-ebs" "basic-example" {
tags = {
OS_Version = "Ubuntu"
Release = "Latest"
Base_AMI_ID = "{{ .SourceAMI }}"
Base_AMI_Name = "{{ .SourceAMIName }}"
}
}
// when accessing one of the variables from a provisioner or post-processor, use
// hcl-syntax
2020-06-29 07:44:57 -04:00
post-processor "manifest" {
output = "manifest.json"
strip_path = true
custom_data = {
source_ami_name = "${build.SourceAMIName}"
}
}
```
</Tab>
</Tabs>
2020-03-23 20:02:12 -04:00
-> **Note:** Packer uses pre-built AMIs as the source for building images.
2016-12-30 16:21:23 -05:00
These source AMIs may include volumes that are not flagged to be destroyed on
2018-10-26 20:02:51 -04:00
termination of the instance building the new image. In addition to those
2020-03-13 14:20:08 -04:00
volumes created by this builder, any volumes in the source AMI which are not
2018-10-26 20:02:51 -04:00
marked for deletion on termination will remain in your account.
2019-04-19 19:35:15 -04:00
2020-03-23 20:02:12 -04:00
@include 'builders/aws-ssh-differentiation-table.mdx'