This project deploys a secure Azure infrastructure consisting of Linux VM Scale Sets, SQL Database, and Key Vault integration with proper networking and security configurations.
The infrastructure includes:
- Virtual Network with custom subnets (app, database, management)
- Linux Virtual Machine Scale Set for high availability
- Azure SQL Server and Database with geo-replication
- Network Security Groups with strict access rules
- Azure Bastion for secure VM access
- Azure Key Vault for secrets management
- Service Endpoints for secure database access
+---------------------------------------------+ | Azure Region | | | | | | +---------------------------------------+ | | | Resource Group (rg-dev) | | | | | | | | +-------------------------------+ | | | | | Virtual Network (vnet-dev) | | | | | | Address Space: | | | | | | | | | | | | +-------------------------+ | | | | | | | Subnet (app-subnet) | | | | | | | | Address Prefix: | | | | | | | | | | | | | | | | | | | | | | | | +---------------------+ | | | | | | | | | Azure SQL Server | | | | | | | | | | (sql-server) | | | | | | | | | +---------------------+ | | | | | | | | | | | | | | | | +---------------------+ | | | | | | | | | VM (app-vm) | | | | | | | | | +---------------------+ | | | | | | | +-------------------------+ | | | | | +-------------------------------+ | | | | | | | | +-------------------------------+ | | | | | Public IP (bastion-dev) | | | | | +-------------------------------+ | | | | | | | | +-------------------------------+ | | | | | Log Analytics Workspace | | | | | | | | | | | +-------------------------------+ | | | +---------------------------------------+ | | | +---------------------------------------------+
- Terraform (v0.12 or later)
- Azure CLI
- SSH key pair for VM access
- Azure subscription with required permissions
# Login to Azure
az login
# Create Service Principal
az ad sp create-for-rbac \
--name "terraform-sp" \
--role "Contributor" \
--scopes "/subscriptions/YOUR_SUBSCRIPTION_ID"
# Create Resource Group
az group create --name "rg-keyvault" --location "swedencentral"
# Create Key Vault
az keyvault create \
--name "kv-terraform-secrets" \
--resource-group "rg-keyvault" \
--location "swedencentral"
# Store Service Principal Secret
az keyvault secret set \
--vault-name "kv-terraform-secrets" \
--name "AZURE-CLIENT-SECRET" \
--value "YOUR_CLIENT_SECRET"
Create a .env
file based on env.example
:
AZURE_SUBSCRIPTION_ID=your-subscription-id
AZURE_TENANT_ID=your-tenant-id
AZURE_CLIENT_ID=your-client-id
AZURE_CLIENT_SECRET=your-client-secret
ENVIRONMENT=dev
REGION=swedencentral
RESOURCE_GROUP_NAME=your-resource-group
-
Clone and Initialize
git clone <repository-url> cd <project-directory> terraform init
-
Configure Variables Create a
terraform.tfvars
file:environment = "dev" location = "swedencentral"
-
Deploy Infrastructure
./terraform.sh plan ./terraform.sh apply
- Linux VM Scale Set
- Ubuntu 18.04 LTS
- Standard_DS2_v2 size
- Auto-scaling enabled
- Zone redundant deployment
- Rolling updates configuration
- Virtual Network with segregated subnets:
- Application subnet
- Database subnet
- Management subnet
- Azure Bastion Host
- Network Security Groups with:
- SSH access via Bastion
- SQL Server access
- Application-specific rules
- Azure SQL Server
- Geo-replication enabled
- Azure AD authentication
- TLS 1.2 enforced
- SQL Database
- Business Critical tier
- Zone redundant
- Automated backups
- Long-term retention
- Azure Key Vault integration
- Service Principal with minimal permissions
- Network Security Groups
- Azure Bastion for secure VM access
- Service Endpoints
- Azure AD integration
# Access VM through Azure Bastion
az network bastion ssh \
--name "bastion-dev" \
--resource-group "your-rg" \
--target-resource-id $(terraform output -raw vmss_id) \
--auth-type ssh-key \
--username adminuser \
--ssh-key ~/.ssh/id_rsa
# Get connection string
terraform output sql_connection_string
# Connect using SQL tools
sqlcmd -S $(terraform output -raw sql_server_fqdn) \
-U $(terraform output -raw sql_admin_username) \
-P $(terraform output -raw sql_admin_password) \
-d $(terraform output -raw database_name)
# Rotate Service Principal secret
az ad sp credential reset \
--name "terraform-sp" \
--append \
--credential-description "terraform-secret-$(date +%Y%m%d)" \
--query password -o tsv | \
az keyvault secret set \
--vault-name "kv-terraform-secrets" \
--name "AZURE-CLIENT-SECRET" \
--value @-
- Update Terraform configurations
- Run plan to review changes:
./terraform.sh plan
- Apply changes:
./terraform.sh apply
- Azure Monitor integration
- Log Analytics workspace
- VM Scale Set metrics
- SQL Server auditing
- Key Vault logging
- Geo-replicated SQL Database
- Zone redundant VM Scale Set
- Automated backups
- Point-in-time recovery
- Resource locks on critical components
- Fork the repository
- Create a feature branch
- Commit changes
- Create a pull request
- Never commit sensitive data
- Use Key Vault for all secrets
- Rotate credentials regularly
- Monitor access logs
- Keep dependencies updated
- Follow least privilege principle
This project is licensed under the MIT License - see the LICENSE file for details.