Format Terraform Provider Configuration

Format and align Terraform provider blocks including AWS, Azure, and GCP configurations with proper indentation, default tags, and authentication settings.

Provider & Backend

Detailed Explanation

Formatting Provider Blocks

Provider blocks are the foundation of every Terraform configuration. They tell Terraform which cloud platform or service to interact with and how to authenticate. Properly formatted provider blocks improve readability and make it easier to spot misconfigurations during code review.

Example HCL

provider "aws" {
  region  = "us-east-1"
  profile = "production"

  default_tags {
    tags = {
      Environment = "production"
      ManagedBy   = "terraform"
      Team        = "platform"
    }
  }

  assume_role {
    role_arn     = "arn:aws:iam::123456789012:role/TerraformRole"
    session_name = "terraform-production"
  }
}

Formatting Rules Applied

  1. Indentation: Each nested block is indented consistently (2 or 4 spaces based on your preference)
  2. Equals alignment: Within each block, the = signs are aligned vertically — region, profile, role_arn, and session_name all have their equals signs at the same column position within their respective blocks
  3. Blank lines: A blank line separates logical groups (simple attributes from nested blocks)
  4. Nested blocks: default_tags and assume_role blocks are properly indented one level deeper

Multiple Provider Aliases

When using provider aliases for multi-region deployments, consistent formatting is even more critical:

provider "aws" {
  alias  = "us_west"
  region = "us-west-2"
}

provider "aws" {
  alias  = "eu_west"
  region = "eu-west-1"
}

The formatter ensures each alias block follows the same structure, making it easy to compare configurations side by side.

Use Case

Setting up multi-cloud or multi-region Terraform configurations where consistent provider formatting helps teams quickly identify which provider and region each resource targets.

Try It — Terraform HCL Formatter

Open full tool