» Data Source: aws_ami
Use this data source to get the ID of a registered AMI for use in other resources.
» Example Usage
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"]
}
}
» Argument Reference
-
owners
- (Required) List of AMI owners to limit search. At least 1 value must be specified. 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 orself
. -
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) A 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. It is recommended to combine this with other options to narrow down the list AWS returns.
NOTE: If more or less than a single match is returned by the search,
Terraform will fail. Ensure that your search is specific enough to return
a single AMI ID only, or use most_recent
to choose the most recent one. If
you want to match multiple AMIs, use the aws_ami_ids
data source instead.
» Attributes Reference
id
is set to the ID of the found AMI. In addition, the following attributes
are exported:
NOTE: Some values are not always set and may not be available for interpolation.
-
architecture
- The OS architecture of the AMI (ie:i386
orx86_64
). -
block_device_mappings
- The block device mappings of the AMI.-
block_device_mappings.#.device_name
- The physical name of the device. -
block_device_mappings.#.ebs.delete_on_termination
-true
if the EBS volume will be deleted on termination. -
block_device_mappings.#.ebs.encrypted
-true
if the EBS volume is encrypted. -
block_device_mappings.#.ebs.iops
-0
if the EBS volume is not a provisioned IOPS image, otherwise the supported IOPS count. -
block_device_mappings.#.ebs.snapshot_id
- The ID of the snapshot. -
block_device_mappings.#.ebs.volume_size
- The size of the volume, in GiB. -
block_device_mappings.#.ebs.volume_type
- The volume type. -
block_device_mappings.#.no_device
- Suppresses the specified device included in the block device mapping of the AMI. -
block_device_mappings.#.virtual_name
- The virtual device name (for instance stores).
-
-
creation_date
- The date and time the image was created. -
description
- The description of the AMI that was provided during image creation. -
hypervisor
- The hypervisor type of the image. -
image_id
- The ID of the AMI. Should be the same as the resourceid
. -
image_location
- The location of the AMI. -
image_owner_alias
- The AWS account alias (for example,amazon
,self
) or the AWS account ID of the AMI owner. -
image_type
- The type of image. -
kernel_id
- The kernel associated with the image, if any. Only applicable for machine images. -
name
- The name of the AMI that was provided during image creation. -
owner_id
- The AWS account ID of the image owner. -
platform
- The value is Windows forWindows
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
- The RAM disk associated with the image, if any. Only applicable for machine images. -
root_device_name
- The device name of the root device. -
root_device_type
- The type of root device (ie:ebs
orinstance-store
). -
root_snapshot_id
- The snapshot id associated with the root device, if any (only applies toebs
root devices). -
sriov_net_support
- Specifies whether enhanced networking is enabled. -
state
- The current state of the AMI. If the state isavailable
, the image is successfully registered and can be used to launch an instance. -
state_reason
- Describes a state change. Fields areUNSET
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
- The key name of the tag. -
tags.#.value
- The value of the tag.
-
-
virtualization_type
- The type of virtualization of the AMI (ie:hvm
orparavirtual
).