github.com/atsaki/terraform@v0.4.3-0.20150919165407-25bba5967654/website/source/docs/providers/aws/r/instance.html.markdown (about)

     1  ---
     2  layout: "aws"
     3  page_title: "AWS: aws_instance"
     4  sidebar_current: "docs-aws-resource-instance"
     5  description: |-
     6    Provides an EC2 instance resource. This allows instances to be created, updated, and deleted. Instances also support provisioning.
     7  ---
     8  
     9  # aws\_instance
    10  
    11  Provides an EC2 instance resource. This allows instances to be created, updated,
    12  and deleted. Instances also support [provisioning](/docs/provisioners/index.html).
    13  
    14  ## Example Usage
    15  
    16  ```
    17  # Create a new instance of the ami-1234 on an m1.small node
    18  # with an AWS Tag naming it "HelloWorld"
    19  resource "aws_instance" "web" {
    20      ami = "ami-1234"
    21      instance_type = "m1.small"
    22      tags {
    23          Name = "HelloWorld"
    24      }
    25  }
    26  ```
    27  
    28  ## Argument Reference
    29  
    30  The following arguments are supported:
    31  
    32  * `ami` - (Required) The AMI to use for the instance.
    33  * `availability_zone` - (Optional) The AZ to start the instance in.
    34  * `placement_group` - (Optional) The Placement Group to start the instance in.
    35  * `ebs_optimized` - (Optional) If true, the launched EC2 instance will be
    36       EBS-optimized.
    37  * `disable_api_termination` - (Optional) If true, enables [EC2 Instance
    38       Termination Protection](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingDisableAPITermination)
    39  * `instance_initiated_shutdown_behavior` - (Optional) Shutdown behavior for the 
    40  instance. Amazon defaults this to `stop` for EBS-backed instances and 
    41  `terminate` for instance-store instances. Cannot be set on instance-store 
    42  instances. See [Shutdown Behavior](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingInstanceInitiatedShutdownBehavior) for more information.
    43  * `instance_type` - (Required) The type of instance to start
    44  * `key_name` - (Optional) The key name to use for the instance.
    45  * `monitoring` - (Optional) If true, the launched EC2 instance will have detailed monitoring enabled. (Available since v0.6.0)
    46  * `security_groups` - (Optional) A list of security group names to associate with.
    47     If you are within a non-default VPC, you'll need to use `vpc_security_group_ids` instead.
    48  * `vpc_security_group_ids` - (Optional) A list of security group IDs to associate with.
    49  * `subnet_id` - (Optional) The VPC Subnet ID to launch in.
    50  * `associate_public_ip_address` - (Optional) Associate a public ip address with an instance in a VPC.
    51  * `private_ip` - (Optional) Private IP address to associate with the
    52       instance in a VPC.
    53  * `source_dest_check` - (Optional) Controls if traffic is routed to the instance when
    54    the destination address does not match the instance. Used for NAT or VPNs. Defaults true.
    55  * `user_data` - (Optional) The user data to provide when launching the instance.
    56  * `iam_instance_profile` - (Optional) The IAM Instance Profile to
    57    launch the instance with.
    58  * `tags` - (Optional) A mapping of tags to assign to the resource.
    59  * `root_block_device` - (Optional) Customize details about the root block
    60    device of the instance. See [Block Devices](#block-devices) below for details.
    61  * `ebs_block_device` - (Optional) Additional EBS block devices to attach to the
    62    instance.  See [Block Devices](#block-devices) below for details.
    63  * `ephemeral_block_device` - (Optional) Customize Ephemeral (also known as
    64    "Instance Store") volumes on the instance. See [Block Devices](#block-devices) below for details.
    65  
    66  
    67  <a id="block-devices"></a>
    68  ## Block devices
    69  
    70  Each of the `*_block_device` attributes controls a portion of the AWS
    71  Instance's "Block Device Mapping". It's a good idea to familiarize yourself with [AWS's Block Device
    72  Mapping docs](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html)
    73  to understand the implications of using these attributes.
    74  
    75  The `root_block_device` mapping supports the following:
    76  
    77  * `volume_type` - (Optional) The type of volume. Can be `"standard"`, `"gp2"`,
    78    or `"io1"`. (Default: `"standard"`).
    79  * `volume_size` - (Optional) The size of the volume in gigabytes.
    80  * `iops` - (Optional) The amount of provisioned
    81    [IOPS](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-io-characteristics.html).
    82    This must be set with a `volume_type` of `"io1"`.
    83  * `delete_on_termination` - (Optional) Whether the volume should be destroyed
    84    on instance termination (Default: `true`).
    85  
    86  Modifying any of the `root_block_device` settings requires resource
    87  replacement.
    88  
    89  Each `ebs_block_device` supports the following:
    90  
    91  * `device_name` - The name of the device to mount.
    92  * `snapshot_id` - (Optional) The Snapshot ID to mount.
    93  * `volume_type` - (Optional) The type of volume. Can be `"standard"`, `"gp2"`,
    94    or `"io1"`. (Default: `"standard"`).
    95  * `volume_size` - (Optional) The size of the volume in gigabytes.
    96  * `iops` - (Optional) The amount of provisioned
    97    [IOPS](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-io-characteristics.html).
    98    This must be set with a `volume_type` of `"io1"`.
    99  * `delete_on_termination` - (Optional) Whether the volume should be destroyed
   100    on instance termination (Default: `true`).
   101  * `encrypted` - (Optional) Enables [EBS
   102    encryption](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html)
   103    on the volume (Default: `false`). Cannot be used with `snapshot_id`.
   104  
   105  Modifying any `ebs_block_device` currently requires resource replacement.
   106  
   107  Each `ephemeral_block_device` supports the following:
   108  
   109  * `device_name` - The name of the block device to mount on the instance.
   110  * `virtual_name` - The [Instance Store Device
   111    Name](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#InstanceStoreDeviceNames)
   112    (e.g. `"ephemeral0"`)
   113  
   114  Each AWS Instance type has a different set of Instance Store block devices
   115  available for attachment. AWS [publishes a
   116  list](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#StorageOnInstanceTypes)
   117  of which ephemeral devices are available on each type. The devices are always
   118  identified by the `virtual_name` in the format `"ephemeral{0..N}"`.
   119  
   120  ~> **NOTE:** Currently, changes to `*_block_device` configuration of _existing_
   121  resources cannot be automatically detected by Terraform. After making updates
   122  to block device configuration, resource recreation can be manually triggered by
   123  using the [`taint` command](/docs/commands/taint.html).
   124  
   125  ## Attributes Reference
   126  
   127  The following attributes are exported:
   128  
   129  * `id` - The instance ID.
   130  * `availability_zone` - The availability zone of the instance.
   131  * `placement_group` - The placement group of the instance.
   132  * `key_name` - The key name of the instance
   133  * `private_dns` - The Private DNS name of the instance
   134  * `private_ip` - The private IP address.
   135  * `public_dns` - The public DNS name of the instance
   136  * `public_ip` - The public IP address.
   137  * `security_groups` - The associated security groups.
   138  * `vpc_security_group_ids` - The associated security groups in non-default VPC
   139  * `subnet_id` - The VPC subnet ID.