Use this data source to get the ID of a registered AMI for use in other resources.
data "aws_ami" "example" {
executable_users = ["self"]
most_recent = true
name_regex = "^myami-\\d{3}"
owners = ["self"]
filter {
name = "name"
values = ["myami-*"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
owners
- (Optional) List of AMI owners to limit search. Valid values: an AWS account ID, self
(the current account), or an AWS owner alias (e.g., amazon
, aws-marketplace
, microsoft
).
most_recent
- (Optional) If more than one result is returned, use the most
recent AMI.
executable_users
- (Optional) Limit search to users with explicit launch permission on
the image. Valid items are the numeric account ID or self
.
include_deprecated
- (Optional) If true, all deprecated AMIs are included in the response. If false, no deprecated AMIs are included in the response. If no value is specified, the default value is false.
filter
- (Optional) One or more name/value pairs to filter off of. There are
several valid keys, for a full reference, check out
describe-images in the AWS CLI reference.
name_regex
- (Optional) Regex string to apply to the AMI list returned
by AWS. This allows more advanced filtering not supported from the AWS API. This
filtering is done locally on what AWS returns, and could have a performance
impact if the result is large. Combine this with other
options to narrow down the list AWS returns.
id
is set to the ID of the found AMI. In addition, the following attributes
are exported:
arn
- ARN of the AMI.architecture
- OS architecture of the AMI (ie: i386
or x86_64
).boot_mode
- Boot mode of the image.block_device_mappings
- Set of objects with block device mappings of the AMI.
device_name
- Physical name of the device.ebs
- Map containing EBS information, if the device is EBS based. Unlike most object attributes, these are accessed directly (e.g., ebs.volume_size
or ebs["volume_size"]
) rather than accessed through the first element of a list (e.g., ebs[0].volume_size
).
delete_on_termination
- true
if the EBS volume will be deleted on termination.encrypted
- true
if the EBS volume is encrypted.iops
- 0
if the EBS volume is not a provisioned IOPS image, otherwise the supported IOPS count.snapshot_id
- The ID of the snapshot.volume_size
- The size of the volume, in GiB.throughput
- The throughput that the EBS volume supports, in MiB/s.volume_type
- The volume type.no_device
- Suppresses the specified device included in the block device mapping of the AMI.virtual_name
- Virtual device name (for instance stores).creation_date
- Date and time the image was created.deprecation_time
- Date and time when the image will be deprecated.description
- Description of the AMI that was provided during image
creation.hypervisor
- Hypervisor type of the image.image_id
- ID of the AMI. Should be the same as the resource id
.image_location
- Location of the AMI.image_owner_alias
- AWS account alias (for example, amazon
, self
) or
the AWS account ID of the AMI owner.image_type
- Type of image.imds_support
- Instance Metadata Service (IMDS) support mode for the image. Set to v2.0
if instances ran from this image enforce IMDSv2.kernel_id
- Kernel associated with the image, if any. Only applicable
for machine images.name
- Name of the AMI that was provided during image creation.owner_id
- AWS account ID of the image owner.platform
- Value is Windows for Windows
AMIs; otherwise blank.product_codes
- Any product codes associated with the AMI.
product_codes.#.product_code_id
- The product code.product_codes.#.product_code_type
- The type of product code.public
- true
if the image has public launch permissions.ramdisk_id
- RAM disk associated with the image, if any. Only applicable
for machine images.root_device_name
- Device name of the root device.root_device_type
- Type of root device (ie: ebs
or instance-store
).root_snapshot_id
- Snapshot id associated with the root device, if any
(only applies to ebs
root devices).sriov_net_support
- Whether enhanced networking is enabled.state
- Current state of the AMI. If the state is available
, the image
is successfully registered and can be used to launch an instance.state_reason
- Describes a state change. Fields are UNSET
if not available.
state_reason.code
- The reason code for the state change.state_reason.message
- The message for the state change.tags
- Any tags assigned to the image.
tags.#.key
- Key name of the tag.tags.#.value
- Value of the tag.tpm_support
- If the image is configured for NitroTPM support, the value is v2.0
.virtualization_type
- Type of virtualization of the AMI (ie: hvm
or
paravirtual
).usage_operation
- Operation of the Amazon EC2 instance and the billing code that is associated with the AMI.platform_details
- Platform details associated with the billing code of the AMI.ena_support
- Whether enhanced networking with ENA is enabled.read
- (Default 20m
)