Format Terraform Provider Configuration
Format and align Terraform provider blocks including AWS, Azure, and GCP configurations with proper indentation, default tags, and authentication settings.
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
- Indentation: Each nested block is indented consistently (2 or 4 spaces based on your preference)
- Equals alignment: Within each block, the
=signs are aligned vertically —region,profile,role_arn, andsession_nameall have their equals signs at the same column position within their respective blocks - Blank lines: A blank line separates logical groups (simple attributes from nested blocks)
- Nested blocks:
default_tagsandassume_roleblocks 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.