Skip to content

This project automates the deployment and management of Azure Kubernetes Service (AKS) using modular Terraform code and CI/CD pipelines via GitHub Actions, with Azure DevOps as an optional alternative. It supports multiple environments (Dev, Stage), each with its own secure Terraform state in Azure Storage.

Notifications You must be signed in to change notification settings

Peter-Opapa/git-actions_terraform_azure

Repository files navigation

Azure Infrastructure Deployment Platform πŸš€

This project automates the deployment and management of Azure Kubernetes Service (AKS) infrastructure using Terraform, with CI/CD pipelines powered primarily by GitHub Actions and optionally by Azure DevOps. The infrastructure is defined using modular Terraform code and supports multiple environments such as Dev and Stage, each maintaining its own Terraform state file stored securely in Azure Storage. Upon code commits to Git, GitHub Actions are triggered to run Terraform commands (init, plan, and apply) to provision or update resources. Authentication to Azure is handled through a Service Principal registered in Microsoft Entra ID, which is granted the Contributor role at the subscription level, ensuring secure access to create and manage resources. A Resource Group is provisioned to contain AKS clusters and Azure Key Vaults, with the AKS cluster managing secure interactions with the vault. Destructive actions like terraform destroy are restricted from DevOps users to prevent accidental deletions. While GitHub Actions is the primary automation tool, Azure DevOps is also integrated as an alternative pipeline option for infrastructure deployment.

Project Architecture

πŸš€ Quick Start

Get your Azure infrastructure running in minutes with this automated GitHub Actions workflows.

🎯 Zero-Config Deployment

  1. Clone this repository
  2. Configure Azure Service Principal credentials
  3. Add Azure secrets to GitHub (5 secrets)
  4. Push to main branch β†’ Auto-deploy to development! πŸš€

πŸ“– Complete Setup Guide | 🀝 Contributing

✨ Key Features:

  • βœ… Production-ready AKS clusters with best practices
  • βœ… Automated CI/CD with GitHub Actions
  • βœ… Multi-environment support (development/staging/production)
  • βœ… Secure secret management with Azure Key Vault
  • βœ… Infrastructure validation and testing
  • βœ… Automated deployments with rollback capabilities
  • βœ… Safe destroy workflows with confirmation gates
  • βœ… Enterprise-grade project structure and documentation

πŸ—οΈ Architecture Overview

graph TB
    A[GitHub Repository] --> B[GitHub Actions]
    B --> C[Azure Service Principal]
    C --> D[Terraform State Storage]
    C --> E[Development Environment]
    C --> F[Staging Environment]
    C --> G[Production Environment]
    
    E --> H[AKS Cluster]
    E --> I[Key Vault]
    E --> J[Service Principal]
    
    F --> K[AKS Cluster]
    F --> L[Key Vault]
    F --> M[Service Principal]
    
    G --> N[AKS Cluster]
    G --> O[Key Vault]
    G --> P[Service Principal]
Loading

πŸ“ Project Structure

