This project involves infrastructure provisioning using Terraform and application deployment with Helm on Azure Kubernetes Service (AKS). The project is structured to separate the management of infrastructure and application deployment, with clear environment-specific configurations for dev and prod environments.
This directory contains the CI/CD pipeline configuration files for both infrastructure and application deployment.
- deploy-infra-cicd.yml: Manages the infrastructure provisioning workflow, including the deployment of AKS, ACR, networking, and storage resources.
- deploy-app-cicd.yml: Handles the application deployment workflow using Helm, ensuring the web app is properly deployed to AKS.
This directory holds the Terraform modules for deploying specific infrastructure components.
- acr/: Deploys Azure Container Registry (ACR) to store Docker images.
- aks/: Deploys Azure Kubernetes Service (AKS) for running the containerized web app.
- networking/: Configures Virtual Networks (VNets) and related networking resources.
- storage/: Provisions Azure Storage resources for application data or other infrastructure needs.
Contains the main Terraform configuration files that define and manage the infrastructure deployment process.
- main.tf: The entry point for Terraform, which ties together the modules and manages resource dependencies.
- variables.tf: Defines variables that are used across the Terraform configuration for flexibility and reusability.
- outputs.tf: Specifies the output variables, such as the AKS cluster name or public IP, that are available after the infrastructure is provisioned.
- dev.tfvars and prod.tfvars: Environment-specific variable files for dev and prod, ensuring that different configurations can be applied depending on the environment.
This directory holds the Helm chart for deploying the web application to AKS.
- app-chart/: Helm chart directory containing Kubernetes manifest templates for the web application deployment.
- Chart.yaml: The metadata file that defines the Helm chart's version, name, and dependencies.
- dev-values.yaml: Values file containing configurations specific to the dev environment.
- prod-values.yaml: Values file containing configurations specific to the prod environment.
This directory contains the application's source code and associated resources.
- app.py: The main Python file that contains the web application code.
- Dockerfile: Defines the instructions to build the Docker image for the web application.
- data_export.sh: A shell script used for exporting data.
- requirements.txt: Lists the Python dependencies required by the web application.
- Azure Account: You need an active Azure account to provision resources like AKS and ACR.
- Terraform: Install Terraform to manage infrastructure.
- Helm: Install Helm to deploy the web app.
- Azure CLI: Install Azure CLI to interact with Azure services.
- Clone this repository.
- Navigate to the
deployment
directory. - Run Terraform commands:
terraform init terraform plan -var-file=dev.tfvars terraform apply -var-file=dev.tfvars
- This will provision AKS, ACR, and other necessary infrastructure resources.
- After the infrastructure is set up, navigate to the
src
folder to build and push the Docker image:docker build -t <acr_registry_name>.azurecr.io/data-upload-app:latest . docker push <acr_registry_name>.azurecr.io/data-upload-app:latest
- Navigate to the
app-chart
directory. - Use Helm to deploy the application:
helm upgrade --install data-upload-app ./app-chart --values ./app-chart/dev-values.yaml
The project includes two CI/CD pipelines:
- Infrastructure CI/CD (deploy-infra-cicd.yml): This pipeline automates the provisioning of infrastructure using Terraform.
- Application CI/CD (deploy-app-cicd.yml): This pipeline automates the build, push, and deployment of the web application using Docker and Helm.
- Development: Use
dev.tfvars
anddev-values.yaml
for dev environment deployment. - Production: Use
prod.tfvars
andprod-values.yaml
for prod environment deployment.
The idea of this structure is to support a clear separation between infrastructure provisioning and application deployment using Terraform, Helm, Docker, and AKS. The GitHub Actions workflows automate both infrastructure and application deployments, with the reusable actions (such as k8s-setup-action) simplifying Kubernetes management tasks.
DEVOPS-TERRAFORM-SAMPLE/ │ ├── .github/ │ └── actions/ │ ├── terraform-action/ │ ├── docker-action/ │ └── k8s-setup-action/ │ └── workflows/ │ ├── deploy-infra-cicd.yml │ └── deploy-app-cicd.yml │ ├── azure-platform/ │ ├── deployment/ │ └── modules/ ├── data-upload-app/ │ ├── deployment/ │ └── modules/ ├── helper/ │ └── scripts/ ├── .gitignore └── README.md
azure-aks-terraform-github-actions/ │ ├── .github/ │ └── actions/ │ ├── terraform-action/ # Composite action to run Terraform commands │ ├── docker-action/ # Composite action to build and push Docker images │ └── k8s-setup-action/ # Composite action to set up Kubernetes (AKS) │ └── workflows/ │ ├── deploy-infra-cicd.yml # GitHub Actions workflow for infrastructure deployment │ └── deploy-app-cicd.yml # GitHub Actions workflow for application deployment │ ├── azure-platform/ │ ├── deployment/ │ │ ├── .terraform/ # Terraform-related files and configurations │ │ ├── data.tf # Data source definitions │ │ ├── dev.tfvars # Environment-specific variables for dev │ │ ├── locals.tf # Local variables used in Terraform │ │ ├── main.tf # Main infrastructure configuration (AKS, Networking, etc.) │ │ ├── outputs.tf # Output values from Terraform (e.g., AKS name, resource group) │ │ ├── prod.tfvars # Environment-specific variables for prod │ │ ├── providers.tf # Provider configuration for Azure (azurerm) │ │ ├── versions.tf # Terraform version and provider version constraints │ └── modules/ │ ├── acr/ │ │ ├── locals.tf # Local variables for ACR │ │ ├── main.tf # ACR module configuration │ │ ├── outputs.tf # Outputs related to ACR │ │ ├── variables.tf # Variables for ACR module │ ├── aks/ │ │ ├── locals.tf # Local variables for AKS │ │ ├── main.tf # AKS module configuration │ │ ├── outputs.tf # Outputs related to AKS │ │ ├── variables.tf # Variables for AKS module │ ├── networking/ │ │ ├── locals.tf # Local variables for Networking │ │ ├── main.tf # Networking configuration (VNet, subnets, etc.) │ │ ├── outputs.tf # Outputs related to Networking │ │ └── variables.tf # Variables for Networking │ └── storage/ │ ├── locals.tf # Local variables for Storage │ ├── main.tf # Azure Blob Storage and Terraform backend configuration │ └── variables.tf # Variables for Storage │ ├── data-upload-app/ │ ├── deployment/ │ │ ├── .terraform/ # Terraform files for the application deployment │ │ ├── dev.tfvars # Environment-specific variables for dev │ │ ├── main.tf # Helm chart deployment using Terraform │ │ ├── outputs.tf # Outputs related to app deployment │ │ ├── prod.tfvars # Environment-specific variables for prod │ │ ├── providers.tf # Providers for the app deployment │ │ ├── variables.tf # Variables for the app deployment │ └── modules/ │ ├── app-chart/ │ │ ├── templates/ # Helm chart templates (deployment, service, ingress, etc.) │ │ ├── Chart.yaml # Helm chart configuration │ │ ├── dev-values.yaml # Helm values for dev environment │ │ ├── prod-values.yaml # Helm values for prod environment │ └── src/ │ ├── Dockerfile # Dockerfile for building the web application image │ ├── app.py # Main application code (Python, Flask or similar) │ ├── requirements.txt # Python dependencies │ ├── helper/ │ └── scripts/ │ ├── 0_local_env_setup.sh # Script for setting up local development environment (git ignored) │ ├── 1_run_terraform.sh # Script to run Terraform commands │ ├── 2_set_aks-cluster-config.sh # Script to configure AKS cluster │ ├── 3_deploy_image_acr.sh # Script to deploy Docker images to ACR │ ├── 4_run_terraform_destroy.sh # Script to destroy infrastructure via Terraform │ ├── check_acr_attach_aks.sh # Script to check ACR attachment with AKS │ ├── delete_all_rg_except.sh # Script to delete all resource groups except specific ones │ ├── git_add_amend_pushf.sh # Script for Git add, amend, and push │ ├── git_switch_rebase.sh # Script to switch branches and rebase in Git │ ├── tf_backend_storage.sh # Script to set up backend storage for Terraform state (git ignored) │ ├── .gitignore # Git ignore file for Terraform and other generated files └── README.md # Project overview and documentation
This project is licensed under the MIT License.
DEVOPS-TERRAFORM-SAMPLE/ │ ├── .github/ # GitHub Actions workflows and custom actions │ └── actions/ │ └── workflows/ │ ├── azure-platform/ # Terraform files for infrastructure provisioning │ ├── deployment/ │ └── modules/ │ ├── data-upload-app/ # Application source code, Helm charts, and Terraform for app deployment │ ├── deployment/ │ └── modules/ │ ├── helper/ # Helper scripts for managing infrastructure and app deployment └── README.md #