github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/website/source/docs/configuration/resources.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Configuring Resources"
     4  sidebar_current: "docs-config-resources"
     5  description: |-
     6    The most important thing you'll configure with Terraform are resources. Resources are a component of your infrastructure. It might be some low level component such as a physical server, virtual machine, or container. Or it can be a higher level component such as an email provider, DNS record, or database provider.
     7  ---
     8  
     9  # Resource Configuration
    10  
    11  The most important thing you'll configure with Terraform are
    12  resources. Resources are a component of your infrastructure.
    13  It might be some low level component such as a physical server,
    14  virtual machine, or container. Or it can be a higher level
    15  component such as an email provider, DNS record, or database
    16  provider.
    17  
    18  This page assumes you're familiar with the
    19  [configuration syntax](/docs/configuration/syntax.html)
    20  already.
    21  
    22  ## Example
    23  
    24  A resource configuration looks like the following:
    25  
    26  ```
    27  resource "aws_instance" "web" {
    28      ami = "ami-123456"
    29      instance_type = "m1.small"
    30  }
    31  ```
    32  
    33  ## Description
    34  
    35  The `resource` block creates a resource of the given `TYPE` (first
    36  parameter) and `NAME` (second parameter). The combination of the type
    37  and name must be unique.
    38  
    39  Within the block (the `{ }`) is configuration for the resource. The
    40  configuration is dependent on the type, and is documented for each
    41  resource type in the
    42  [providers section](/docs/providers/index.html).
    43  
    44  There are **meta-parameters** available to all resources:
    45  
    46    * `count` (int) - The number of identical resources to create.
    47        This doesn't apply to all resources. You can use the `${count.index}`
    48        [interpolation](/docs/configuration/interpolation.html) to reference
    49        the current count index in your resource.
    50  
    51    * `depends_on` (list of strings) - Explicit dependencies that this
    52        resource has. These dependencies will be created before this
    53        resource. The dependencies are in the format of `TYPE.NAME`,
    54        for example `aws_instance.web`.
    55  
    56    * `lifecycle` (configuration block) - Customizes the lifecycle
    57        behavior of the resource. The specific options are documented
    58        below.
    59  
    60  The `lifecycle` block allows the following keys to be set:
    61  
    62    * `create_before_destroy` (bool) - This flag is used to ensure
    63        the replacement of a resource is created before the original
    64        instance is destroyed. As an example, this can be used to
    65        create an new DNS record before removing an old record.
    66  
    67  -------------
    68  
    69  Within a resource, you can optionally have a **connection block**.
    70  Connection blocks describe to Terraform how to connect to the
    71  resource for
    72  [provisioning](/docs/provisioners/index.html). This block doesn't
    73  need to be present if you're using only local provisioners, or
    74  if you're not provisioning at all.
    75  
    76  Resources provide some data on their own, such as an IP address,
    77  but other data must be specified by the user.
    78  
    79  The full list of settings that can be specified are listed on
    80  the [provisioner connection page](/docs/provisioners/connection.html).
    81  
    82  -------------
    83  
    84  Within a resource, you can specify zero or more **provisioner
    85  blocks**. Provisioner blocks configure
    86  [provisioners](/docs/provisioners/index.html).
    87  
    88  Within the provisioner block is provisioner-specific configuration,
    89  much like resource-specific configuration.
    90  
    91  Provisioner blocks can also contain a connection block
    92  (documented above). This connection block can be used to
    93  provide more specific connection info for a specific provisioner.
    94  An example use case might be to use a different user to log in
    95  for a single provisioner.
    96  
    97  ## Syntax
    98  
    99  The full syntax is:
   100  
   101  ```
   102  resource TYPE NAME {
   103  	CONFIG ...
   104  	[count = COUNT]
   105      [depends_on = [RESOURCE NAME, ...]]
   106      [LIFECYCLE]
   107  
   108  	[CONNECTION]
   109  	[PROVISIONER ...]
   110  }
   111  ```
   112  
   113  where `CONFIG` is:
   114  
   115  ```
   116  KEY = VALUE
   117  
   118  KEY {
   119  	CONFIG
   120  }
   121  ```
   122  
   123  where `LIFECYCLE` is:
   124  
   125  ```
   126  lifecycle {
   127      [create_before_destroy = true|false]
   128  }
   129  ```
   130  
   131  where `CONNECTION` is:
   132  
   133  ```
   134  connection {
   135  	KEY = VALUE
   136  	...
   137  }
   138  ```
   139  
   140  where `PROVISIONER` is:
   141  
   142  ```
   143  provisioner NAME {
   144  	CONFIG ...
   145  
   146  	[CONNECTION]
   147  }
   148  ```