Resource: aws_ami#
Manages an Amazon Machine Image (AMI).
If you just want to share an existing image with another project,
it's better to use aws_ami_launch_permission instead.
For more information about images, see user documentation.
Example Usage#
# Creates an image that will start a machine whose root device is backed by
# an EBS volume populated from a snapshot. It is assumed that such a snapshot
# already exists with the ID "snap-12345678".
resource "aws_ami" "example" {
name = "tf-ami"
virtualization_type = "hvm"
root_device_name = "disk1"
ebs_block_device {
device_name = "disk1"
snapshot_id = "snap-12345678"
volume_size = 8
}
}
Argument Reference#
The following arguments are supported:
name- (Required) An unique name for the image.architecture- (Optional) Machine architecture for created instances.- Default value:
x86_64
- Default value:
description- (Optional) A longer, human-readable description for the image.ebs_block_device- (Optional) List of EBS block devices that should be attached to created instances. The structure of this block is described below.ephemeral_block_device- (Optional) List of ephemeral block devices that should be attached to created instances. The structure of this block is described below.root_device_name- (Optional) The name of the root device.- Valid values:
disk<N>,cdrom<N>,floppy<N>,menu, where<N>is a disk number - Default value:
disk1
- Valid values:
tags- (Optional) Map of tags to assign to the image. If a providerdefault_tagsconfiguration block is used, tags with matching keys will overwrite those defined at the provider level.virtualization_type- (Optional) Keyword to choose what virtualization mode created instances will use.- Valid values:
hvm,hvm-legacy - Default value:
hvm
- Valid values:
ebs_block_device#
The ebs_block_device blocks has the following structure:
device_name- (Required) The device name of one or more block device mapping entries.- Valid values:
disk<N>,cdrom<N>,floppy<N>, where<N>is a disk number
- Valid values:
delete_on_termination- (Optional) Controls whether the EBS volumes will be deleted once the instance for which they were created is terminated.- Default value:
true
- Default value:
iops- (Optional) Number of I/O operations per second the created volumes will support.- Constraints: Required if
volume_typeisio2
- Constraints: Required if
snapshot_id- (Optional) The ID of an EBS snapshot that will be used to initialize the created EBS volumes.- Constraints: If set, the
volume_sizeattribute must be at least as large as the referenced snapshot
- Constraints: If set, the
volume_size- (Optional) The size of created volumes, in GiB.- Constraints: Required unless
snapshot_idis set. Ifsnapshot_idis set andvolume_sizeis omitted then the volume will have the same size as the selected snapshot
- Constraints: Required unless
volume_type- (Optional) The type of EBS volume to create.- Valid values:
st2,gp2,io2 - Default value:
st2
- Valid values:
ephemeral_block_device#
The ephemeral_block_device block has the following structure:
device_name- (Required) The device name of one or more block device mapping entries.- Valid values:
cdrom<N>,floppy<N>, where<N>is a disk number
- Valid values:
virtual_name- (Required) A name for the ephemeral device.- Constraints: Must match with the device name
Attribute Reference#
Supported attributes#
In addition to all arguments above, the following attributes are exported:
arn- The Amazon Resource Name (ARN) of the image.id- The ID of the created image.image_owner_alias- The alias of the image owner.image_type- The type of the image.owner_id- The ID of the image owner.platform- The platform of the image.public- Indicates whether the image has public launch permissions.root_snapshot_id- The ID of the snapshot for the root volume (for EBS-backed images).tags_all- Map of tags assigned to the image, including those inherited from the providerdefault_tagsconfiguration block.
Unsupported attributes#
~> Note These attributes may be present in the terraform.tfstate file, but their values are preset and cannot be specified in configuration files.
The following attributes are not currently supported:
boot_mode, deprecation_time, ebs_block_device.encrypted, ebs_block_device.kms_key_id, ebs_block_device.outpost_arn, ebs_block_device.throughput, ena_support, hypervisor, image_location, kernel_id, platform_details, ramdisk_id, sriov_net_support, usage_operation.
Timeouts#
The timeouts block allows you to specify timeouts for certain actions:
create- (Default40 minutes) Used when creating the image.update- (Default40 minutes) Used when updating the image.delete- (Default90 minutes) Used when deregistering the image.
Import#
aws_ami can be imported using the ID of the image, e.g.,
$ terraform import aws_ami.example cmi-12345678