github.com/jmbataller/terraform@v0.6.8-0.20151125192640-b7a12e3a580c/website/source/docs/configuration/providers.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Configuring Providers"
     4  sidebar_current: "docs-config-providers"
     5  description: |-
     6    Providers are responsible in Terraform for managing the lifecycle of a resource: create, read, update, delete.
     7  ---
     8  
     9  # Provider Configuration
    10  
    11  Providers are responsible in Terraform for managing the lifecycle
    12  of a [resource](/docs/configuration/resources.html): create,
    13  read, update, delete.
    14  
    15  Every resource in Terraform is mapped to a provider based
    16  on longest-prefix matching. For example the `aws_instance`
    17  resource type would map to the `aws` provider (if that exists).
    18  
    19  Most providers require some sort of configuration to provide
    20  authentication information, endpoint URLs, etc. Provider configuration
    21  blocks are a way to set this information globally for all
    22  matching resources.
    23  
    24  This page assumes you're familiar with the
    25  [configuration syntax](/docs/configuration/syntax.html)
    26  already.
    27  
    28  ## Example
    29  
    30  A provider configuration looks like the following:
    31  
    32  ```
    33  provider "aws" {
    34  	access_key = "foo"
    35  	secret_key = "bar"
    36  	region = "us-east-1"
    37  }
    38  ```
    39  
    40  ## Description
    41  
    42  The `provider` block configures the provider of the given `NAME`.
    43  Multiple provider blocks can be used to configure multiple providers.
    44  
    45  Terraform matches providers to resources by matching two criteria.
    46  Both criteria must be matched for a provider to manage a resource:
    47  
    48    * They must share a common prefix. Longest matching prefixes are
    49      tried first. For example, `aws_instance` would choose the
    50      `aws` provider.
    51  
    52    * The provider must report that it supports the given resource
    53      type. Providers internally tell Terraform the list of resources
    54      they support.
    55  
    56  Within the block (the `{ }`) is configuration for the resource.
    57  The configuration is dependent on the type, and is documented
    58  [for each provider](/docs/providers/index.html).
    59  
    60  ## Multiple Provider Instances
    61  
    62  You can define multiple instances of the same provider in order to support
    63  multiple regions, multiple hosts, etc. The primary use case for this for
    64  multiple cloud regions. Other use cases including targeting multiple
    65  Docker hosts, multiple Consul hosts, etc.
    66  
    67  To define multiple provider instances, repeat the provider configuration
    68  multiple times, but set the `alias` field and name the provider. For
    69  example:
    70  
    71  ```
    72  # The default provider
    73  provider "aws" {
    74  	# ...
    75  }
    76  
    77  # West coast region
    78  provider "aws" {
    79  	alias = "west"
    80  
    81  	region = "us-west-2"
    82  }
    83  ```
    84  
    85  After naming a provider, you reference it in resources with the `provider`
    86  field:
    87  
    88  ```
    89  resource "aws_instance" "foo" {
    90  	provider = "aws.west"
    91  
    92  	# ...
    93  }
    94  ```
    95  
    96  If a provider isn't specified, then the default provider configuration
    97  is used (the provider configuration with no `alias` set). The value of the
    98  `provider` field is `TYPE.ALIAS`, such as "aws.west" above.
    99  
   100  ## Syntax
   101  
   102  The full syntax is:
   103  
   104  ```
   105  provider NAME {
   106  	CONFIG ...
   107  	[alias = ALIAS]
   108  }
   109  ```
   110  
   111  where `CONFIG` is:
   112  
   113  ```
   114  KEY = VALUE
   115  
   116  KEY {
   117  	CONFIG
   118  }
   119  ```