ποΈ Terraform Azure Modular Infrastructure (with for_each), Multi Environment, Used Two Different Subscriptions,one for INIT and another one for Plan & Apply
A production-ready Infrastructure as Code (IaC) project using Terraform to deploy a complete modular Azure environment.
Built with for_each to dynamically create resources like Resource Groups, VNets, NSGs, NICs, VMs, Bastion, SQL Server, Databases, and Load Balancers.
Perfect for DevOps learners and cloud engineers who want to master modular Terraform + Azure.
Depending on how you want to run Terraform, pick one of the two options:
- Write and run Terraform from your laptop.
- Push state to Azure Storage backend.
π Go to: π Local Setup
- Automate provisioning using Azure DevOps Pipelines or GitHub Actions.
- Store state securely in Azure Blob Storage.
π Go to: π CI/CD Setup
infra/
βββ main.tf # Root module - calls all child modules
βββ variables.tf # Input variable definitions
βββ terraform.tfvars # Values for input variables
βββ provider.tf # Provider + remote backend config
βββ output.tf # Exported outputs
βββ modules/ # Child modules for infra components
βββ resourceGroup/
β βββ azurerm_resource_group
βββ networking/
β βββ azurerm_virtual_network
β βββ azurerm_nsg
β βββ azurerm_nic
β βββ azurerm_pip
β βββ azurerm_bastion
β βββ azurerm_nic_nsg_assoc
βββ virtual_machine/
βββ database/
β βββ azurerm_mssql_server
β βββ azurerm_mssql_database
β βββ azurerm_mssql_firewall_rule
βββ loadBalancer/
βββ azurerm_lb
βββ azurerm_backend_address_pool
βββ azurerm_lb_probe
βββ azurerm_lb_rule
βββ azurerm_nic_bp_association
git clone https://github.com/<your-username>/terraform-azure-modular-infra.git
cd terraform-azure-modular-infra/infra
terraform init
terraform validate terraform plan
terraform apply -auto-approve
terraform destroy -auto-approve
Store backend credentials (Storage Account, Container, Key) in Azure DevOps/GitHub Secrets.
Create pipeline with Terraform tasks:
- init
- validate
- plan
- apply
Approve deployments for prod environments.
Do not push terraform.tfvars with passwords to GitHub.
*.tfstate
*.tfstate.*
.terraform/
*.lock.hcl
terraform.tfvars
- Resource Group names & IDs
- Virtual Network & Subnet IDs
- NIC IDs & IPs
- Load Balancer Probe IDs
- SQL Database IDs
This project is licensed under the MIT License. Free to use with attribution.
Ritesh Sharma
π LinkedIn