Skip to content

Mx Infrastructure - Terraform Project

A comprehensive Terraform infrastructure-as-code project for deploying and managing the Marketing (Mx) platform on Microsoft Azure. This project provides multi-environment support with standardized configurations for Dev, QA, UAT, and Production environments.

Overview

The Mx Infrastructure project manages Azure resources for multiple marketing applications including: - AIO - All-in-One Marketing Platform - HFH - Homes for Heroes Platform
- Hub - Central Hub Application - MIP - Marketing Integration Platform - Portal - Marketing Portal Application

Key Features

  • Multi-Environment Support: Dev, QA, UAT, and Production environments
  • Modular Design: Reusable Terraform modules for consistent deployments
  • Azure Integration: Full Azure cloud infrastructure with networking, security, and monitoring
  • Container Support: Azure Container Registry integration for containerized applications
  • Database Management: Elastic SQL pools and databases with configurable performance tiers
  • Security: Key Vault integration, private endpoints, and network security rules
  • Monitoring: Application Insights integration for telemetry and monitoring

Project Structure

mx-infrastructure/
β”œβ”€β”€ πŸ“ environments/                    # Environment-specific configurations
β”‚   β”œβ”€β”€ πŸ“ dev/                        # Development environment
β”‚   β”‚   β”œβ”€β”€ backend.tf                 # Remote state configuration
β”‚   β”‚   β”œβ”€β”€ dev.tf                     # Dev-specific resources
β”‚   β”‚   └── providers.tf               # Provider configurations
β”‚   β”œβ”€β”€ πŸ“ qa/                         # QA environment
β”‚   β”‚   β”œβ”€β”€ backend.tf
β”‚   β”‚   β”œβ”€β”€ qa.tf
β”‚   β”‚   └── providers.tf
β”‚   └── πŸ“ uat/                        # UAT environment
β”‚       β”œβ”€β”€ backend.tf
β”‚       β”œβ”€β”€ uat.tf
β”‚       └── providers.tf
β”‚
β”œβ”€β”€ πŸ“ mx-resources/                    # Core infrastructure module
β”‚   β”œβ”€β”€ app-insights.tf               # Application monitoring
β”‚   β”œβ”€β”€ app-service-plan.tf           # Hosting platform
β”‚   β”œβ”€β”€ virtual-network.tf            # Network infrastructure
β”‚   β”œβ”€β”€ key-vault.tf                  # Secrets management
β”‚   β”œβ”€β”€ elastic-sqlserver.tf          # Database infrastructure
β”‚   └── variables.tf                  # Input variables
β”‚
β”œβ”€β”€ πŸ“ mx-projects/                     # Application-specific modules
β”‚   β”œβ”€β”€ πŸ“ aio/                        # All-in-One platform
β”‚   β”‚   β”œβ”€β”€ linux-app-service.tf      # Containerized app
β”‚   β”‚   β”œβ”€β”€ elastic-sqldb.tf          # Dedicated database
β”‚   β”‚   └── frontdoor.tf              # Global load balancer
β”‚   β”œβ”€β”€ πŸ“ hfh/                        # Homes for Heroes
β”‚   β”œβ”€β”€ πŸ“ hub/                        # Central Hub (includes Functions)
β”‚   β”œβ”€β”€ πŸ“ mip/                        # Marketing Integration Platform
β”‚   └── πŸ“ portal/                     # Marketing Portal
β”‚
└── πŸ“ Documentation
    β”œβ”€β”€ README.md                      # This project guide
    └── ARCHITECTURE.md                # Technical architecture

Module Dependencies

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   environments/ │───▢│   mx-resources/ │───▢│   mx-projects/  β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ dev.tf        β”‚    β”‚ β€’ Core infra    β”‚    β”‚ β€’ Applications  β”‚
β”‚ β€’ qa.tf         β”‚    β”‚ β€’ Networking    β”‚    β”‚ β€’ Databases     β”‚
β”‚ β€’ uat.tf        β”‚    β”‚ β€’ Security      β”‚    β”‚ β€’ Front Doors   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Prerequisites

Required Tools

  • Terraform: ~> 1.9 (1.x.x)
  • Azure CLI: Latest version for authentication
  • Azure DevOps Service Connection: For automated deployments

Required Permissions

  • Contributor access to target Azure subscriptions
  • Access to Azure Container Registry for image pulls
  • Key Vault access for secrets management

