

What a provider block does
A provider block (written in HCL like the rest of your Terraform) specifies how Terraform authenticates to and communicates with a platform. Typical configuration options include:- Endpoints and regions
- Authentication credentials or identity sources
- API version or feature toggles
- Provider-specific behavior and defaults
providers.tf file for clarity, but Terraform reads any *.tf file in the working directory. File placement is a convention, not a requirement.
Provider block structure and examples
- The syntax is
provider "<name>" { ... }. The provider label must match the provider name registered in the Terraform Registry (for example:aws,azurerm,github). - Each provider exposes its own arguments — consult the provider’s Registry page for exact options.
features {} block; authentication fields shown as placeholders)
Use secure secret management and the principle of least privilege. Avoid storing credentials or secrets directly in
.tf files or version control.Pinning provider versions (recommended)
Providers evolve independently from Terraform Core. To ensure consistent, reproducible deployments and to avoid unexpected breaking changes, pin provider versions with therequired_providers block inside terraform {}.
Example: pinning AWS and Azure providers
Authentication methods by provider
Different providers support different authentication mechanisms. The table below summarizes common approaches and recommended best practices.| Provider | Common authentication methods | Best practice |
|---|---|---|
| AWS | access key/secret, shared credentials file, instance profile / IAM role | Prefer IAM roles (instance profiles) or environment credentials; use least privilege |
| Azure | service principal (client_id/client_secret), managed identity | Use managed identity where possible; rotate service principals regularly |
| Google Cloud (GCP) | service account keys, workload identity | Use workload identity or short-lived tokens instead of long-lived keys |
| GitHub | personal access tokens (PAT), OAuth apps | Use fine-scoped tokens and rotate regularly |
Never commit credentials, client secrets, or service account keys into version control. Doing so risks accidental exposure.
Provider lifecycle and initialization
When you runterraform init, Terraform performs the following provider-related steps:
- Reads provider requirements from your configuration (
required_providers). - Checks local cache for provider binaries; if missing, downloads required provider plugins from the Terraform Registry (
https://registry.terraform.io). - Verifies downloads using cryptographic checksums and installs plugins locally.
- Initializes providers with the configuration you provided.
Using multiple provider configurations
A single provider configuration can manage many resource types for that platform (for example, oneaws provider can manage compute, storage, networking, and databases). You only need one provider block per account/region/scope.
If you must target multiple accounts, regions, or scopes, create multiple provider configurations and use alias to reference them in resources. Example flow:
- Define the default provider for the main account.
- Define an aliased provider for the secondary account or other region.
- Reference the aliased provider from resources with
provider = aws.secondary.
Where to find providers and documentation
Primary sources:- Terraform Registry: https://registry.terraform.io — provider pages include resource types, arguments, data sources, authentication examples, and change logs.
- Provider GitHub repositories — useful for release notes, issues, and deep dives.
- Official cloud provider docs for platform-specific details.
Summary
- Provider blocks configure how Terraform talks to platform APIs (regions, endpoints, credentials, features).
- Providers are independent plugins — pin versions with
required_providersto keep deployments stable. - Never store secrets in
.tffiles; use secret management and least privilege. - Run
terraform initto download and initialize providers; Terraform verifies provider binaries automatically. - Consult the Terraform Registry for provider documentation, examples, and versioning information.