Terraform Tutorial — The required_providers Block

1 minute read

The required_providers block tells Terraform which providers your configuration needs, where to download them, and which versions are acceptable.


Basic Syntax

The required_providers block lives inside the terraform {} block:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}
Attribute Purpose
aws The local name for this provider (used in provider "aws" {})
source Where to download it — <namespace>/<type> on the Terraform Registry
version Version constraint (which versions are acceptable)

The Source Address

The source attribute follows the format <hostname>/<namespace>/<type>:

  • hostname: Usually registry.terraform.io (implied if omitted)
  • namespace: The organization that publishes the provider
  • type: The provider name
# Full form
source = "registry.terraform.io/hashicorp/aws"

# Short form (registry.terraform.io is implied)
source = "hashicorp/aws"

Common Sources

Source Provider
hashicorp/aws Official AWS provider
hashicorp/azurerm Official Azure provider
hashicorp/google Official GCP provider
hashicorp/kubernetes Official Kubernetes provider
integrations/github GitHub provider (community-maintained)
cloudflare/cloudflare Cloudflare provider

Multiple Providers

Most projects use more than one provider:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
    random = {
      source  = "hashicorp/random"
      version = "~> 3.0"
    }
    tls = {
      source  = "hashicorp/tls"
      version = "~> 4.0"
    }
  }

  required_version = ">= 1.7.0"
}

The random provider generates random values (useful for unique names), and the tls provider creates TLS keys and certificates.


required_version

While not part of required_providers, it belongs in the same terraform {} block:

terraform {
  required_version = ">= 1.7.0, < 2.0.0"
}

This ensures everyone on the team uses a compatible Terraform CLI version.


What’s Next?

You’ve declared your providers. Next, let’s dive deeper into version constraints — the ~>, >=, and exact version operators.


← What is a Provider? Provider Versioning →