β”œβ”€β”€ πŸ“ .github/workflows/       # πŸ€– GitHub Actions CI/CD workflows
β”‚   β”œβ”€β”€ terraform-deploy.yml     # πŸš€ Main deployment workflow
β”‚   └── terraform-destroy.yml   # πŸ’₯ Infrastructure destruction workflow
β”œβ”€β”€ πŸ“ .vscode/                # πŸ› οΈ VS Code workspace configuration
β”œβ”€β”€ πŸ“ docs/                    # πŸ“š Documentation and diagrams
β”‚   β”œβ”€β”€ architecture.png        # πŸ›οΈ Infrastructure architecture
β”‚   └── infrastructure.md       # πŸ“‹ Infrastructure details
β”œβ”€β”€ πŸ“ infrastructure/          # πŸ—οΈ Main Terraform infrastructure code
β”‚   β”œβ”€β”€ πŸ“ environments/        # 🌍 Environment-specific configurations
β”‚   β”‚   β”œβ”€β”€ πŸ“ development/     # πŸ§ͺ Development environment
β”‚   β”‚   β”œβ”€β”€ πŸ“ staging/         # πŸ”„ Staging environment
β”‚   β”‚   └── πŸ“ production/      # 🏭 Production environment
β”‚   β”œβ”€β”€ πŸ“ modules/             # 🧩 Reusable Terraform modules
β”‚   β”‚   β”œβ”€β”€ πŸ“ aks/             # ☸️ Kubernetes cluster module
β”‚   β”‚   β”œβ”€β”€ πŸ“ keyvault/        # πŸ” Secret management module
β”‚   β”‚   └── πŸ“ ServicePrincipal/# πŸ”‘ Authentication module
β”‚   β”œβ”€β”€ πŸ“ shared/              # 🀝 Shared configurations
β”‚   └── πŸ“„ README.md            # πŸ“– Infrastructure documentation
β”œβ”€β”€ πŸ“ legacy/                  # πŸ“œ Legacy Azure DevOps pipelines
β”œβ”€β”€ πŸ“ scripts/                 # πŸ“œ Setup and utility scripts
β”‚   β”œβ”€β”€ setup-azure-sp.sh       # πŸ”§ Service Principal setup (Bash)
β”‚   └── setup-azure-sp.ps1      # πŸ”§ Service Principal setup (PowerShell)
β”œβ”€β”€ πŸ“„ GITHUB_ACTIONS_SETUP.md  # πŸ“– Complete setup guide
β”œβ”€β”€ πŸ“„ CONTRIBUTING.md          # 🀝 Contribution guidelines
β”œβ”€β”€ πŸ“„ SECURITY.md              # πŸ”’ Security policy
β”œβ”€β”€ πŸ“„ CHANGELOG.md             # πŸ“‹ Version history
└── πŸ“„ README.md                # πŸ“„ This file

πŸ› οΈ Infrastructure Components

My project deploys a complete Azure infrastructure including:

πŸ”§ Core Infrastructure

  • Resource Groups: Organized environment separation
  • Storage Account: Terraform state backend with encryption
  • Service Principals: Secure authentication for applications

☸️ Kubernetes Infrastructure

  • Azure Kubernetes Service (AKS): Managed Kubernetes clusters with best practices
  • Node Pools: Auto-scaling compute resources
  • RBAC Integration: Secure access controls
  • Network Policies: Secure pod-to-pod communication

πŸ” Security & Secrets

  • Azure Key Vault: Centralized secret management
  • Service Principal Authentication: Secure application access
  • Role-Based Access Control: Least privilege principles
  • TLS/SSL Certificates: Automated certificate management

🌍 Multi-Environment Architecture

Environment Resource Group Purpose Auto-Deploy Location
Shared terraform-state-rg Terraform state storage βœ… Always infrastructure/shared/
Development dev-peter-rg Development workloads βœ… On main push infrastructure/environments/development/
Staging stage-peter-rg Pre-production testing πŸ”„ Manual approval infrastructure/environments/staging/
Production prod-peter-rg Production workloads πŸ›‘οΈ Protected branch infrastructure/environments/production/

πŸš€ Getting Started

Prerequisites

  • Azure subscription (Get free account)
  • GitHub account
  • Basic understanding of Terraform and Azure
  • Azure CLI installed (optional, for local development)

1. Clone and Setup

git clone https://github.com/YOUR_USERNAME/gitactions-terraform.git
cd gitactions-terraform

2. Configure Azure Service Principal

# Run the setup script
./scripts/setup-azure-sp.sh
# Or use PowerShell version
./scripts/setup-azure-sp.ps1

3. Add GitHub Secrets

Add these 5 secrets to your GitHub repository settings:

  • AZURE_CLIENT_ID
  • AZURE_CLIENT_SECRET
  • AZURE_SUBSCRIPTION_ID
  • AZURE_TENANT_ID
  • AZURE_BACKEND_STORAGE_ACCOUNT

4. Deploy Infrastructure

# Push to main branch triggers automatic deployment
git add .
git commit -m "feat: initial infrastructure deployment"
git push origin main

πŸ”„ Workflow Operations

Automatic Deployments

  • Development: Auto-deploys on push to main
  • Staging: Manual approval required
  • Production: Protected branch workflow

Manual Operations

  • Plan: Create execution plan for review
  • Apply: Deploy infrastructure changes
  • Destroy: Safely tear down infrastructure

πŸ› οΈ Technical Stack

Infrastructure as Code

  • Terraform v1.5+ - Infrastructure provisioning and management
  • Azure Provider v3.0+ - Azure resource management
  • GitHub Actions - CI/CD automation and workflows

