Configuring Providers
A provider block configures a plugin such as AWS, setting the region and other defaults.
provider "aws" {
region = "us-east-1"
}A provider is the plugin that lets Terraform talk to a specific platform. Declaring it in required_providers tells Terraform to download it; a provider block configures how it behaves.
The AWS provider
The most common setting is region. Other arguments configure profiles, endpoints, and default tags applied to every resource.
default_tags
Setting default_tags on the provider automatically stamps those tags onto every resource it creates — great for cost tracking.
Example
provider "aws" {
region = "us-east-1"
# Applied to every resource this provider creates
default_tags {
tags = {
Project = "SoundsCode"
ManagedBy = "Terraform"
}
}
}When to use it
- A team configures the AWS provider with a default region and tags so that every resource created in that configuration inherits those defaults.
- A DevOps engineer sets the Kubernetes provider to read credentials from kubeconfig, enabling Terraform to manage cluster resources alongside cloud infra.
- An operator uses provider version constraints to lock the AWS provider to a tested minor version and prevent CI from silently upgrading it.
More examples
Basic AWS provider block
Declares and configures the AWS provider with a version constraint and a default region.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.50"
}
}
}
provider "aws" {
region = "us-east-1"
}Provider with default tags
Uses the AWS provider's default_tags block to automatically apply a standard tag set to every created resource.
provider "aws" {
region = "us-east-1"
default_tags {
tags = {
Project = "my-app"
ManagedBy = "terraform"
Environment = var.environment
}
}
}Google Cloud provider config
Configures the Google Cloud provider with project, region, and zone defaults for all resources in the configuration.
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
}
}
provider "google" {
project = "my-gcp-project-id"
region = "us-central1"
zone = "us-central1-a"
}
Discussion