Code Structure
.
βββ azure-pipelines.yml # Azure DevOps CI/CD pipeline
βββ main
β βββ main.tf # Module orchestration
β βββ provider.tf # Azure provider configuration
β βββ terraform.tfvars # Input variable values
β βββ variable.tf # Module variables
βββ modules
β βββ 01_resource_group # Resource Group creation
β βββ 02_storage_account # Storage Accounts
β βββ 03_storage_container # Storage Containers
β βββ 04-Public_IP # Public IP
β βββ 05_Virtual_Net # VNet & Subnets
β βββ 06_sql_server # Azure SQL Server
β βββ 07_sql_database # Azure SQL Database
β βββ 08_net_interface # Network Interfaces
β βββ 09_Virtual_Machine # Azure VM
βββ README.md
3-Tier Terraform Infra + Azure Pipeline Architecture Diagram
Git Repository URL:
https://github.com/deepak83s143/3-Tier-Application-Infra-with-SAST-Scanning-Azure-Pipeline.git
Features
- Modular Terraform structure
- Incremental resource creation
- Environment-based scalability
- Azure backend remote state configuration
- DevSecOps validation:
- Terraform Validation (terraform validate)
- tfsec security scan
- tflint linting
- Manual approval stage before provisioning
Technologies
- Terraform β IaC provisioning
- AzureRM Provider
- Azure DevOps Pipeline
- tfsec β Static security scan
- tflint β Terraform linting and provider validation
Terraform Workflow (Modules)
The root main/main.tf orchestrates creation in dependency order:
- Resource Group
- Storage Account
- Storage Container
- Public IP
- Virtual Network & Subnets
- SQL Server
- SQL Database
- Network Interface
- Virtual Machine
Each module accepts input variables and returns useful outputs such as IDs, names, and connection objects.
Remote State Backend
Azure backend ensures centralized state storage.
backendAzureRmResourceGroupName: "ResourceGroupName"
backendAzureRmStorageAccountName: "StorageAccountName
backendAzureRmContainerName: "StorageContainerName"
backendAzureRmKey: "KeyName"
Azure DevOps Pipeline Overview
-
Pipeline stages:
- Integration
- Terraform init
- Terraform validate
-
SanityCheck
- tfsec security scan
- tflint recursive lint
-
CodePlanning
- terraform plan
-
ManualValidation
- Manual approval by reviewer
-
InfraCreation
- terraform apply (auto approve)
SAST Tools
tfsec
- Performs static vulnerability scanning
- Detects insecure Terraform configurations
- Ensures cloud compliance
Used with:
task: tfsec@1
dir: $(System.DefaultWorkingDirectory)/main
version: v1.26.0
tflint
- Validates wrong resource types, regions, and deprecated resources
- Provider-specific rule sets
Run manually:
tflint --recursive
Variables & tfvars
User inputs are stored in:
main/variable.tf
main/terraform.tfvars
Examples include:
- Resource Group configuration
- Storage details
- VNet CIDR blocks and subnet ranges
- SQL server credentials
- VM sizing and OS details
Note! :- Never commit sensitive credentials to Git.
Best Practices
- Follow module boundaries strictly
- No direct resource creation in main.tf
- Use tfsec & tflint before merge
- Always review plan outputs
- Store secrets in:
- Azure KeyVault
- DevOps Library secure variables
Notes
- Designed for IaC repeatability
- Suitable for multi-environment deployments (dev/stg/prod)
- Scalable due to isolated Terraform modules
π Follow me on

Top comments (0)