2014-07-28 19:43:00 +02:00
---
layout: "docs"
page_title: "Configuring Providers"
sidebar_current: "docs-config-providers"
2014-10-22 05:21:56 +02:00
description: |-
Providers are responsible in Terraform for managing the lifecycle of a resource: create, read, update, delete.
2014-07-28 19:43:00 +02:00
---
# Provider Configuration
Providers are responsible in Terraform for managing the lifecycle
2015-05-04 20:41:18 +02:00
of a [resource ](/docs/configuration/resources.html ): create,
2014-07-28 19:43:00 +02:00
read, update, delete.
Every resource in Terraform is mapped to a provider based
on longest-prefix matching. For example the `aws_instance`
resource type would map to the `aws` provider (if that exists).
Most providers require some sort of configuration to provide
authentication information, endpoint URLs, etc. Provider configuration
blocks are a way to set this information globally for all
matching resources.
This page assumes you're familiar with the
[configuration syntax ](/docs/configuration/syntax.html )
already.
## Example
A provider configuration looks like the following:
2017-04-05 17:29:27 +02:00
```hcl
2014-07-28 19:43:00 +02:00
provider "aws" {
2017-04-05 17:29:27 +02:00
access_key = "foo"
secret_key = "bar"
region = "us-east-1"
2014-07-28 19:43:00 +02:00
}
```
2014-08-07 09:19:56 +02:00
## Description
2014-07-28 19:43:00 +02:00
The `provider` block configures the provider of the given `NAME` .
Multiple provider blocks can be used to configure multiple providers.
Terraform matches providers to resources by matching two criteria.
Both criteria must be matched for a provider to manage a resource:
2017-04-05 17:29:27 +02:00
- They must share a common prefix. Longest matching prefixes are tried first.
For example, `aws_instance` would choose the `aws` provider.
2014-07-28 19:43:00 +02:00
2017-04-05 17:29:27 +02:00
- The provider must report that it supports the given resource type. Providers
internally tell Terraform the list of resources they support.
2014-07-28 19:43:00 +02:00
Within the block (the `{ }` ) is configuration for the resource.
The configuration is dependent on the type, and is documented
[for each provider ](/docs/providers/index.html ).
2015-04-21 01:54:56 +02:00
## Multiple Provider Instances
You can define multiple instances of the same provider in order to support
2016-09-08 05:55:03 +02:00
multiple regions, multiple hosts, etc. The primary use case for this is
utilizing multiple cloud regions. Other use cases include targeting multiple
2015-04-21 01:54:56 +02:00
Docker hosts, multiple Consul hosts, etc.
To define multiple provider instances, repeat the provider configuration
multiple times, but set the `alias` field and name the provider. For
example:
2017-04-05 17:29:27 +02:00
```hcl
2015-04-21 01:54:56 +02:00
# The default provider
provider "aws" {
2017-04-05 17:29:27 +02:00
# ...
2015-04-21 01:54:56 +02:00
}
# West coast region
provider "aws" {
2017-04-05 17:29:27 +02:00
alias = "west"
region = "us-west-2"
2015-04-21 01:54:56 +02:00
}
```
After naming a provider, you reference it in resources with the `provider`
field:
2017-04-05 17:29:27 +02:00
```hcl
2015-04-21 01:54:56 +02:00
resource "aws_instance" "foo" {
2017-04-05 17:29:27 +02:00
provider = "aws.west"
2015-04-21 01:54:56 +02:00
2017-04-05 17:29:27 +02:00
# ...
2015-04-21 01:54:56 +02:00
}
```
If a provider isn't specified, then the default provider configuration
is used (the provider configuration with no `alias` set). The value of the
`provider` field is `TYPE.ALIAS` , such as "aws.west" above.
2014-07-28 19:43:00 +02:00
## Syntax
The full syntax is:
2017-04-05 17:29:27 +02:00
```text
2014-07-28 19:43:00 +02:00
provider NAME {
2017-04-05 17:29:27 +02:00
CONFIG ...
[alias = ALIAS]
2014-07-28 19:43:00 +02:00
}
```
where `CONFIG` is:
2017-04-05 17:29:27 +02:00
```text
2014-07-28 19:43:00 +02:00
KEY = VALUE
KEY {
2017-04-05 17:29:27 +02:00
CONFIG
2014-07-28 19:43:00 +02:00
}
```
2017-04-06 10:19:37 +02:00
## Interpolation
Providers support [interpolation syntax ](/docs/configuration/interpolation.html ) allowing dynamic configuration at run time.
```
provider "aws" {
region = "${var.aws_region}"
}
```
2017-04-07 11:07:23 +02:00
~> **NOTE:** Only [variables ](/docs/configuration/variables ) and [remote state ](/docs/state/remote.html ) are supported at this point, it is not currently possible to use the output from a resource, module or data source in the interpolation syntax for a provider.