Last reviewed: September 2026
Terraform providers are plugins that translate Terraform configuration into API operations for cloud platforms, SaaS products, Kubernetes clusters and other services. A provider defines the resource types and data sources available to a configuration.
Provider, resource and data source
| Concept | Purpose |
|---|---|
| Provider | Connects Terraform to a platform API and defines available types |
| Resource | Creates or manages an infrastructure object |
| Data source | Reads information that already exists |
| Provider configuration | Sets region, endpoint, alias or other connection behavior |
Declare required providers
Declare every provider in the terraform block with its registry source address and a reviewed version constraint. Commit the dependency lock file so team and automation runs select consistent provider builds.
terraform {
required_version = ">= 1.8.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}Treat the example version constraints as a pattern, not a permanent recommendation. Check the provider release notes and compatibility requirements before choosing versions for a real environment.
Configure the AWS provider
provider "aws" {
region = "ap-south-1"
}
resource "aws_s3_bucket" "logs" {
bucket = "example-application-logs"
}Configure the Azure provider
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = "example-platform-rg"
location = "Central India"
}Configure the Google Cloud provider
provider "google" {
project = "example-project-id"
region = "asia-south1"
}Configure the Kubernetes provider
provider "kubernetes" {
config_path = "~/.kube/config"
}Configure the GitLab provider
provider "gitlab" {
base_url = "https://gitlab.example.com/api/v4/"
}Initialize providers
Run initialization after adding or changing provider requirements. Terraform downloads acceptable provider builds, verifies packages and updates the dependency lock file when necessary.
terraform init
terraform providers
terraform validateUse provider aliases
Aliases allow one configuration to use multiple regions, accounts, subscriptions or endpoints for the same provider. Pass the required alias explicitly to resources and modules.
provider "aws" {
alias = "primary"
region = "ap-south-1"
}
provider "aws" {
alias = "recovery"
region = "ap-southeast-1"
}
resource "aws_s3_bucket" "recovery" {
provider = aws.recovery
bucket = "example-recovery-bucket"
}Authenticate providers securely
- Prefer workload identity, instance roles, managed identities or short-lived federation over static credentials.
- Use environment variables or the platform's standard credential chain when required.
- Store CI/CD secrets in the automation platform's protected secret store.
- Never place access keys, client secrets, private keys or service-account JSON directly in Terraform files.
- Separate credentials and permissions by environment and workload.
- Grant only the API permissions required by the managed resources.
Manage provider versions
- Use explicit source addresses from the Terraform Registry.
- Set compatible version constraints after testing.
- Commit .terraform.lock.hcl to version control.
- Review release notes before upgrades.
- Run initialization with controlled upgrade behavior in a branch.
- Validate plans in non-production environments before promotion.
Providers inside modules
Reusable modules should declare provider requirements but generally receive configured providers from the calling module. Avoid embedding environment-specific credentials or assumptions inside reusable modules.
Common mistakes
- Omitting a provider source or version constraint.
- Ignoring the dependency lock file.
- Hardcoding credentials in configuration or state-adjacent files.
- Using a default provider accidentally when an alias was intended.
- Forgetting initialization after changing provider requirements.
- Upgrading providers without reviewing the execution plan and release notes.
- Confusing a data source that reads an object with a resource that manages it.
Troubleshooting
- Provider not found: verify the registry source address and network access.
- Configuration not present: confirm the required alias is passed to the module or resource.
- Authentication failed: inspect the active identity and credential chain without printing secrets.
- Unsupported argument: compare the configuration with documentation for the selected provider version.
- Checksum or lock mismatch: investigate the lock file and installation source before changing trust settings.
- Unexpected changes: confirm provider versions, aliases, defaults and imported state.
Official references
Join the discussion
0 CommentsAsk questions, add context, or share what worked.
More from Melochip Editorial
Learn what Playwright testing is, why modern QA teams use it, how testers can get started, and the major types...
7 min read · Sep 19, 2026
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Sep 17, 2026
Learn Kubernetes security best practices with RBAC, Secrets, ServiceAccounts, Pod securityContext, NetworkPoli...
6 min read · Sep 17, 2026Related articles
Learn Kubernetes monitoring and logs with kubectl logs, events, metrics-server, top commands, Prometheus, Graf...
5 min read · Sep 17, 2026
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Sep 17, 2026
Learn Kubernetes Ingress with controllers, IngressClass, host and path routing, TLS, DNS, annotations, redirec...
8 min read · Sep 17, 2026
Learn Kubernetes ConfigMaps and Secrets with YAML, environment variables, file mounts, update behavior, immuta...
8 min read · Sep 17, 2026Stay in the loop. Get new Melochip articles
Receive Melochip article updates when new articles are available. Explicit opt-in only.
No comments yet. Start the discussion.