Format Required Providers Block

Format the required_providers block with multiple provider sources, version constraints, and proper alignment for team-wide Terraform version management.

Provider & Backend

Detailed Explanation

Formatting Required Providers

The required_providers block inside the terraform block declares which providers your configuration depends on and what versions are acceptable. As projects grow to use multiple providers, consistent formatting becomes essential.

Multi-Provider Example

terraform {
  required_version = ">= 1.5.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 3.0, < 4.0"
    }
    kubernetes = {
      source  = "hashicorp/kubernetes"
      version = "~> 2.23"
    }
    helm = {
      source  = "hashicorp/helm"
      version = "~> 2.11"
    }
    datadog = {
      source  = "DataDog/datadog"
      version = "~> 3.30"
    }
  }
}

Formatting Benefits

Each provider entry follows the same two-line pattern with aligned source and version attributes. This makes it easy to:

  1. Spot missing version constraints — unversioned providers can cause unexpected upgrades
  2. Compare versions across environments — aligned formatting reveals differences at a glance
  3. Add new providers — the pattern is clear and consistent

Version Constraint Formats

Constraint Meaning
~> 5.0 Any 5.x version (>= 5.0, < 6.0)
>= 3.0, < 4.0 Explicit range
= 2.23.1 Exact version pin
!= 3.5.0 Exclude a specific version

The formatter preserves these constraint strings exactly as written while aligning the surrounding structure.

Use Case

Managing provider dependencies in large Terraform projects with multiple cloud providers, ensuring all team members use compatible provider versions.

Try It — Terraform HCL Formatter

Open full tool