Course contentsShow
← Cloud and Infrastructure
Lesson 744 of 2,98914. Terraform FundamentalsFree lesson

Resource Meta-Arguments: provider

Specify which provider configuration a resource should use when multiple provider instances exist.

Resource Meta-Arguments: provider

What you'll learn: How to explicitly assign a resource to a specific provider configuration when you have multiple instances of the same provider.


Why This Matters

Sometimes you need to manage resources across multiple regions, accounts, or configurations of the same cloud provider. For example, you might deploy an application in both us-east-1 and eu-west-1. By default, Terraform uses the default provider configuration for each resource, but the provider meta-argument lets you specify exactly which provider instance to use.

How It Works

The provider meta-argument accepts a reference to a named provider configuration. You use an alias in your provider block to distinguish between multiple configurations, then reference that alias in your resource.

Example Structure

# Default AWS provider in us-east-1
provider "aws" {
  region = "us-east-1"
}

# Additional AWS provider in eu-west-1 with alias
provider "aws" {
  alias  = "europe"
  region = "eu-west-1"
}

# This resource uses the default provider (us-east-1)
resource "aws_instance" "default_region" {
  ami           = "ami-12345"
  instance_type = "t2.micro"
}

# This resource explicitly uses the europe provider
resource "aws_instance" "europe_region" {
  provider      = aws.europe
  ami           = "ami-67890"
  instance_type = "t2.micro"
}

Notice the syntax: provider = aws.europe references the provider with alias "europe".

The Analogy

Think of providers as different warehouses your company uses. The default warehouse handles most orders, but sometimes you need to ship from a specific regional warehouse. The provider meta-argument is like writing "Ship from European warehouse" on a particular order.

Key Takeaway: Use the provider meta-argument to direct a resource to a specific provider configuration when managing infrastructure across multiple regions, accounts, or cloud environments.