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" "nat_ami" {
  most_recent      = true
  executable_users = ["self"]

  filter {
    name   = "owner-alias"
    values = ["amazon"]
  }

  filter {
    name   = "name"
    values = ["amzn-ami-vpc-nat*"]
  }

  name_regex = "^myami-\\d{3}"
  owners     = ["self"]
}

Argument Reference

  • 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.

  • 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.

  • owners - (Optional) Limit search to specific AMI owners. Valid items are the numeric account ID, amazon, or self.

  • 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.

Attributes Reference

id is set to the ID of the found AMI. In addition, the following attributes are exported:

© 2018 HashiCorp
Licensed under the MPL 2.0 License.
https://www.terraform.io/docs/providers/aws/d/ami.html