github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/website/source/docs/builders/amazon-ebs-volume.html.md (about) 1 --- 2 description: | 3 The `amazon-ebsvolume` Packer builder is like the EBS builder, but is 4 intended to create EBS volumes rather than a machine image. 5 layout: docs 6 page_title: 'Amazon EBS Volume Builder' 7 ... 8 9 # EBS Volume Builder 10 11 Type: `amazon-ebsvolume` 12 13 The `amazon-ebsvolume` Packer builder is able to create Amazon Elastic Block 14 Store volumes which are prepopulated with filesystems or data. 15 16 This builder builds EBS volumes by launching an EC2 instance from a source AMI, 17 provisioning that running machine, and then destroying the source machine, keeping 18 the volumes intact. 19 20 This is all done in your own AWS account. The builder will create temporary 21 key pairs, security group rules, etc. that provide it temporary access to the 22 instance while the image is being created. 23 24 The builder does *not* manage EBS Volumes. Once it creates volumes and stores 25 it in your account, it is up to you to use, delete, etc. the volumes. 26 27 ## Configuration Reference 28 29 There are many configuration options available for the builder. They are 30 segmented below into two categories: required and optional parameters. Within 31 each category, the available configuration keys are alphabetized. 32 33 In addition to the options listed here, a 34 [communicator](/docs/templates/communicator.html) can be configured for this 35 builder. 36 37 ### Required: 38 39 - `access_key` (string) - The access key used to communicate with AWS. [Learn 40 how to set this.](/docs/builders/amazon.html#specifying-amazon-credentials) 41 42 - `instance_type` (string) - The EC2 instance type to use while building the 43 AMI, such as `m1.small`. 44 45 - `region` (string) - The name of the region, such as `us-east-1`, in which to 46 launch the EC2 instance to create the AMI. 47 48 - `secret_key` (string) - The secret key used to communicate with AWS. [Learn 49 how to set this.](/docs/builders/amazon.html#specifying-amazon-credentials) 50 51 - `source_ami` (string) - The initial AMI used as a base for the newly 52 created machine. `source_ami_filter` may be used instead to populate this 53 automatically. 54 55 ### Optional: 56 57 - `ebs_volumes` (array of block device mappings) - Add the block 58 device mappings to the AMI. The block device mappings allow for keys: 59 60 - `device_name` (string) - The device name exposed to the instance (for 61 example, `/dev/sdh` or `xvdh`). Required when specifying `volume_size`. 62 - `delete_on_termination` (boolean) - Indicates whether the EBS volume is 63 deleted on instance termination 64 - `encrypted` (boolean) - Indicates whether to encrypt the volume or not 65 - `iops` (integer) - The number of I/O operations per second (IOPS) that the 66 volume supports. See the documentation on 67 [IOPs](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html) 68 for more information 69 - `no_device` (boolean) - Suppresses the specified device included in the 70 block device mapping of the AMI 71 - `snapshot_id` (string) - The ID of the snapshot 72 - `virtual_name` (string) - The virtual device name. See the documentation on 73 [Block Device 74 Mapping](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_BlockDeviceMapping.html) 75 for more information 76 - `volume_size` (integer) - The size of the volume, in GiB. Required if not 77 specifying a `snapshot_id` 78 - `volume_type` (string) - The volume type. `gp2` for General Purpose (SSD) 79 volumes, `io1` for Provisioned IOPS (SSD) volumes, and `standard` for Magnetic 80 volumes 81 - `tags` (map) - Tags to apply to the volume. These are retained after the 82 builder completes. 83 84 - `associate_public_ip_address` (boolean) - If using a non-default VPC, public 85 IP addresses are not provided by default. If this is toggled, your new 86 instance will get a Public IP. 87 88 - `availability_zone` (string) - Destination availability zone to launch 89 instance in. Leave this empty to allow Amazon to auto-assign. 90 91 - `ebs_optimized` (boolean) - Mark instance as [EBS 92 Optimized](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSOptimized.html). 93 Default `false`. 94 95 - `enhanced_networking` (boolean) - Enable enhanced 96 networking (SriovNetSupport) on HVM-compatible AMIs. If true, add 97 `ec2:ModifyInstanceAttribute` to your AWS IAM policy. 98 99 - `iam_instance_profile` (string) - The name of an [IAM instance 100 profile](https://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html) 101 to launch the EC2 instance with. 102 103 - `run_tags` (object of key/value strings) - Tags to apply to the instance 104 that is *launched* to create the AMI. These tags are *not* applied to the 105 resulting AMI unless they're duplicated in `tags`. 106 107 - `security_group_id` (string) - The ID (*not* the name) of the security group 108 to assign to the instance. By default this is not set and Packer will 109 automatically create a new temporary security group to allow SSH access. 110 Note that if this is specified, you must be sure the security group allows 111 access to the `ssh_port` given below. 112 113 - `security_group_ids` (array of strings) - A list of security groups as 114 described above. Note that if this is specified, you must omit the 115 `security_group_id`. 116 117 - `shutdown_behavior` (string) - Automatically terminate instances on shutdown 118 incase packer exits ungracefully. Possible values are `stop` and `terminate`. 119 Defaults to `stop`. 120 121 - `skip_region_validation` (boolean) - Set to `true` if you want to skip 122 validation of the region configuration option. Defaults to `false`. 123 124 - `snapshot_groups` (array of strings) - A list of groups that have access to 125 create volumes from the snapshot(s). By default no groups have permission to create 126 volumes form the snapshot(s). `all` will make the snapshot publicly accessible. 127 128 - `snapshot_users` (array of strings) - A list of account IDs that have access to 129 create volumes from the snapshot(s). By default no additional users other than the 130 user creating the AMI has permissions to create volumes from the backing snapshot(s). 131 132 - `source_ami_filter` (object) - Filters used to populate the `source_ami` field. 133 Example: 134 135 ``` {.javascript} 136 "source_ami_filter": { 137 "filters": { 138 "virtualization-type": "hvm", 139 "name": "*ubuntu-xenial-16.04-amd64-server-*", 140 "root-device-type": "ebs" 141 }, 142 "owners": ["099720109477"], 143 "most_recent": true 144 } 145 ``` 146 147 This selects the most recent Ubuntu 16.04 HVM EBS AMI from Canonical. 148 NOTE: This will fail unless *exactly* one AMI is returned. In the above 149 example, `most_recent` will cause this to succeed by selecting the newest image. 150 151 - `filters` (map of strings) - filters used to select a `source_ami`. 152 NOTE: This will fail unless *exactly* one AMI is returned. 153 Any filter described in the docs for [DescribeImages](http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html) 154 is valid. 155 156 - `owners` (array of strings) - This scopes the AMIs to certain Amazon account IDs. 157 This is helpful to limit the AMIs to a trusted third party, or to your own account. 158 159 - `most_recent` (bool) - Selects the newest created image when true. 160 This is most useful for selecting a daily distro build. 161 162 - `spot_price` (string) - The maximum hourly price to pay for a spot instance 163 to create the AMI. Spot instances are a type of instance that EC2 starts 164 when the current spot price is less than the maximum price you specify. Spot 165 price will be updated based on available spot instance capacity and current 166 spot instance requests. It may save you some costs. You can set this to 167 `auto` for Packer to automatically discover the best spot price or to `0` 168 to use an on-demand instance (default). 169 170 - `spot_price_auto_product` (string) - Required if `spot_price` is set 171 to `auto`. This tells Packer what sort of AMI you're launching to find the 172 best spot price. This must be one of: `Linux/UNIX`, `SUSE Linux`, `Windows`, 173 `Linux/UNIX (Amazon VPC)`, `SUSE Linux (Amazon VPC)` or `Windows (Amazon VPC)` 174 175 - `ssh_keypair_name` (string) - If specified, this is the key that will be 176 used for SSH with the machine. By default, this is blank, and Packer will 177 generate a temporary key pair unless 178 [`ssh_password`](/docs/templates/communicator.html#ssh_password) is used. 179 [`ssh_private_key_file`](/docs/templates/communicator.html#ssh_private_key_file) 180 must be specified with this. 181 182 - `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private 183 IP if available. 184 185 - `subnet_id` (string) - If using VPC, the ID of the subnet, such as 186 `subnet-12345def`, where Packer will launch the EC2 instance. This field is 187 required if you are using an non-default VPC. 188 189 - `temporary_key_pair_name` (string) - The name of the temporary key pair 190 to generate. By default, Packer generates a name with an UUID. 191 192 - `token` (string) - The access token to use. This is different from the 193 access key and secret key. If you're not sure what this is, then you 194 probably don't need it. This will also be read from the `AWS_SESSION_TOKEN` 195 environmental variable. 196 197 - `user_data` (string) - User data to apply when launching the instance. Note 198 that you need to be careful about escaping characters due to the templates 199 being JSON. It is often more convenient to use `user_data_file`, instead. 200 201 - `user_data_file` (string) - Path to a file that will be used for the user 202 data when launching the instance. 203 204 - `vpc_id` (string) - If launching into a VPC subnet, Packer needs the VPC ID 205 in order to create a temporary security group within the VPC. Requires `subnet_id` 206 to be set. 207 208 - `windows_password_timeout` (string) - The timeout for waiting for a Windows 209 password for Windows instances. Defaults to 20 minutes. Example value: `10m` 210 211 ## Basic Example 212 213 ``` 214 { 215 "type" : "amazon-ebsvolume", 216 "secret_key" : "YOUR SECRET KEY HERE", 217 "access_key" : "YOUR KEY HERE", 218 "region" : "us-east-1", 219 "ssh_username" : "ubuntu", 220 "instance_type" : "t2.medium", 221 "source_ami" : "ami-40d28157", 222 "ebs_volumes" : [ 223 { 224 "volume_type" : "gp2", 225 "device_name" : "/dev/xvdf", 226 "delete_on_termination" : false, 227 "tags" : { 228 "zpool" : "data", 229 "Name" : "Data1" 230 }, 231 "volume_size" : 10 232 }, 233 { 234 "volume_type" : "gp2", 235 "device_name" : "/dev/xvdg", 236 "tags" : { 237 "zpool" : "data", 238 "Name" : "Data2" 239 }, 240 "delete_on_termination" : false, 241 "volume_size" : 10 242 }, 243 { 244 "volume_size" : 10, 245 "tags" : { 246 "Name" : "Data3", 247 "zpool" : "data" 248 }, 249 "delete_on_termination" : false, 250 "device_name" : "/dev/xvdh", 251 "volume_type" : "gp2" 252 } 253 ] 254 } 255 ``` 256 257 -> **Note:** Packer can also read the access key and secret access key from 258 environmental variables. See the configuration reference in the section above 259 for more information on what environmental variables Packer will look for. 260 261 Further information on locating AMI IDs and their relationship to instance 262 types and regions can be found in the AWS EC2 Documentation 263 [for Linux](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html) 264 or [for Windows](http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/finding-an-ami.html). 265 266 ## Accessing the Instance to Debug 267 268 If you need to access the instance to debug for some reason, run the builder 269 with the `-debug` flag. In debug mode, the Amazon builder will save the private 270 key in the current directory and will output the DNS or IP information as well. 271 You can use this information to access the instance as it is running. 272 273 -> **Note:** Packer uses pre-built AMIs as the source for building images. 274 These source AMIs may include volumes that are not flagged to be destroyed on 275 termination of the instance building the new image. In addition to those volumes 276 created by this builder, any volumes inn the source AMI which are not marked for 277 deletion on termination will remain in your account.