github.com/bengesoff/terraform@v0.3.1-0.20141018223233-b25a53629922/website/source/docs/configuration/resources.html.md (about)

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