|
1 | | -# Azure DevSecOps Pipeline |
| 1 | +# Azure DevSecOps Pipeline - Terraform |
2 | 2 |
|
3 | | -:construction: Still a work in progress :construction: |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
4 | 10 |
|
5 | | -## References |
| 11 | +## Overview |
| 12 | + |
| 13 | +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. |
| 14 | + |
| 15 | +## Requirements |
| 16 | + |
| 17 | +- **Terraform** (latest stable version) |
| 18 | +- **Terraform Cloud** account |
| 19 | +- **Azure** subscription with appropriate RBAC permissions |
| 20 | +- **Azure DevOps** account for running pipelines |
| 21 | + |
| 22 | +## Pipeline Workflow |
| 23 | + |
| 24 | +The main pipeline (`azure-pipelines.yml`) orchestrates the following stages: |
| 25 | + |
| 26 | +1. **Build Docker Image** |
| 27 | + Uses [`build-image.yml`](.azdo-pipelines/pipeline_templates/build-image.yml) to build container images from source code using Azure DevOps agents. |
| 28 | + |
| 29 | +2. **Lint and Format** |
| 30 | + Uses [`linting.yml`](.azdo-pipelines/pipeline_templates/linting.yml) to enforce Python code formatting and linting (Python 3.12.6 by default). |
| 31 | + |
| 32 | +3. **Unit & Security Testing** |
| 33 | + Uses [`unit-sec-scan.yml`](.azdo-pipelines/pipeline_templates/unit-sec-scan.yml) to run unit tests and basic security checks before publishing artifacts. |
| 34 | + |
| 35 | +4. **Push Docker Image** |
| 36 | + Uses [`push-image.yml`](.azdo-pipelines/pipeline_templates/push-image.yml) to push the validated image to Azure Container Registry (ACR). |
| 37 | + |
| 38 | +## Repository Structure |
| 39 | + |
| 40 | +```bash |
| 41 | +.azdo-pipelines/ |
| 42 | + ├── azure-pipelines.yml # Main Azure DevOps pipeline |
| 43 | + └── pipeline_templates/ # Modular templates |
| 44 | + ├── build-image.yml # Build container images |
| 45 | + ├── linting.yml # Code linting & formatting |
| 46 | + ├── push-image.yml # Push image to ACR |
| 47 | + ├── sample-push.yml # Example template for image push |
| 48 | + └── unit-sec-scan.yml # Unit + security testing |
| 49 | + |
| 50 | +terraform/ |
| 51 | + ├── main.tf # Core Terraform configuration |
| 52 | + ├── acr_aks.tf # Azure Container Registry + AKS |
| 53 | + ├── providers.tf # Provider configuration |
| 54 | + ├── variables.tf # Input variables |
| 55 | + ├── variable-group.tf # Variable groups integration |
| 56 | + └── outputs.tf # Outputs |
| 57 | +``` |
| 58 | + |
| 59 | +## Setup Instructions |
6 | 60 |
|
7 | | -https://dev.to/this-is-learning/deploy-azure-infrastructure-using-terraform-cloud-3j9d |
| 61 | +### 1. **Terraform Cloud Setup** |
| 62 | + |
| 63 | +- Create an account on [Terraform Cloud](https://app.terraform.io/). |
| 64 | +- Generate an API key and store it in Azure DevOps as a secure variable. |
| 65 | +- Create workspaces for your infrastructure modules. |
| 66 | + |
| 67 | +### 2. **Configure Azure Credentials** |
| 68 | + |
| 69 | +- Follow [Terraform Dynamic Provider Credentials](https://developer.hashicorp.com/terraform/cloud-docs/workspaces/dynamic-provider-credentials/azure-configuration). |
| 70 | +- Ensure your Service Principal or Managed Identity has proper roles (Contributor, AcrPush, AKS permissions). |
| 71 | + |
| 72 | +### 3. **Initialize Terraform** |
| 73 | + |
| 74 | +From the `terraform/` folder: |
| 75 | + |
| 76 | +```bash |
| 77 | +terraform init |
| 78 | +terraform plan |
| 79 | +``` |
| 80 | + |
| 81 | +### 4. **Run the Pipeline** |
| 82 | + |
| 83 | +- Connect your repository to Azure DevOps. |
| 84 | +- Trigger the pipeline defined in `.azdo-pipelines/azure-pipelines.yml`. |
| 85 | + |
| 86 | +## Environment Variables |
| 87 | + |
| 88 | +Configure the following in **Terraform Cloud** or **Azure DevOps Variable Groups**: |
| 89 | + |
| 90 | +- `ARM_CLIENT_ID` |
| 91 | +- `ARM_CLIENT_SECRET` |
| 92 | +- `ARM_SUBSCRIPTION_ID` |
| 93 | +- `ARM_TENANT_ID` |
| 94 | + |
| 95 | +## References |
8 | 96 |
|
9 | | -https://developer.hashicorp.com/terraform/cloud-docs/workspaces/dynamic-provider-credentials/azure-configuration#configure-hcp-terraform |
| 97 | +- [Deploy Azure Infrastructure using Terraform Cloud](https://dev.to/this-is-learning/deploy-azure-infrastructure-using-terraform-cloud-3j9d) |
| 98 | +- [Terraform Cloud: Dynamic Provider Credentials for Azure](https://developer.hashicorp.com/terraform/cloud-docs/workspaces/dynamic-provider-credentials/azure-configuration#configure-hcp-terraform) |
0 commit comments