-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (99 loc) · 3.31 KB
/
ci‑cd.yml
File metadata and controls
127 lines (99 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: CI Pipeline
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
id-token: write # Needed for OIDC (if enabled)
contents: read
jobs:
lint-and-validate:
name: Lint & Validate Terraform + Bicep
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
# TERRAFORM VALIDATION
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.6.3
- name: Terraform init
working-directory: terraform/
run: terraform init
- name: Terraform format check
working-directory: terraform/
run: terraform fmt -check -recursive
- name: TFLint
uses: terraform-linters/setup-tflint@v1
with:
tflint_version: latest
- name: Run tflint
working-directory: terraform/
run: tflint
- name: Terraform validate
working-directory: terraform/
run: terraform validate
# BICEP VALIDATION
- name: Install Bicep CLI
run: |
az bicep install
az bicep upgrade
- name: Bicep build
working-directory: bicep/
run: bicep build main.bicep
- name: Bicep what-if (simulated)
run: echo "Skipped: would run az deployment group what-if here"
#
# OPTIONAL: OIDC Login to Azure (commented)
#
# - name: Azure login (OIDC)
# uses: azure/login@v1
# with:
# client-id: ${{ secrets.AZURE_CLIENT_ID }}
# tenant-id: ${{ secrets.AZURE_TENANT_ID }}
# subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
terratest:
name: Terraform Integration Tests (Parallel)
runs-on: ubuntu-latest
strategy:
matrix:
region: [canadacentral, eastus2]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Simulated Terratest
run: |
echo "Running Terratest for region: ${{ matrix.region }}"
echo "(Stubbed) Would deploy to sandbox, run Go test, and destroy."
blue-green-swap:
name: Blue-Green Swap & E2E Test
runs-on: ubuntu-latest
needs: terratest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Simulate blue-green swap
run: |
echo "Simulating Traffic Manager swap: staging -> production"
# Would run something like:
# az network traffic-manager endpoint update \
# --name prod-app --profile-name traffic-prof --resource-group rg-demo \
# --type azureEndpoints --target-resource-id /subscriptions/.../aks-green \
echo "(Swap logic stubbed for showcase)"
- name: Run E2E test
id: e2e
run: |
echo "Running end-to-end health check against production endpoint..."
# Simulate test result
echo "Simulated failure"
exit 1 # force failure to trigger rollback path
- name: Rollback Traffic Manager to blue slot
if: failure() && steps.e2e.outcome == 'failure'
run: |
echo "Rolling back traffic to previous (blue) deployment"
# Would normally call:
# az network traffic-manager endpoint update --target-resource-id /aks-blue