2020-11-13 03:06:32 +01:00
|
|
|
---
|
2021-12-15 03:41:17 +01:00
|
|
|
page_title: The Resource provider Meta-Argument - Configuration Language
|
|
|
|
description: >-
|
|
|
|
The provider meta-argument specifies the provider configuration Terraform
|
|
|
|
should use for a resource, overriding Terraform's default behavior.
|
2020-11-13 03:06:32 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
# The Resource `provider` Meta-Argument
|
|
|
|
|
|
|
|
The `provider` meta-argument specifies which provider configuration to use for a resource,
|
|
|
|
overriding Terraform's default behavior of selecting one based on the resource
|
|
|
|
type name. Its value should be an unquoted `<PROVIDER>.<ALIAS>` reference.
|
|
|
|
|
2021-12-15 03:41:17 +01:00
|
|
|
As described in [Provider Configuration](/language/providers/configuration), you can optionally
|
2020-11-13 03:06:32 +01:00
|
|
|
create multiple configurations for a single provider (usually to manage
|
|
|
|
resources in different regions of multi-region services). Each provider can have
|
|
|
|
one default configuration, and any number of alternate configurations that
|
|
|
|
include an extra name segment (or "alias").
|
|
|
|
|
|
|
|
By default, Terraform interprets the initial word in the resource type name
|
|
|
|
(separated by underscores) as the local name of a provider, and uses that
|
|
|
|
provider's default configuration. For example, the resource type
|
|
|
|
`google_compute_instance` is associated automatically with the default
|
|
|
|
configuration for the provider named `google`.
|
|
|
|
|
|
|
|
By using the `provider` meta-argument, you can select an alternate provider
|
|
|
|
configuration for a resource:
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
# default configuration
|
|
|
|
provider "google" {
|
|
|
|
region = "us-central1"
|
|
|
|
}
|
|
|
|
|
|
|
|
# alternate configuration, whose alias is "europe"
|
|
|
|
provider "google" {
|
|
|
|
alias = "europe"
|
|
|
|
region = "europe-west1"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance" "example" {
|
|
|
|
# This "provider" meta-argument selects the google provider
|
|
|
|
# configuration whose alias is "europe", rather than the
|
|
|
|
# default configuration.
|
|
|
|
provider = google.europe
|
|
|
|
|
|
|
|
# ...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
A resource always has an implicit dependency on its associated provider, to
|
|
|
|
ensure that the provider is fully configured before any resource actions
|
|
|
|
are taken.
|
|
|
|
|
|
|
|
The `provider` meta-argument expects
|
2021-12-15 03:41:17 +01:00
|
|
|
[a `<PROVIDER>.<ALIAS>` reference](/language/providers/configuration#referring-to-alternate-provider-configurations),
|
2020-11-13 03:06:32 +01:00
|
|
|
which does not need to be quoted. Arbitrary expressions are not permitted for
|
|
|
|
`provider` because it must be resolved while Terraform is constructing the
|
|
|
|
dependency graph, before it is safe to evaluate expressions.
|