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