Provides an EC2 instance resource. This allows instances to be created, updated, and deleted. Instances also support provisioning.

Example Usage

# Create a new instance of the latest Ubuntu 14.04 on an
# t1.micro node with an AWS Tag naming it "HelloWorld"
provider "aws" {
    region = "us-east-1"

data "aws_ami" "ubuntu" {
  most_recent = true
  filter {
    name = "name"
    values = ["ubuntu/images/ebs/ubuntu-trusty-14.04-amd64-server-*"]
  filter {
    name = "virtualization-type"
    values = ["paravirtual"]
  owners = ["099720109477"] # Canonical

resource "aws_instance" "web" {
    ami = "${data.aws_ami.ubuntu.id}"
    instance_type = "t1.micro"
    tags {
        Name = "HelloWorld"

Argument Reference

The following arguments are supported:

Block devices

Each of the *_block_device attributes controls a portion of the AWS Instance’s “Block Device Mapping”. It’s a good idea to familiarize yourself with AWS’s Block Device Mapping docs to understand the implications of using these attributes.

The root_block_device mapping supports the following:

Modifying any of the root_block_device settings requires resource replacement.

Each ebs_block_device supports the following:

Modifying any ebs_block_device currently requires resource replacement.

~> NOTE on EBS block devices: If you use ebs_block_device on an aws_instance, Terraform will assume management over the full set of non-root EBS block devices for the instance, and treats additional block devices as drift. For this reason, ebs_block_device cannot be mixed with external aws_ebs_volume + aws_volume_attachment resources for a given instance.

Each ephemeral_block_device supports the following:

Each AWS Instance type has a different set of Instance Store block devices available for attachment. AWS publishes a list of which ephemeral devices are available on each type. The devices are always identified by the virtual_name in the format "ephemeral{0..N}".

~> NOTE: Currently, changes to *_block_device configuration of existing resources cannot be automatically detected by Terraform. After making updates to block device configuration, resource recreation can be manually triggered by using the taint command.

Attributes Reference

The following attributes are exported:


Instances can be imported using the id, e.g.

$ terraform import aws_instance.web i-12345678

See the source of this document at Terraform.io