Terraform
provider reference
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. Note that the provider argument is distinct from the provider block, which contains provider configuration settings. Refer to Providers for more information.
Usage
By default, Terraform determines the local name of the provider from the first word in the resource type and uses that provider's default configuration to create the resource. For example, the resource type google_compute_instance automatically uses the default configuration for the google provider.
The default behavior does not apply to list blocks, however, because Terraform does not implicitly use the default provider configuration when querying resources.
You can add multiple provider blocks to your configuration and use the provider argument to a resource definition to specify which provider it should use. For its value, the provider argument expects a reference formatted as <PROVIDER>.<ALIAS>. In the following example, the google_compute_instance resource selects the provider configuration with the europe alias.
provider "google" {
region = "us-central1"
}
provider "google" {
alias = "europe"
region = "europe-west1"
}
resource "google_compute_instance" "example" {
provider = google.europe
# ...
}
Quotation marks are not required. Arbitrary expressions are not permitted because Terraform must resolve the provider value while constructing the dependency graph before Terraform can safely evaluate expressions.
A resource always has an implicit dependency on its associated provider. This ensures that the provider is fully configured before Terraform takes any actions on resources.
Creating multiple configurations for a single provider is a common pattern for managing resources in different regions of multi-region services.
Supported constructs
You can use provider in the following Terraform configuration blocks:
You can use for_each in the following query configuration blocks:
Example use cases
The following use cases describe common patterns for the provider argument. Refer to the examples in the provider block reference for more use cases.
Query a data source in different region
In the following example, the google_compute_instance data source selects the provider configuration with the europe alias.
provider "google" {
region = "us-central1"
}
provider "google" {
alias = "europe"
region = "europe-west1"
}
data "google_compute_instance" "example" {
provider = google.europe
# ...
}
Use alternate provider for an ephemeral resource
In the following example, Terraform uses the aws.west provider configuration to create the aws_secretsmanager_secret_version resource in the us-west-2 region:
provider "aws" {
region = "us-east-1"
}
provider "aws" {
alias = "west"
region = "us-west-2"
}
ephemeral "aws_secretsmanager_secret_version" "db_password" {
provider = aws.west
secret_id = aws_secretsmanager_secret.db_password.id
}
Import resources using an alternate provider configuration
In the following example, Terraform imports the AWS instance with the ID i-096fba6d03d36d262 to the aws_instance.web resource according to the east alias.
provider "aws" {
region = "us-westl-1"
}
provider "aws" {
alias = "east"
region = "us-east-1"
}
import {
id = "i-096fba6d03d36d262"
to = aws_instance.web
provider = aws.east
}
resource "aws_instance" "web" {
# ...
}