Resource: aws_ami

The AMI resource allows the creation and management of a completely-custom Amazon Machine Image (AMI).

If you just want to duplicate an existing AMI, possibly copying it to another region, it's better to use aws_ami_copy instead.

If you just want to share an existing AMI with another AWS account, it's better to use aws_ami_launch_permission instead.

Example Usage

# Create an AMI that will start a machine whose root device is backed by
# an EBS volume populated from a snapshot. We assume that such a snapshot
# already exists with the id "snap-xxxxxxxx".
resource "aws_ami" "example" {
  name                = "terraform-example"
  virtualization_type = "hvm"
  root_device_name    = "/dev/xvda"
  imds_support        = "v2.0" # Enforce usage of IMDSv2. You can safely remove this line if your application explicitly doesn't support it.
  ebs_block_device {
    device_name = "/dev/xvda"
    snapshot_id = "snap-xxxxxxxx"
    volume_size = 8
  }
}

Argument Reference

This resource supports the following arguments:

When virtualization_type is "paravirtual" the following additional arguments apply:

When virtualization_type is "hvm" the following additional arguments apply:

Nested ebs_block_device blocks have the following structure:

Nested ephemeral_block_device blocks have the following structure:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Timeouts

Configuration options:

Import

In Terraform v1.5.0 and later, use an import block to import aws_ami using the ID of the AMI. For example:

import {
  to = aws_ami.example
  id = "ami-12345678"
}

Using terraform import, import aws_ami using the ID of the AMI. For example:

% terraform import aws_ami.example ami-12345678