Services

Resources

Company

/

Terraform provider

Terraform provider

A Terraform provider is the plugin that lets Terraform talk to one API. Terraform core parses your infrastructure as code, builds the dependency graph and keeps state. It knows nothing about EC2 or DNS records. The AWS provider defines resource types such as aws_instance and turns each create, update or delete into AWS API calls.

How it works

Each provider ships as its own binary. You declare which ones you need and which versions you accept:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

terraform init downloads a matching build and records its exact version and checksums in .terraform.lock.hcl. The constraint ~> 5.0 accepts any 5.x release and refuses 6.0.

At plan time Terraform starts the provider as a child process and talks to it over gRPC. Core asks for the provider's schema, then calls it to plan and apply each resource. Vendors can therefore write and release providers on their own schedule.

Say a team writes version = ">= 5.0" and keeps .terraform.lock.hcl out of Git. Laptops installed 5.x months ago. When 6.0 ships, the CI runner's fresh init pulls it, and the plan shows changes on code nobody touched.

The fix is two lines of work. Tighten the constraint to ~> 5.0 and commit the lock file. Upgrades then happen on purpose, with terraform init -upgrade on a branch and a reviewed plan.

One configuration can also use a provider twice. A second provider "aws" block with alias = "us_east_1" and region = "us-east-1" lets a resource set provider = aws.us_east_1. Teams use this for a CloudFront certificate, which must live in us-east-1, while everything else stays in ap-south-1.

Why it matters in production

A new provider version can change a default and show a diff that is easy to mistake for configuration drift. Credentials are the provider's job too: the AWS provider reads them at runtime from environment variables or ~/.aws/credentials, and Terraform never writes them to state. Set TF_LOG=DEBUG when a provider misbehaves, and the log shows the plugin handshake and every API request.

See also

On the One2N blog

References

  1. Terraform: Provider requirements

  2. Terraform: Dependency lock file

Layer stack of a Terraform provider: your .tf code goes to Terraform core (graph, state), then over gRPC to the AWS provider, which makes API calls to the AWS API. Beside the provider is a version line from 5.0 through 5.x to 6.0. A green bracket for ~> 5.0 stops before 6.0. A red arrow for >= 5.0 runs past it: CI pulls 6.0, a diff on code nobody touched. Committing .terraform.lock.hcl pins the exact version.