Getting Started

1. Authentication

# Login to Azure
az login

# Set the subscription (replace with your subscription ID)
az account set --subscription "your-subscription-id"

2. Initialize Terraform

Navigate to the desired environment directory:

cd environments/dev
terraform init

3. Plan Deployment

terraform plan

4. Apply Configuration

terraform apply

Environment Configuration

Development Environment

  • Network: 10.221.112.0/23
  • Debug Mode: Enabled
  • DNS Servers: ["10.221.7.20", "10.220.8.20"]
  • Hub VNet: Connected to CmgHubDevVnet01

QA Environment

  • Network: Custom address space
  • Debug Mode: Disabled
  • Production-like configuration with reduced capacity

UAT Environment

  • Network: Custom address space
  • Production mirror for user acceptance testing
  • Full security and monitoring enabled

Key Variables

Required Variables

Variable Description Type
environment_name Environment name (Dev/Qa/Uat/Prod) string
webAppEnableDebugMode Enable debug mode for web apps bool
azure_devops_service_connection_id ADO service connection Object ID string
vnet_address_space Virtual network address space string
remote_hub_vnet_id Hub VNet resource ID for peering string
container_registry_id Container registry resource ID string

Optional Variables

Variable Default Description
project_name "Mx" Project/application name
location "westus2" Azure region
appservice_plan_capacity 1 App Service Plan instances
sql_sku_name "StandardPool" SQL database SKU
sql_min_compute_capacity 10 SQL pool min compute
sql_max_compute_capacity 100 SQL pool max compute

Infrastructure Components

Core Resources (mx-resources/)

Core Infrastructure Components:

Component Purpose Configuration
πŸ—οΈ Resource Groups Logical organization Environment-specific grouping
🌐 Virtual Network Network isolation 10.221.112.0/23 address space
πŸ–₯️ App Service Plan Compute platform Linux containers, auto-scaling
πŸ” Key Vault Secrets management Private endpoint, RBAC policies
πŸ“Š Application Insights Monitoring Telemetry and performance tracking
πŸ—„οΈ SQL Server Database platform Private endpoint, audit policies
πŸ“ˆ Elastic Pool Shared DB resources Standard tier, DTU-based scaling

Security & Networking Layer:

    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                     Virtual Network                         β”‚
    β”‚                   (10.221.112.0/23)                       β”‚
    β”‚                                                            β”‚
    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
    β”‚  β”‚ App Service  β”‚  β”‚   Database   β”‚  β”‚  Management  β”‚    β”‚
    β”‚  β”‚    Subnet    β”‚  β”‚    Subnet    β”‚  β”‚    Subnet    β”‚    β”‚
    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
    β”‚                                                            β”‚
    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
    β”‚  β”‚            Network Security Groups                  β”‚  β”‚
    β”‚  β”‚            Private Endpoints                        β”‚  β”‚
    β”‚  β”‚            DNS Integration                          β”‚  β”‚
    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
                              Hub VNet Peering
                                    β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                       Hub Network                           β”‚
    β”‚                 DNS: 10.221.7.20, 10.220.8.20            β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Application Modules (mx-projects/)

Application Architecture:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        APPLICATION LAYER                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚     AIO     β”‚     HFH     β”‚     Hub     β”‚     MIP     β”‚   Portal    β”‚
β”‚  Platform   β”‚   Homes     β”‚   Central   β”‚ Integration β”‚  Marketing  β”‚
β”‚             β”‚ for Heroes  β”‚     Hub     β”‚  Platform   β”‚   Portal    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚             β”‚             β”‚             β”‚             β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚             β”‚             β”‚
                     β–Ό             β–Ό             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       SHARED SERVICES                               β”‚
β”‚                                                                     β”‚
β”‚  🌍 Azure Front Door    🐳 Container Registry    πŸ” Key Vault      β”‚
β”‚  πŸ—„οΈ SQL Server         πŸ“Š Application Insights  πŸ”’ Private Endpointsβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Per-Application Components:

Application App Service Functions Database Front Door Secrets
AIO βœ… Linux Container ❌ βœ… Dedicated DB βœ… Global LB βœ… App-specific
HFH βœ… Linux Container ❌ βœ… Dedicated DB βœ… Global LB βœ… App-specific
Hub βœ… Linux Container βœ… Event Processing βœ… Dedicated DB βœ… Global LB βœ… App-specific
MIP βœ… Linux Container ❌ βœ… Dedicated DB βœ… Global LB βœ… App-specific
Portal βœ… Linux Container ❌ βœ… Dedicated DB βœ… Global LB βœ… App-specific

