Terraform Providers
A provider is a plugin that lets Terraform talk to an API. Each cloud or service has its own provider.
A provider block
The source names the provider. The version pins it to a known release.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "6.72.0"
}
}
}The Registry
The Registry is the catalogue of providers. Each entry shows its source address and versions.
# The Registry lists providers by name.
# hashicorp/aws is the AWS provider.
# hashicorp/random creates random values.
# hashicorp/local manages local files.Providers arrive at init
Init downloads each named provider. The files land in the .terraform folder.
terraform initExample
# main.tf
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "2.9.1"
}
random = {
source = "hashicorp/random"
version = "3.9.1"
}
}
}
resource "random_pet" "name" {
length = 2
}
resource "local_file" "pet" {
filename = "pet.txt"
content = "Pet name: ${random_pet.name.id}"
}
# Commands:
# terraform init
# terraform apply
# terraform destroyKey points
- A provider translates Terraform files into calls to a service.
- The Registry is the public list of providers, with their names and versions.
- A provider block names the provider and pins its version.
- Pin a version, so an update cannot change behaviour without warning.
- One configuration can use more than one provider at once.
- Terraform downloads providers during init, from the Registry.
Each provider block names a plugin and its version. The random provider creates a name, and the local provider writes it to a file. Two providers work in one configuration.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What is a Terraform provider?