github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/website/source/docs/builders/amazon-ebssurrogate.html.md (about)

     1  ---
     2  description: |
     3      The amazon-ebssurrogate Packer builder is like the chroot builder, but does
     4      not require running inside an EC2 instance.
     5  layout: docs
     6  page_title: 'Amazon EBS Surrogate - Builders'
     7  sidebar_current: 'docs-builders-amazon-ebssurrogate'
     8  ---
     9  
    10  # EBS Surrogate Builder
    11  
    12  Type: `amazon-ebssurrogate`
    13  
    14  The `amazon-ebssurrogate` Packer builder is able to create Amazon AMIs by
    15  running a source instance with an attached volume, provisioning the attached
    16  volume in such a way that it can be used as the root volume for the AMI, and
    17  then snapshotting and creating the AMI from that volume.
    18  
    19  This builder can therefore be used to bootstrap scratch-build images - for
    20  example FreeBSD or Ubuntu using ZFS as the root file system.
    21  
    22  This is all done in your own AWS account. The builder will create temporary key
    23  pairs, security group rules, etc. that provide it temporary access to the
    24  instance while the image is being created.
    25  
    26  ## Configuration Reference
    27  
    28  There are many configuration options available for the builder. They are
    29  segmented below into two categories: required and optional parameters. Within
    30  each category, the available configuration keys are alphabetized.
    31  
    32  In addition to the options listed here, a
    33  [communicator](/docs/templates/communicator.html) can be configured for this
    34  builder.
    35  
    36  ### Required:
    37  
    38  -   `access_key` (string) - The access key used to communicate with AWS. [Learn
    39      how to set this.](/docs/builders/amazon.html#specifying-amazon-credentials)
    40  
    41  -   `instance_type` (string) - The EC2 instance type to use while building the
    42      AMI, such as `m1.small`.
    43  
    44  -   `region` (string) - The name of the region, such as `us-east-1`, in which to
    45      launch the EC2 instance to create the AMI.
    46  
    47  -   `secret_key` (string) - The secret key used to communicate with AWS. [Learn
    48      how to set this.](/docs/builders/amazon.html#specifying-amazon-credentials)
    49  
    50  -   `source_ami` (string) - The initial AMI used as a base for the newly
    51      created machine. `source_ami_filter` may be used instead to populate this
    52      automatically.
    53  
    54  -   `ami_root_device` (block device mapping) - A block device mapping describing
    55      the root device of the AMI. This looks like the mappings in `ami_block_device_mapping`,
    56      except with an additional field:
    57  
    58      -   `source_device_name` (string) - The device name of the block device on the
    59          source instance to be used as the root device for the AMI. This must correspond
    60          to a block device in `launch_block_device_mapping`.
    61  
    62  ### Optional:
    63  
    64  -   `ami_block_device_mappings` (array of block device mappings) - Add one or
    65      more [block device mappings](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html)
    66      to the AMI. These will be attached when booting a new instance from your
    67      AMI. To add a block device during the packer build see
    68      `launch_block_device_mappings` below. Your options here may vary depending
    69      on the type of VM you use. The block device mappings allow for the following
    70      configuration:
    71  
    72      -   `delete_on_termination` (boolean) - Indicates whether the EBS volume is
    73          deleted on instance termination. Default `false`. **NOTE**: If this
    74          value is not explicitly set to `true` and volumes are not cleaned up by
    75          an alternative method, additional volumes will accumulate after
    76          every build.
    77  
    78      -   `device_name` (string) - The device name exposed to the instance (for
    79          example, `/dev/sdh` or `xvdh`). Required when specifying `volume_size`.
    80  
    81      -   `encrypted` (boolean) - Indicates whether to encrypt the volume or not
    82  
    83      -   `iops` (number) - The number of I/O operations per second (IOPS) that the
    84          volume supports. See the documentation on
    85          [IOPs](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html)
    86          for more information
    87  
    88      -   `no_device` (boolean) - Suppresses the specified device included in the
    89          block device mapping of the AMI
    90  
    91      -   `snapshot_id` (string) - The ID of the snapshot
    92  
    93      -   `virtual_name` (string) - The virtual device name. See the documentation on
    94          [Block Device
    95          Mapping](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_BlockDeviceMapping.html)
    96          for more information
    97  
    98      -   `volume_size` (number) - The size of the volume, in GiB. Required if not
    99          specifying a `snapshot_id`
   100  
   101      -   `volume_type` (string) - The volume type. `gp2` for General Purpose (SSD)
   102          volumes, `io1` for Provisioned IOPS (SSD) volumes, and `standard` for Magnetic
   103          volumes
   104  
   105  -   `ami_description` (string) - The description to set for the
   106      resulting AMI(s). By default this description is empty. This is a
   107      [template engine](/docs/templates/engine.html),
   108      see [Build template data](#build-template-data) for more information.
   109  
   110  -   `ami_groups` (array of strings) - A list of groups that have access to
   111      launch the resulting AMI(s). By default no groups have permission to launch
   112      the AMI. `all` will make the AMI publicly accessible. AWS currently doesn't
   113      accept any value other than `all`.
   114  
   115  -   `ami_product_codes` (array of strings) - A list of product codes to
   116      associate with the AMI. By default no product codes are associated with
   117      the AMI.
   118  
   119  -   `ami_regions` (array of strings) - A list of regions to copy the AMI to.
   120      Tags and attributes are copied along with the AMI. AMI copying takes time
   121      depending on the size of the AMI, but will generally take many minutes.
   122  
   123  -   `ami_users` (array of strings) - A list of account IDs that have access to
   124      launch the resulting AMI(s). By default no additional users other than the
   125      user creating the AMI has permissions to launch it.
   126  
   127  -   `ami_virtualization_type` (string) - The type of virtualization for the AMI
   128      you are building. This option must match the supported virtualization
   129      type of `source_ami`. Can be `paravirtual` or `hvm`.
   130  
   131  -   `associate_public_ip_address` (boolean) - If using a non-default VPC, public
   132      IP addresses are not provided by default. If this is toggled, your new
   133      instance will get a Public IP.
   134  
   135  -   `availability_zone` (string) - Destination availability zone to launch
   136      instance in. Leave this empty to allow Amazon to auto-assign.
   137  
   138  -   `custom_endpoint_ec2` (string) - This option is useful if you use a cloud
   139      provider whose API is compatible with aws EC2. Specify another endpoint
   140      like this `https://ec2.custom.endpoint.com`.
   141  
   142  -   `disable_stop_instance` (boolean) - Packer normally stops the build instance
   143      after all provisioners have run. For Windows instances, it is sometimes
   144      desirable to [run Sysprep](http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ami-create-standard.html)
   145      which will stop the instance for you. If this is set to true, Packer *will not*
   146      stop the instance but will assume that you will send the stop signal
   147      yourself through your final provisioner. You can do this with a
   148      [windows-shell provisioner](https://www.packer.io/docs/provisioners/windows-shell.html).
   149  
   150      Note that Packer will still wait for the instance to be stopped, and failing
   151      to send the stop signal yourself, when you have set this flag to `true`,
   152      will cause a timeout.
   153  
   154      Example of a valid shutdown command:
   155  
   156      ``` json
   157      {
   158        "type": "windows-shell",
   159        "inline": ["\"c:\\Program Files\\Amazon\\Ec2ConfigService\\ec2config.exe\" -sysprep"]
   160      }
   161      ```
   162  
   163  -   `ebs_optimized` (boolean) - Mark instance as [EBS
   164      Optimized](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSOptimized.html).
   165      Default `false`.
   166  
   167  -   `ena_support` (boolean) - Enable enhanced networking (ENA but not SriovNetSupport)
   168      on HVM-compatible AMIs. If true, add `ec2:ModifyInstanceAttribute` to your AWS IAM policy.
   169      Note: you must make sure enhanced networking is enabled on your instance. See [Amazon's
   170      documentation on enabling enhanced networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking). Default `false`.
   171  
   172  -   `enable_t2_unlimited` (boolean) - Enabling T2 Unlimited allows the source
   173      instance to burst additional CPU beyond its available [CPU Credits]
   174      (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/t2-credits-baseline-concepts.html)
   175      for as long as the demand exists.
   176      This is in contrast to the standard configuration that only allows an
   177      instance to consume up to its available CPU Credits.
   178      See the AWS documentation for [T2 Unlimited]
   179      (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/t2-unlimited.html)
   180      and the 'T2 Unlimited Pricing' section of the [Amazon EC2 On-Demand
   181      Pricing](https://aws.amazon.com/ec2/pricing/on-demand/) document for more
   182      information.
   183      By default this option is disabled and Packer will set up a [T2
   184      Standard](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/t2-std.html)
   185      instance instead.
   186  
   187      To use T2 Unlimited you must use a T2 instance type e.g. t2.micro.
   188      Additionally, T2 Unlimited cannot be used in conjunction with Spot
   189      Instances e.g. when the `spot_price` option has been configured.
   190      Attempting to do so will cause an error.
   191  
   192      !> **Warning!** Additional costs may be incurred by enabling T2
   193      Unlimited - even for instances that would usually qualify for the
   194      [AWS Free Tier](https://aws.amazon.com/free/).
   195  
   196  -   `force_deregister` (boolean) - Force Packer to first deregister an existing
   197      AMI if one with the same name already exists. Default `false`.
   198  
   199  -   `force_delete_snapshot` (boolean) - Force Packer to delete snapshots associated with
   200      AMIs, which have been deregistered by `force_deregister`. Default `false`.
   201  
   202  -   `encrypt_boot` (boolean) - Instruct packer to automatically create a copy of the
   203      AMI with an encrypted boot volume (discarding the initial unencrypted AMI in the
   204      process). Packer will always run this operation, even if the base
   205      AMI has an encrypted boot volume to start with. Default `false`.
   206  
   207  -   `kms_key_id` (string) - The ID of the KMS key to use for boot volume encryption.
   208      This only applies to the main `region`, other regions where the AMI will be copied
   209      will be encrypted by the default EBS KMS key.
   210  
   211  -   `iam_instance_profile` (string) - The name of an [IAM instance
   212      profile](https://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html)
   213      to launch the EC2 instance with.
   214  
   215  -   `launch_block_device_mappings` (array of block device mappings) - Add one
   216      or more block devices before the Packer build starts. If you add instance
   217      store volumes or EBS volumes in addition to the root device volume, the
   218      created AMI will contain block device mapping information for those
   219      volumes. Amazon creates snapshots of the source instance's root volume and
   220      any other EBS volumes described here. When you launch an instance from this
   221      new AMI, the instance automatically launches with these additional volumes,
   222      and will restore them from snapshots taken from the source instance.
   223  
   224  -   `mfa_code` (string) - The MFA [TOTP](https://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm)
   225      code. This should probably be a user variable since it changes all the time.
   226  
   227  -   `profile` (string) - The profile to use in the shared credentials file for
   228      AWS. See Amazon's documentation on [specifying
   229      profiles](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-profiles)
   230      for more details.
   231  
   232  -   `region_kms_key_ids` (map of strings) - a map of regions to copy the ami to,
   233      along with the custom kms key id to use for encryption for that region.
   234      Keys must match the regions provided in `ami_regions`. If you just want to
   235      encrypt using a default ID, you can stick with `kms_key_id` and `ami_regions`.
   236      If you want a region to be encrypted with that region's default key ID, you can
   237      use an empty string `""` instead of a key id in this map. (e.g. `"us-east-1": ""`)
   238      However, you cannot use default key IDs if you are using this in conjunction with
   239      `snapshot_users` -- in that situation you must use custom keys.
   240  
   241  -   `run_tags` (object of key/value strings) - Tags to apply to the instance
   242      that is *launched* to create the AMI. These tags are *not* applied to the
   243      resulting AMI unless they're duplicated in `tags`. This is a
   244      [template engine](/docs/templates/engine.html),
   245      see [Build template data](#build-template-data) for more information.
   246  
   247  -   `run_volume_tags` (object of key/value strings) - Tags to apply to the volumes
   248      that are *launched* to create the AMI. These tags are *not* applied to the
   249      resulting AMI unless they're duplicated in `tags`. This is a
   250      [template engine](/docs/templates/engine.html),
   251      see [Build template data](#build-template-data) for more information.
   252  
   253  -   `security_group_id` (string) - The ID (*not* the name) of the security group
   254      to assign to the instance. By default this is not set and Packer will
   255      automatically create a new temporary security group to allow SSH access.
   256      Note that if this is specified, you must be sure the security group allows
   257      access to the `ssh_port` given below.
   258  
   259  -   `security_group_ids` (array of strings) - A list of security groups as
   260      described above. Note that if this is specified, you must omit the
   261      `security_group_id`.
   262  
   263  -   `temporary_security_group_source_cidr` (string) - An IPv4 CIDR block to be authorized
   264      access to the instance, when packer is creating a temporary security group.
   265      The default is `0.0.0.0/0` (ie, allow any IPv4 source). This is only used
   266      when `security_group_id` or `security_group_ids` is not specified.
   267  
   268  -   `shutdown_behavior` (string) - Automatically terminate instances on shutdown
   269      incase packer exits ungracefully. Possible values are "stop" and "terminate",
   270      default is `stop`.
   271  
   272  -   `skip_region_validation` (boolean) - Set to true if you want to skip
   273      validation of the region configuration option. Default `false`.
   274  
   275  -   `snapshot_groups` (array of strings) - A list of groups that have access to
   276      create volumes from the snapshot(s). By default no groups have permission to create
   277      volumes from the snapshot(s). `all` will make the snapshot publicly accessible.
   278  
   279  -   `snapshot_users` (array of strings) - A list of account IDs that have access to
   280      create volumes from the snapshot(s). By default no additional users other than the
   281      user creating the AMI has permissions to create volumes from the backing snapshot(s).
   282  
   283  -   `snapshot_tags` (object of key/value strings) - Tags to apply to snapshot.
   284      They will override AMI tags if already applied to snapshot. This is a
   285      [template engine](/docs/templates/engine.html),
   286      see [Build template data](#build-template-data) for more information.
   287  
   288  -   `source_ami_filter` (object) - Filters used to populate the `source_ami` field.
   289      Example:
   290  
   291      ``` json
   292      {
   293        "source_ami_filter": {
   294          "filters": {
   295            "virtualization-type": "hvm",
   296            "name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
   297            "root-device-type": "ebs"
   298          },
   299          "owners": ["099720109477"],
   300          "most_recent": true
   301        }
   302      }
   303      ```
   304  
   305      This selects the most recent Ubuntu 16.04 HVM EBS AMI from Canonical.
   306      NOTE: This will fail unless *exactly* one AMI is returned. In the above
   307      example, `most_recent` will cause this to succeed by selecting the newest image.
   308  
   309      -   `filters` (map of strings) - filters used to select a `source_ami`.
   310          NOTE: This will fail unless *exactly* one AMI is returned.
   311          Any filter described in the docs for [DescribeImages](http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html)
   312          is valid.
   313  
   314      -   `owners` (array of strings) - This scopes the AMIs to certain Amazon account IDs.
   315          This is helpful to limit the AMIs to a trusted third party, or to your own account.
   316  
   317      -   `most_recent` (boolean) - Selects the newest created image when true.
   318          This is most useful for selecting a daily distro build.
   319  
   320      You may set this in place of `source_ami` or in conjunction with it. If you
   321      set this in conjunction with `source_ami`, the `source_ami` will be added to
   322      the filter. The provided `source_ami` must meet all of the filtering criteria
   323      provided in `source_ami_filter`; this pins the AMI returned by the filter,
   324      but will cause Packer to fail if the `source_ami` does not exist.
   325  
   326  -   `spot_price` (string) - The maximum hourly price to pay for a spot instance
   327      to create the AMI. Spot instances are a type of instance that EC2 starts
   328      when the current spot price is less than the maximum price you specify. Spot
   329      price will be updated based on available spot instance capacity and current
   330      spot instance requests. It may save you some costs. You can set this to
   331      `auto` for Packer to automatically discover the best spot price or to "0"
   332      to use an on demand instance (default).
   333  
   334  -   `spot_price_auto_product` (string) - Required if `spot_price` is set
   335      to `auto`. This tells Packer what sort of AMI you're launching to find the
   336      best spot price. This must be one of: `Linux/UNIX`, `SUSE Linux`, `Windows`,
   337      `Linux/UNIX (Amazon VPC)`, `SUSE Linux (Amazon VPC)`, `Windows (Amazon VPC)`
   338  
   339  -   `spot_tags` (object of key/value strings) - Requires `spot_price` to
   340      be set. This tells Packer to apply tags to the spot request that is
   341      issued.
   342  
   343  -   `sriov_support` (boolean) - Enable enhanced networking (SriovNetSupport but not ENA)
   344      on HVM-compatible AMIs. If true, add `ec2:ModifyInstanceAttribute` to your AWS IAM
   345      policy. Note: you must make sure enhanced networking is enabled on your instance. See [Amazon's
   346      documentation on enabling enhanced networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking).
   347      Default `false`.
   348  
   349  -   `ssh_keypair_name` (string) - If specified, this is the key that will be
   350      used for SSH with the machine. The key must match a key pair name loaded
   351      up into Amazon EC2. By default, this is blank, and Packer will
   352      generate a temporary keypair unless
   353      [`ssh_password`](/docs/templates/communicator.html#ssh_password) is used.
   354      [`ssh_private_key_file`](/docs/templates/communicator.html#ssh_private_key_file)
   355      or `ssh_agent_auth` must be specified when `ssh_keypair_name` is utilized.
   356  
   357  -   `ssh_agent_auth` (boolean) - If true, the local SSH agent will be used to
   358      authenticate connections to the source instance. No temporary keypair will
   359      be created, and the values of `ssh_password` and `ssh_private_key_file` will
   360      be ignored. To use this option with a key pair already configured in the source
   361      AMI, leave the `ssh_keypair_name` blank. To associate an existing key pair
   362      in AWS with the source instance, set the `ssh_keypair_name` field to the name
   363      of the key pair.
   364  
   365  -   `ssh_private_ip` (boolean) - No longer supported. See
   366      [`ssh_interface`](#ssh_interface). A fixer exists to migrate.
   367  
   368  -   `ssh_interface` (string) - One of `public_ip`, `private_ip`,
   369      `public_dns` or `private_dns`. If set, either the public IP address,
   370      private IP address, public DNS name or private DNS name will used as the host for SSH.
   371      The default behaviour if inside a VPC is to use the public IP address if available,
   372      otherwise the private IP address will be used. If not in a VPC the public DNS name
   373      will be used. Also works for WinRM.
   374  
   375      Where Packer is configured for an outbound proxy but WinRM traffic should be direct,
   376      `ssh_interface` must be set to `private_dns` and `<region>.compute.internal` included
   377      in the `NO_PROXY` environment variable.
   378  
   379  -   `subnet_id` (string) - If using VPC, the ID of the subnet, such as
   380      `subnet-12345def`, where Packer will launch the EC2 instance. This field is
   381      required if you are using an non-default VPC.
   382  
   383  -   `tags` (object of key/value strings) - Tags applied to the AMI and
   384      relevant snapshots. This is a
   385      [template engine](/docs/templates/engine.html),
   386      see [Build template data](#build-template-data) for more information.
   387  
   388  -   `temporary_key_pair_name` (string) - The name of the temporary keypair
   389      to generate. By default, Packer generates a name with a UUID.
   390  
   391  -   `token` (string) - The access token to use. This is different from the
   392      access key and secret key. If you're not sure what this is, then you
   393      probably don't need it. This will also be read from the `AWS_SESSION_TOKEN`
   394      environmental variable.
   395  
   396  -   `user_data` (string) - User data to apply when launching the instance. Note
   397      that you need to be careful about escaping characters due to the templates
   398      being JSON. It is often more convenient to use `user_data_file`, instead.
   399  
   400  -   `user_data_file` (string) - Path to a file that will be used for the user
   401      data when launching the instance.
   402  
   403  -   `vpc_id` (string) - If launching into a VPC subnet, Packer needs the VPC ID
   404      in order to create a temporary security group within the VPC. Requires `subnet_id`
   405      to be set. If this field is left blank, Packer will try to get the VPC ID from the
   406      `subnet_id`.
   407  
   408  -   `windows_password_timeout` (string) - The timeout for waiting for a Windows
   409      password for Windows instances. Defaults to 20 minutes. Example value: `10m`
   410  
   411  ## Basic Example
   412  
   413  ``` json
   414  {
   415     "type" : "amazon-ebssurrogate",
   416     "secret_key" : "YOUR SECRET KEY HERE",
   417     "access_key" : "YOUR KEY HERE",
   418     "region" : "us-east-1",
   419     "ssh_username" : "ubuntu",
   420     "instance_type" : "t2.medium",
   421     "source_ami" : "ami-40d28157",
   422     "launch_block_device_mappings" : [
   423       {
   424         "volume_type" : "gp2",
   425         "device_name" : "/dev/xvdf",
   426         "delete_on_termination" : false,
   427         "volume_size" : 10
   428       }
   429     ],
   430     "ami_root_device": {
   431       "source_device_name": "/dev/xvdf",
   432       "device_name": "/dev/xvda",
   433       "delete_on_termination": true,
   434       "volume_size": 16,
   435       "volume_type": "gp2"
   436     }
   437  }
   438  ```
   439  
   440  -&gt; **Note:** Packer can also read the access key and secret access key from
   441  environmental variables. See the configuration reference in the section above
   442  for more information on what environmental variables Packer will look for.
   443  
   444  Further information on locating AMI IDs and their relationship to instance
   445  types and regions can be found in the AWS EC2 Documentation
   446  [for Linux](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html)
   447  or [for Windows](http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/finding-an-ami.html).
   448  
   449  ## Accessing the Instance to Debug
   450  
   451  If you need to access the instance to debug for some reason, run the builder
   452  with the `-debug` flag. In debug mode, the Amazon builder will save the private
   453  key in the current directory and will output the DNS or IP information as well.
   454  You can use this information to access the instance as it is running.
   455  
   456  ## Build template data
   457  
   458  The available variables are:
   459  
   460  - `BuildRegion` - The region (for example `eu-central-1`) where Packer is building the AMI.
   461  - `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build the AMI.
   462  - `SourceAMIName` - The source AMI Name (for example `ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to build the AMI.
   463  - `SourceAMITags` - The source AMI Tags, as a `map[string]string` object.
   464  
   465  
   466  -&gt; **Note:** Packer uses pre-built AMIs as the source for building images.
   467  These source AMIs may include volumes that are not flagged to be destroyed on
   468  termination of the instance building the new image. In addition to those volumes
   469  created by this builder, any volumes inn the source AMI which are not marked for
   470  deletion on termination will remain in your account.