2.01 Terraform Providers
Overview
Terraform uses a plugin-based architecture to interact with infrastructure platforms. Providers are plugins that expose resource types and data sources for a specific platform — downloaded and installed automatically during terraform init.
Abstract
Providers are the bridge between Terraform and external APIs (AWS, GCP, Azure, local OS, etc.). Every resource in a configuration belongs to a provider. Terraform downloads provider plugins from the public Terraform Registry at registry.terraform.io unless a custom or private registry is specified.
Why It Matters in Production
Without understanding providers, teams risk:
- Unexpected breaking changes from auto-upgraded provider versions
- Inconsistent environments across team members or CI runners
- Failed
terraform initin air-gapped or restricted environments - Security gaps from using unverified community providers in sensitive workloads
Locking provider versions and understanding their trust tier is a foundational IaC practice.
Key Concepts
| Concept | Description |
|---|---|
| Provider | A plugin that interfaces Terraform with a specific platform or API |
| Source Address | Unique identifier for a provider: [hostname/]namespace/type |
| Hostname | Registry where the plugin lives (defaults to registry.terraform.io) |
| Namespace | Organisational owner, e.g. hashicorp, digitalocean |
| Type | Provider name, e.g. aws, google, local |
| terraform init | Downloads and installs all required provider plugins |
.terraform/ |
Hidden directory where plugins are cached locally |
Provider Tiers
| Tier | Owned By | Examples |
|---|---|---|
| Official | HashiCorp | aws, google, azurerm, local |
| Partner | Third-party companies (HashiCorp-verified) | bigip (F5 Networks), heroku, digitalocean |
| Community | Individual contributors | activedirectory, ucloud, netapp-gcp |
Note
Official and partner providers appear in the Terraform Registry UI with labelled badges. Community providers should be reviewed more carefully before use in production.
Source Address Format
registry.terraform.io/hashicorp/local
└─────────────────────┘ └────────┘ └───┘
Hostname Namespace Type
The hostname is optional — when omitted, Terraform defaults to registry.terraform.io:
# Short form (hostname omitted — resolves to registry.terraform.io)
source = "hashicorp/local"
# Full form
source = "registry.terraform.io/hashicorp/local"
Example Configuration & Commands
Declare a Required Provider
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
local = {
source = "hashicorp/local"
version = "~> 2.0"
}
}
}
Initialise and Inspect
# Download and install all declared providers
terraform init
# Confirm installed plugins
ls /root/my-project/.terraform/plugins
# Re-initialise safely (no infrastructure impact)
terraform init
Example init Output
Initializing provider plugins...
- Finding latest version of hashicorp/local...
- Installing hashicorp/local v2.0.0...
- Installed hashicorp/local v2.0.0 (signed by HashiCorp)
* hashicorp/local: version = "~> 2.0.0"
Terraform has been successfully initialized!
Best Practices
Best Practices
- Always declare
required_providerswith version constraints interraform {}block — never rely on automatic latest installs in production. - Use
~>(pessimistic constraint) to allow patch updates but block major version changes:~> 2.0allows2.xbut not3.0. - Commit
.terraform.lock.hclto version control to pin exact provider versions across all team members and CI runners. - Run
terraform init -upgradedeliberately and in a branch, not on main, when upgrading providers. - Prefer official providers for core infrastructure; vet community providers before use.
Security Best Practices
Security
- Only use providers signed by their verified publisher — Terraform verifies GPG signatures during install.
- For air-gapped environments, use a private registry or filesystem mirror instead of pulling directly from
registry.terraform.io. - Avoid community providers with low download counts or no recent updates in sensitive production workloads.
- Do not pin to a provider version that has a known CVE — monitor HashiCorp security advisories.
Do and Don't
| ✅ Do | ❌ Don't |
|---|---|
Pin provider versions with version = "~> X.Y" |
Leave version unconstrained and rely on latest |
Commit .terraform.lock.hcl to source control |
Add .terraform/ to version control (it's large and ephemeral) |
Run terraform init again after adding a new provider |
Assume a new provider block works without re-initialising |
| Use official or partner providers for production workloads | Use unknown community providers without code review |
| Use a private registry or mirror in air-gapped environments | Assume outbound internet access is always available in CI |
Common Mistakes
Common Mistakes
- No version constraints: Terraform installs the latest, which can introduce breaking changes silently.
- Missing
terraform initafter adding a provider: Terraform will error onplanorapplyif the plugin isn't installed. - Deleting
.terraform/in CI without caching: Causes repeated slow plugin downloads on every pipeline run. - Confusing provider namespace with type:
hashicorp/aws—hashicorpis the namespace,awsis the type; they are not interchangeable.
Troubleshooting
# Check which providers are installed and their versions
terraform providers
# Force re-download of all providers (useful after corruption or version changes)
terraform init -upgrade
# Inspect the lock file for pinned versions and hashes
cat .terraform.lock.hcl
# List cached plugin binaries
ls -la .terraform/providers/
Tip
terraform init is idempotent — it is safe to run multiple times. It will not modify existing infrastructure; it only manages local plugin state.
Quick Recap
terraform initdownloads provider plugins into.terraform/plugins/in the working directory- Provider source address format:
[hostname/]namespace/type(hostname defaults toregistry.terraform.io) - Three tiers: Official (HashiCorp), Partner (verified third-party), Community (individual contributors)
- By default Terraform installs the latest version — always add version constraints in
required_providers terraform initis safe and idempotent; it can be run as many times as needed
Interview / Revision Notes
Revision
- What does
terraform initdo? Downloads and installs provider plugins for all providers declared in the configuration. - Where are plugins stored? In the
.terraform/plugins/hidden directory within the working directory. - What is the source address format?
[hostname/]namespace/type— e.g.hashicorp/localorregistry.terraform.io/hashicorp/local. - What are the three provider tiers? Official (HashiCorp-owned), Partner (third-party verified), Community (individual contributors).
- Is
terraform initdestructive? No — it only manages local plugin state and never modifies infrastructure. - How do you prevent auto-upgrades to breaking versions? Use version constraints in
required_providersand commit.terraform.lock.hcl.