Azure Services

  • Azure Kubernetes Service (AKS) - Container orchestration
  • Azure Key Vault - Secret and certificate management
  • Azure Active Directory - Identity and access management
  • Azure Storage - Terraform state backend
  • Azure Resource Manager - Resource organization and governance

Development Tools

  • VS Code - Development environment with Terraform extensions
  • Azure CLI - Local development and debugging
  • Git - Version control and collaboration

πŸ”§ Module Architecture

Core Modules

πŸ—οΈ AKS Module (infrastructure/modules/aks/)

# Production-ready Kubernetes cluster
- Auto-scaling node pools
- Azure CNI networking
- Azure RBAC integration
- Monitoring and logging
- Security hardening

πŸ” Key Vault Module (infrastructure/modules/keyvault/)

# Centralized secret management
- Certificate management
- Secret rotation policies
- Access policies and RBAC
- Network access restrictions
- Backup and recovery

πŸ”‘ Service Principal Module (infrastructure/modules/ServicePrincipal/)

# Secure authentication
- Application registration
- Role assignments
- Certificate-based auth
- Least privilege access
- Credential rotation

⚑ Quick Deployment Commands

Environment Management

# Deploy to development
terraform -chdir=infrastructure/environments/development plan
terraform -chdir=infrastructure/environments/development apply

# Deploy to staging
terraform -chdir=infrastructure/environments/staging plan
terraform -chdir=infrastructure/environments/staging apply

# Deploy to production (requires approval)
terraform -chdir=infrastructure/environments/production plan
terraform -chdir=infrastructure/environments/production apply

Destroy Resources

# Destroy development environment
terraform -chdir=infrastructure/environments/development destroy

# Use GitHub Actions destroy workflow for production
gh workflow run terraform-destroy.yml -f environment=production

πŸ” Monitoring and Observability

Built-in Monitoring

  • Azure Monitor - Infrastructure and application metrics
  • Log Analytics - Centralized logging and analysis
  • Application Insights - Application performance monitoring
  • Azure Alerts - Proactive issue detection

GitHub Actions Insights

  • Workflow Status - Real-time deployment tracking
  • Resource Drift Detection - Configuration compliance
  • Cost Tracking - Infrastructure cost monitoring
  • Security Scanning - Vulnerability assessments

🚨 Troubleshooting Guide

Common Issues

Issue Solution Documentation
Authentication Failed Check service principal credentials Setup Guide
State Lock Conflicts Release state lock manually State Management
Resource Conflicts Check resource naming conventions Naming Guide
Permission Denied Verify RBAC assignments Security Guide

Support Resources

πŸ† Production Features

Enterprise Grade

  • βœ… High Availability - Multi-zone AKS deployments
  • βœ… Auto Scaling - Horizontal and vertical pod autoscaling
  • βœ… Disaster Recovery - Cross-region backup strategies
  • βœ… Security Hardening - CIS benchmarks and security policies
  • βœ… Compliance Ready - SOC 2, ISO 27001 framework support

DevOps Best Practices

  • βœ… GitOps Workflows - Infrastructure as code versioning
  • βœ… Automated Testing - Infrastructure validation and testing
  • βœ… Rollback Capabilities - Safe deployment rollback mechanisms
  • βœ… Environment Parity - Consistent dev/staging/production environments
  • βœ… Change Management - Structured approval processes

πŸ“Š Cost Optimization

Resource Efficiency

  • Spot Instances - Cost-effective compute for development
  • Auto-shutdown - Automatic resource cleanup
  • Resource Tagging - Detailed cost allocation and tracking
  • Right-sizing - Optimal resource sizing recommendations

Budget Controls

  • Cost Alerts - Proactive spending notifications
  • Resource Quotas - Environment-specific resource limits
  • Policy Enforcement - Automated compliance and governance

πŸ“š Documentation

Essential Guides

Advanced Topics

🀝 Contributing

I welcome contributions! Please see the Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ”— Resources

πŸ™ Acknowledgments

Built with ❀️ by Peter for the DevOps community. This platform demonstrates enterprise-grade infrastructure automation best practices.


Ready to deploy enterprise Azure infrastructure? Start with the GitHub Actions Setup Guide! πŸš€

About

This project automates the deployment and management of Azure Kubernetes Service (AKS) using modular Terraform code and CI/CD pipelines via GitHub Actions, with Azure DevOps as an optional alternative. It supports multiple environments (Dev, Stage), each with its own secure Terraform state in Azure Storage.

Topics

Resources

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published