Skip to content

ShrutiCloudDevOpsNinja/lb-tf-gha-two-diff-subscriptions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—οΈ 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.


πŸ”§ Choose Your Setup Path

Depending on how you want to run Terraform, pick one of the two options:

πŸ–₯️ Option A: Local Machine (Developer Laptop/PC)

  • Write and run Terraform from your laptop.
  • Push state to Azure Storage backend.

πŸ‘‰ Go to: πŸ“‚ Local Setup


☁️ Option B: Azure DevOps / CI/CD Pipeline

  • Automate provisioning using Azure DevOps Pipelines or GitHub Actions.
  • Store state securely in Azure Blob Storage.

πŸ‘‰ Go to: πŸš€ CI/CD Setup


πŸ“‚ Project Structure

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

βš™οΈ Prerequisites

  • βœ… Terraform v1.6+
  • βœ… Azure CLI (az login)
  • βœ… Azure Storage Account + Container for remote state

Local Setup

Step 1: Clone Repo

git clone https://github.com/<your-username>/terraform-azure-modular-infra.git
cd terraform-azure-modular-infra/infra

Step 2: Initialize Terraform

terraform init

Step 3: Validate & Plan

terraform validate terraform plan

Step 4: Apply Infrastructure

terraform apply -auto-approve

Step 5: Destroy When Not Needed

terraform destroy -auto-approve

CI/CD Setup

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.


πŸ” Security Notes

Do not push terraform.tfvars with passwords to GitHub.

.gitignore

Local Terraform files

*.tfstate

*.tfstate.*

Terraform working directory

.terraform/

Lock files

*.lock.hcl

Sensitive variable files

terraform.tfvars


πŸ“€ Outputs

  • Resource Group names & IDs
  • Virtual Network & Subnet IDs
  • NIC IDs & IPs
  • Load Balancer Probe IDs
  • SQL Database IDs

πŸ“ƒ License

This project is licensed under the MIT License. Free to use with attribution.


πŸ‘¨β€πŸ’» Author

Ritesh Sharma
πŸ”— LinkedIn

About

πŸ—οΈ Terraform Code For Loadbalancer - Azure Modular Infrastructure with for_each, Multi Environment, Used Two Different Subscriptions, One for INIT and Another One For PLAN & APPLY

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages