Last updated
Last updated
Terraform is HashiCorp's Infrastructure as Code (IaC) tool that enables you to safely and predictably create, change, and improve infrastructure across multiple cloud providers and services. This guide covers modern Terraform practices as of 2025, including the latest features and best practices.
For WSL2, you can either use the Linux distribution's package manager as above, or install via the official package:
Add Terraform to your system configuration (configuration.nix
):
Or for a project-specific environment using shell.nix
:
Native Support for Multi-Cloud Deployments
Unified workflow across AWS, Azure, GCP, and other providers
Cross-cloud resource dependencies
Cloud-agnostic modules
Enhanced State Management
Improved state locking mechanisms
Built-in state encryption
Advanced state migration tools
Testing and Validation
Built-in testing framework
Policy as code integration
Automated validation pipelines
Security Features
Native secrets management
IAM role assumption
Provider authentication improvements
Use remote state storage (AWS S3, Azure Storage, GCP Cloud Storage)
Implement state locking
Separate state files per environment
Enable state encryption
Example backend configuration for Azure:
Use workspaces for environment separation
Implement consistent naming conventions
Maintain modular code structure
Use provider authentication with OIDC
Implement least privilege access
Enable audit logging
Use sensitive input variables
Use for_each
instead of count
where possible
Implement parallel resource creation
Use data sources efficiently
Implement cost estimation in CI/CD
Use cost allocation tags
Enable cost reports and budgets
GitHub Actions workflow example:
Using OPA (Open Policy Agent) for policy enforcement:
Using Terratest for infrastructure testing:
- Core concepts powering Terraform-based automation
- Practical implementation patterns for AWS resources
- Azure-specific deployment strategies with Terraform
- Google Cloud automation with Terraform
- Ensuring infrastructure reliability with automated tests
- Automating Terraform deployments in pipelines
- Production-ready implementation strategies
- Alternative IaC approach for Azure-specific workloads
- Git-based infrastructure delivery that works with Terraform
Setting up and using terraform for Azure Deployments