This project provides an automated DevSecOps pipeline for deploying and securing infrastructure on Azure using Terraform and Terraform Cloud. The pipeline is defined in azure-pipelines.yml and leverages reusable templates under .azdo-pipelines/pipeline_templates/ for modular, secure, and maintainable builds.
- Terraform (latest stable version)
- Terraform Cloud account
- Azure subscription with appropriate RBAC permissions
- Azure DevOps account for running pipelines
The main pipeline (azure-pipelines.yml) orchestrates the following stages:
-
Build Docker Image
Usesbuild-image.ymlto build container images from source code using Azure DevOps agents. -
Lint and Format
Useslinting.ymlto enforce Python code formatting and linting (Python 3.12.6 by default). -
Unit & Security Testing
Usesunit-sec-scan.ymlto run unit tests and basic security checks before publishing artifacts. -
Push Docker Image
Usespush-image.ymlto push the validated image to Azure Container Registry (ACR).
.azdo-pipelines/
├── azure-pipelines.yml # Main Azure DevOps pipeline
└── pipeline_templates/ # Modular templates
├── build-image.yml # Build container images
├── linting.yml # Code linting & formatting
├── push-image.yml # Push image to ACR
├── sample-push.yml # Example template for image push
└── unit-sec-scan.yml # Unit + security testing
terraform/
├── main.tf # Core Terraform configuration
├── acr_aks.tf # Azure Container Registry + AKS
├── providers.tf # Provider configuration
├── variables.tf # Input variables
├── variable-group.tf # Variable groups integration
└── outputs.tf # Outputs- Create an account on Terraform Cloud.
- Generate an API key and store it in Azure DevOps as a secure variable.
- Create workspaces for your infrastructure modules.
- Follow Terraform Dynamic Provider Credentials.
- Ensure your Service Principal or Managed Identity has proper roles (Contributor, AcrPush, AKS permissions).
From the terraform/ folder:
terraform init
terraform plan- Connect your repository to Azure DevOps.
- Trigger the pipeline defined in
.azdo-pipelines/azure-pipelines.yml.
Configure the following in Terraform Cloud or Azure DevOps Variable Groups:
ARM_CLIENT_IDARM_CLIENT_SECRETARM_SUBSCRIPTION_IDARM_TENANT_ID