Security Features

Network Security

  • Private endpoints for PaaS services
  • Network security groups with restrictive rules
  • VNet peering with centralized hub
  • DNS resolution through private zones

Identity and Access

  • Service connection-based authentication
  • Key Vault access policies
  • Role-based access control (RBAC)
  • Managed identities for applications

Data Protection

  • SQL audit policies with retention
  • Encrypted storage and transmission
  • Backup and disaster recovery
  • Compliance with security standards

Monitoring and Observability

Application Insights

  • Performance monitoring
  • Error tracking and diagnostics
  • Custom telemetry and metrics
  • Alerting and notifications

SQL Monitoring

  • Database performance insights
  • Query performance tracking
  • Audit log retention (30-730 days)
  • Automated backup management

Deployment Pipeline

Azure DevOps Integration

CI/CD Pipeline Workflow:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ πŸ“ Source   │───▢│ πŸ”§ Build    │───▢│ βœ… Test     │───▢│ πŸš€ Deploy   β”‚
β”‚ Control     β”‚    β”‚ Pipeline    β”‚    β”‚ Validation  β”‚    β”‚ Pipeline    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                   β”‚                   β”‚                   β”‚
   Feature Branch    Terraform Init    Terraform Plan    Terraform Apply
   Pull Request      Terraform Validate    Security Scan     Environment Deploy
   Code Review       Lint & Format     Integration Tests    State Management

Environment Promotion Flow:

    Development               QA               UAT              Production
        β”‚                     β”‚                β”‚                    β”‚
        β–Ό                     β–Ό                β–Ό                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸ”§ DEV      │───▢│  πŸ§ͺ QA       │───▢│  πŸ‘₯ UAT      │───▢│  🏭 PROD     β”‚
β”‚              β”‚    β”‚              β”‚    β”‚              β”‚    β”‚              β”‚
β”‚ β€’ Auto       β”‚    β”‚ β€’ Auto       β”‚    β”‚ β€’ Manual     β”‚    β”‚ β€’ Manual     β”‚
β”‚ β€’ Fast Fail  β”‚    β”‚ β€’ Testing    β”‚    β”‚ β€’ Approval   β”‚    β”‚ β€’ Approval   β”‚
β”‚ β€’ Debug      β”‚    β”‚ β€’ Validation β”‚    β”‚ β€’ Full Scale β”‚    β”‚ β€’ Monitoring β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

State Management:

Component Configuration Purpose
πŸ—„οΈ Remote Backend Azure Storage Account Centralized state storage
πŸ”’ State Locking Azure Blob Lease Prevent concurrent modifications
πŸ’Ύ State Backup Versioned blobs Recovery and rollback capability
πŸ” Encryption Azure encryption at rest State file security

Best Practices

  • State file security and locking
  • Plan review before apply
  • Environment promotion workflow
  • Rollback capabilities

Troubleshooting

Common Issues

  1. Authentication Errors
  2. Verify Azure CLI login
  3. Check service connection permissions
  4. Validate subscription access

  5. Network Connectivity

  6. Verify VNet peering configuration
  7. Check DNS server settings
  8. Validate network security rules

  9. Resource Conflicts

  10. Check for naming conflicts
  11. Verify resource availability in region
  12. Review quota limits

Useful Commands

# Check Terraform state
terraform state list

# Import existing resources
terraform import azurerm_resource_group.example /subscriptions/.../resourceGroups/example

# Refresh state
terraform refresh

# Target specific resources
terraform apply -target=module.example

Contributing

Development Workflow

  1. Create feature branch from master
  2. Make changes in appropriate environment
  3. Test in development environment
  4. Submit pull request with detailed description
  5. Deploy to QA/UAT for validation
  6. Promote to production

Code Standards

  • Use consistent naming conventions
  • Document all variables and outputs
  • Include validation rules where applicable
  • Follow Terraform best practices
  • Maintain backward compatibility

Support

For questions or issues: - Technical Issues: Create issue in repository - Access Requests: Contact Azure administrators - Feature Requests: Submit through standard change process

License

This project is proprietary to CMG Financial Services and is not licensed for external use.