A Terraform provider is a plugin that connects Terraform to an external API, translating declarative resource definitions into the create, read, update and delete calls that a cloud platform, SaaS product or on-premises system understands. In infrastructure as code, providers are the layer that makes Terraform platform-agnostic: the core engine knows nothing about virtual machines or DNS records, and every concrete resource type comes from a provider.
Each provider defines a set of resource types and data sources, a configuration schema for authentication and region settings, and the logic that maps attributes to API fields. Thousands of providers exist, from the large AWS, Azure and Google Cloud providers to small ones for monitoring tools, identity systems and network appliances, and the same plugin protocol is used by OpenTofu.
How a Terraform provider works with Terraform core
A Terraform provider runs as a separate executable process that Terraform core starts and talks to over gRPC using the plugin protocol. Core parses the HashiCorp Configuration Language files, builds a dependency graph and compares desired configuration with Terraform state, while the provider handles everything specific to the target API.
During terraform plan, core asks the provider to validate configuration and plan changes for each resource, and the provider returns the proposed new state, including values that will be known only after apply. During terraform apply, core calls the provider to perform the actual changes and then records the returned attributes in state. Refresh operations call the read function to detect configuration drift.
The table below shows the main operations that core requests from a provider and the purpose of each.
| Operation | When it runs | Purpose |
|---|---|---|
| GetProviderSchema | At initialization | Describes resources, data sources and attributes |
| ValidateResourceConfig | During validate and plan | Rejects invalid argument values early |
| PlanResourceChange | During plan | Computes the proposed new state and replacements |
| ApplyResourceChange | During apply | Calls the API to create, update or delete |
| ReadResource | During refresh | Fetches current real-world attributes |
| ImportResourceState | During import | Brings an existing object under management |
Provider sources, versions and installation
Providers are declared in a required_providers block that gives each one a source address and a version constraint. The source address has the form hostname, namespace and type, such as registry.terraform.io/hashicorp/aws, with the public registry hostname usually omitted as hashicorp/aws.
Running terraform init downloads the matching provider binaries for the local operating system and architecture and writes the exact versions and checksums to the dependency lock file .terraform.lock.hcl. Committing this file to version control ensures that every team member and every CI run uses the same provider build, which is essential because provider upgrades can change resource behavior.
Providers are grouped into tiers that indicate who maintains them, as summarized in the following table.
| Tier | Maintained by | Typical examples |
|---|---|---|
| Official | HashiCorp | AWS, Azure, Google Cloud, Kubernetes |
| Partner | Technology vendors in a partner program | Datadog, Cloudflare, MongoDB Atlas |
| Community | Individual contributors or groups | Niche tools and smaller services |
| Archived | No longer maintained | Deprecated or superseded providers |
Version constraints use operators such as ~> 5.0, which allows minor and patch updates within major version 5 but blocks a breaking jump to 6. Major provider releases routinely remove deprecated arguments, so upgrades should be planned and reviewed rather than accepted automatically.
Configuring providers, aliases and authentication
A provider block supplies the settings a provider needs to reach its API, such as region, endpoint, project identifier and credentials. Most providers also read standard environment variables or local credential files, which keeps secrets out of the configuration and out of version control.
When one configuration must address several accounts or regions, a provider can be declared multiple times with an alias, and individual resources select the right instance with the provider meta-argument. Modules receive provider configurations from their caller through the providers argument, so a reusable Terraform module should not hard-code its own provider block.
The table compares the common authentication approaches and where each fits best.
| Approach | Best suited for | Main risk |
|---|---|---|
| Static access keys | Quick local experiments | Long-lived secrets that leak easily |
| Environment variables | Local work and simple pipelines | Exposure in logs or shell history |
| Assumed roles | Cross-account deployments | Overly broad trust policies |
| Workload identity (OIDC) | CI pipelines in hosted platforms | Misconfigured claim conditions |
| Instance or managed identity | Runners inside the cloud | Permissions shared by all workloads on the host |
How providers relate to modules, state and other tools
Providers are often confused with neighboring concepts, yet each plays a distinct role in a Terraform project. A provider supplies resource types, a module groups resources into a reusable unit, and state records which real objects those resources correspond to.
| Concept | What it is | Relationship to providers |
|---|---|---|
| Terraform provider | Plugin that implements resource types | Foundation that everything else uses |
| Terraform module | Reusable collection of resources | Consumes provider configurations |
| Terraform state | Record of managed objects and attributes | Stores provider-returned values |
| Pulumi provider | Plugin for the Pulumi engine | Some are bridged from Terraform providers |
| Crossplane provider | Kubernetes controller for external APIs | Several are generated from Terraform providers |
Because the plugin protocol is well documented, the Terraform provider ecosystem has become a shared asset beyond Terraform itself. OpenTofu uses the same providers through its own registry, and tools such as Pulumi and Crossplane reuse Terraform provider code through bridging layers.
Writing providers and avoiding common pitfalls
Custom providers are written in Go with the Terraform Plugin Framework, which replaced the older Plugin SDK v2 as the recommended library. A provider author defines schemas, implements the CRUD functions against the target API and writes acceptance tests that create and destroy real objects.
Users of existing providers face recurring problems that experienced practitioners learn to anticipate:
- Unpinned versions: a new major release changes defaults and produces unexpected replacements in the plan.
- Missing lock file: different machines resolve different builds, which makes plans inconsistent.
- Perpetual diffs: the API normalizes a value, such as JSON policy formatting, and the provider reports changes on every plan.
- Eventual consistency: the API accepts a request but the object is not yet readable, causing intermittent errors.
- Provider configuration depending on unknown values: a provider block that uses attributes created in the same apply cannot be configured during planning.
The most reliable defense is to read the provider changelog before upgrading, test upgrades in a non-production workspace and review every planned replacement, because a single changed argument can force Terraform to destroy and recreate a stateful resource.
In everyday language
Terraform is like a universal remote control for computing infrastructure. On its own, it cannot talk to any particular device. A Terraform provider is the translator for one specific system, such as a cloud platform or a DNS service.
Someone writes down what they want, for example two servers and a database. The provider turns that wish into the exact requests the service understands. Adding a new provider is like teaching the remote a new device. That is why one tool can manage many different platforms in the same way.
Seen in the real world
A platform team at a mid-sized retailer runs its web shop on AWS, serves traffic through Cloudflare and sends alerts to a monitoring service. Previously, each system was configured by hand in a separate web console, and changes in one place were often forgotten in another.
The team defines everything in one Terraform repository that declares three providers: hashicorp/aws pinned to ~> 5.0, the Cloudflare provider and the monitoring vendor’s partner provider. An aliased AWS provider handles a second region for backups, and the CI pipeline authenticates through OIDC workload identity instead of stored access keys. The committed lock file guarantees that every run uses identical provider builds.
When a new storefront region launches, an engineer adds a module call and opens a pull request. The plan shows the load balancer, DNS records and alert rules together, reviewers approve it and the apply finishes in about twelve minutes, with no manual console changes across the three platforms.