github.com/paybyphone/terraform@v0.9.5-0.20170613192930-9706042ddd51/website/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 ```hcl 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 tried first. 49 For example, `aws_instance` would choose the `aws` provider. 50 51 - The provider must report that it supports the given resource type. Providers 52 internally tell Terraform the list of resources they support. 53 54 Within the block (the `{ }`) is configuration for the resource. 55 The configuration is dependent on the type, and is documented 56 [for each provider](/docs/providers/index.html). 57 58 ## Initialization 59 60 Each time a new provider is added to configuration -- either explicitly via 61 a `provider` block or by adding a resource from that provider -- it's necessary 62 to initialize that provider before use. Initialization downloads and installs 63 the provider's plugin and prepares it to be used. 64 65 Provider initialization is one of the actions of `terraform init`. Running 66 this command will download and initialize any providers that are not already 67 initialized. 68 69 For more information, see 70 [the `terraform init` command](/docs/commands/init.html). 71 72 ## Provider Versions 73 74 Providers are released on a separate rhythm from Terraform itself, and thus 75 have their own version numbers. For production use, it is recommended to 76 constrain the acceptable provider versions via configuration, to ensure that 77 new versions with breaking changes will not be automatically installed by 78 `terraform init` in future. 79 80 When `terraform init` is run _without_ provider version constraints, it 81 prints a suggested version constraint string for each provider: 82 83 ``` 84 The following providers do not have any version constraints in configuration, 85 so the latest version was installed. 86 87 To prevent automatic upgrades to new major versions that may contain breaking 88 changes, it is recommended to add version = "..." constraints to the 89 corresponding provider blocks in configuration, with the constraint strings 90 suggested below. 91 92 * provider.aws: version = "~> 1.0" 93 ``` 94 95 To constrain the provider version as suggested, add a `version` argument to 96 the provider configuration block: 97 98 ```hcl 99 provider "aws" { 100 version = "~> 1.0" 101 102 access_key = "foo" 103 secret_key = "bar" 104 region = "us-east-1" 105 } 106 ``` 107 108 This special argument applies to _all_ providers. 109 [`terraform providers`](/docs/commands/providers.html) can be used to 110 view the specified version constraints for all providers used in the 111 current configuration. 112 113 ## Multiple Provider Instances 114 115 You can define multiple instances of the same provider in order to support 116 multiple regions, multiple hosts, etc. The primary use case for this is 117 utilizing multiple cloud regions. Other use cases include targeting multiple 118 Docker hosts, multiple Consul hosts, etc. 119 120 To define multiple provider instances, repeat the provider configuration 121 multiple times, but set the `alias` field and name the provider. For 122 example: 123 124 ```hcl 125 # The default provider 126 provider "aws" { 127 # ... 128 } 129 130 # West coast region 131 provider "aws" { 132 alias = "west" 133 region = "us-west-2" 134 } 135 ``` 136 137 After naming a provider, you reference it in resources with the `provider` 138 field: 139 140 ```hcl 141 resource "aws_instance" "foo" { 142 provider = "aws.west" 143 144 # ... 145 } 146 ``` 147 148 If a provider isn't specified, then the default provider configuration 149 is used (the provider configuration with no `alias` set). The value of the 150 `provider` field is `TYPE.ALIAS`, such as "aws.west" above. 151 152 ## Syntax 153 154 The full syntax is: 155 156 ```text 157 provider NAME { 158 CONFIG ... 159 [alias = ALIAS] 160 } 161 ``` 162 163 where `CONFIG` is: 164 165 ```text 166 KEY = VALUE 167 168 KEY { 169 CONFIG 170 } 171 ``` 172 173 ## Interpolation 174 Providers support [interpolation syntax](/docs/configuration/interpolation.html) allowing dynamic configuration at run time. 175 176 ```hcl 177 provider "aws" { 178 region = "${var.aws_region}" 179 } 180 ``` 181 182 -> **NOTE:** Because providers are one of the first things loaded when Terraform parses the graph, it is not possible to use the output from modules or resources as inputs to the provider. At this time, only [variables](/docs/configuration/variables.html) and [data sources](/docs/configuration/data-sources.html), including [remote state](/docs/providers/terraform/d/remote_state.html) may be used in an interpolation inside a provider stanza.