-
Notifications
You must be signed in to change notification settings - Fork 8
4374 lines (3777 loc) · 197 KB
/
deploy-azd.yml
File metadata and controls
4374 lines (3777 loc) · 197 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: deploy-azd-core (reusable)
on:
workflow_call:
inputs:
environment:
description: Deployment environment name (for azd -e)
required: true
type: string
githubEnvironment:
description: GitHub Actions environment name used for approvals and protection rules
required: false
type: string
default: branch
location:
description: Azure location
required: true
type: string
projectName:
description: Project prefix used by naming convention
required: false
type: string
default: holidaypeakhub405
imageTag:
description: Image tag to deploy
required: false
type: string
default: latest
sourceSha:
description: Explicit tested source commit SHA to checkout across the workflow
required: false
type: string
default: ''
sourceRef:
description: Explicit tested source ref to checkout when sourceSha is not provided
required: false
type: string
default: ''
deployStatic:
description: Provision static web app resources
required: false
type: boolean
default: true
uiOnly:
description: Deploy only the UI using SWA token (skips provision and Azure login jobs)
required: false
type: boolean
default: false
apiBaseUrl:
description: Optional API base URL for UI build override
required: false
type: string
default: ''
deployChangedOnly:
description: Legacy flag (changed-app-only deployment is always enforced)
required: false
type: boolean
default: true
forceApimSync:
description: Force APIM sync and smoke checks even when no changed services are detected
required: false
type: boolean
default: false
autoAllowAcrRunnerIp:
description: Temporarily allow this GitHub runner egress IP in ACR firewall during deploy and remove it afterward
required: false
type: boolean
default: true
skipApiSmokeChecks:
description: Skip API smoke checks for urgent UI-only deployments
required: false
type: boolean
default: false
serviceFilter:
description: Comma-separated list of agent service names to deploy (empty = all changed). Use to scope deploys to a subset of services.
required: false
type: string
default: ''
skipProvision:
description: Skip azd provision and reuse the current azd environment plus existing infrastructure for an emergency redeploy
required: false
type: boolean
default: false
skipPromptGates:
description: Skip the prompt-sync CI gates (image prompt verification and Foundry instructions verification). Use only for urgent deploys where the gates are known to be unrelated to the change.
required: false
type: boolean
default: false
skipPostgresPreflight:
description: Skip the PostgreSQL password preflight probe run before the CRUD rollout. When true, the gate is bypassed and a warning is logged.
required: false
type: boolean
default: false
deployFoundrySurfaces:
description: Plan or apply Foundry Hosted/Custom surface registration after tested agent images are available.
required: false
type: boolean
default: false
foundrySurfaceMode:
description: Foundry surface registration mode. Use plan for dry-run artifacts; use apply to create/update Hosted Agent versions.
required: false
type: string
default: plan
secrets:
AZURE_CLIENT_ID:
required: true
AZURE_TENANT_ID:
required: true
AZURE_SUBSCRIPTION_ID:
required: true
permissions:
id-token: write
contents: write
env:
FOUNDRY_RUNTIME_STRICT_ENFORCEMENT: "true"
FOUNDRY_RUNTIME_AUTO_ENSURE_ON_STARTUP: "true"
DEPLOY_SOURCE_SHA: ${{ inputs.sourceSha != '' && inputs.sourceSha || github.sha }}
DEPLOY_SOURCE_REF: ${{ inputs.sourceRef != '' && inputs.sourceRef || github.ref }}
DEPLOY_SOURCE_CHECKOUT_REF: ${{ inputs.sourceSha != '' && inputs.sourceSha || (inputs.sourceRef != '' && inputs.sourceRef || github.sha) }}
REPOSITORY_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
FLUX_SOURCE_NAME: holiday-peak-gitops
FLUX_SOURCE_NAMESPACE: flux-system
concurrency:
group: deploy-azd-${{ inputs.environment }}
cancel-in-progress: false
jobs:
detect-changes:
if: ${{ !inputs.uiOnly }}
runs-on: ubuntu-latest
outputs:
crud_changed: ${{ steps.detect.outputs.crud_changed }}
ui_changed: ${{ steps.detect.outputs.ui_changed }}
agents_changed: ${{ steps.detect.outputs.agents_changed }}
changed_agents_matrix: ${{ steps.detect.outputs.changed_agents_matrix }}
changed_agent_services_csv: ${{ steps.detect.outputs.changed_agent_services_csv }}
changed_aks_services_csv: ${{ steps.detect.outputs.changed_aks_services_csv }}
changed_aks_matrix: ${{ steps.detect.outputs.changed_aks_matrix }}
lib_changed: ${{ steps.detect.outputs.lib_changed }}
infra_changed: ${{ steps.detect.outputs.infra_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ env.DEPLOY_SOURCE_CHECKOUT_REF }}
- name: Detect changed services
id: detect
shell: bash
run: |
set -euo pipefail
DEFAULT_BRANCH="${{ github.event.repository.default_branch }}"
TARGET_SHA="${DEPLOY_SOURCE_SHA}"
echo "Detected deploy source SHA: ${TARGET_SHA}"
echo "Detected deploy source ref: ${DEPLOY_SOURCE_REF}"
git fetch origin "$DEFAULT_BRANCH" --depth=1 || true
CHANGED_FILES=""
DIFF_RANGE=""
DIFF_STRATEGY=""
if [ "${{ github.event_name }}" = "push" ] && [ -n "${{ github.event.before }}" ] && [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then
if git cat-file -e "${{ github.event.before }}^{commit}" 2>/dev/null; then
PUSH_BASE="${{ github.event.before }}"
MERGE_BASE=$(git merge-base "$PUSH_BASE" "$TARGET_SHA" || true)
if [ -n "$MERGE_BASE" ]; then
DIFF_RANGE="$PUSH_BASE...$TARGET_SHA"
DIFF_STRATEGY="push-before-three-dot"
else
DIFF_RANGE="$PUSH_BASE..$TARGET_SHA"
DIFF_STRATEGY="push-before-two-dot-fallback"
echo "::warning::No common ancestor between push before SHA and current SHA; using two-dot fallback diff range '$DIFF_RANGE'."
fi
else
echo "::warning::Push before SHA '${{ github.event.before }}' is not available in local clone; falling back to default branch baseline."
fi
fi
if [ -z "$DIFF_RANGE" ] && [ -n "${{ inputs.sourceSha }}" ] && [ -n "$TARGET_SHA" ] && git cat-file -e "${TARGET_SHA}^{commit}" 2>/dev/null; then
if git rev-parse --verify "${TARGET_SHA}^1" >/dev/null 2>&1; then
DIFF_RANGE="${TARGET_SHA}^1...${TARGET_SHA}"
DIFF_STRATEGY="source-sha-first-parent-three-dot"
fi
fi
if [ -z "$DIFF_RANGE" ]; then
DEFAULT_REF="origin/$DEFAULT_BRANCH"
if git rev-parse --verify "$DEFAULT_REF" >/dev/null 2>&1; then
MERGE_BASE=$(git merge-base "$DEFAULT_REF" HEAD || true)
if [ -n "$MERGE_BASE" ]; then
DIFF_RANGE="$MERGE_BASE...HEAD"
DIFF_STRATEGY="default-branch-merge-base-three-dot"
else
DIFF_RANGE="$DEFAULT_REF..HEAD"
DIFF_STRATEGY="default-branch-two-dot-fallback"
echo "::warning::No common ancestor with '$DEFAULT_REF'; using conservative fallback diff range '$DIFF_RANGE'."
fi
else
DIFF_STRATEGY="full-tree-fallback"
echo "::warning::Default branch reference '$DEFAULT_REF' is unavailable; treating tracked files as changed."
fi
fi
if [ "$DIFF_STRATEGY" = "full-tree-fallback" ]; then
CHANGED_FILES=$(git ls-files)
else
CHANGED_FILES=$(git diff --name-only "$DIFF_RANGE" || true)
fi
CHANGED_COUNT=$(printf '%s\n' "$CHANGED_FILES" | sed '/^$/d' | wc -l | xargs)
echo "Changed-services detection strategy: $DIFF_STRATEGY"
if [ -n "$DIFF_RANGE" ]; then
echo "Changed-services diff range: $DIFF_RANGE"
fi
echo "Changed-services file count: $CHANGED_COUNT"
mapfile -t AGENT_SERVICES < <(python3 - <<'PY'
import re
with open('azure.yaml', encoding='utf-8') as f:
lines = f.readlines()
in_services = False
current_service = None
current_host = None
services = []
for raw in lines:
line = raw.rstrip('\n')
if not in_services:
if re.match(r'^services:\s*$', line):
in_services = True
continue
if re.match(r'^[^\s]', line):
break
service_match = re.match(r'^ ([a-z0-9\-]+):\s*$', line)
if service_match:
if current_service and current_host == 'aks' and current_service != 'crud-service':
services.append(current_service)
current_service = service_match.group(1)
current_host = None
continue
host_match = re.match(r'^ host:\s*(\S+)\s*$', line)
if host_match:
current_host = host_match.group(1)
if current_service and current_host == 'aks' and current_service != 'crud-service':
services.append(current_service)
for service in services:
print(service)
PY
)
CRUD_CHANGED=false
if echo "$CHANGED_FILES" | grep -Eq '^apps/crud-service/'; then
CRUD_CHANGED=true
fi
UI_CHANGED=false
if echo "$CHANGED_FILES" | grep -Eq '^apps/ui/'; then
UI_CHANGED=true
fi
LIB_CHANGED=false
if echo "$CHANGED_FILES" | grep -Eq '^lib/'; then
LIB_CHANGED=true
fi
INFRA_CHANGED=false
if echo "$CHANGED_FILES" | grep -Eq '^(\.infra/|azure\.yaml|\.kubernetes/)'; then
INFRA_CHANGED=true
fi
AGENTS_CHANGED=false
MATRIX='[]'
CHANGED_AGENTS=()
for service in "${AGENT_SERVICES[@]}"; do
if echo "$CHANGED_FILES" | grep -Eq "^apps/$service/"; then
CHANGED_AGENTS+=("$service")
fi
done
# If lib/ changed, all agent services need rebuild
if [ "$LIB_CHANGED" = true ]; then
CHANGED_AGENTS=("${AGENT_SERVICES[@]}")
CRUD_CHANGED=true
fi
# Apply service filter when provided (scoped deployments)
SERVICE_FILTER="${{ inputs.serviceFilter }}"
if [ -n "$SERVICE_FILTER" ]; then
IFS=',' read -ra FILTER_LIST <<< "$SERVICE_FILTER"
FILTERED_AGENTS=()
for filter_svc in "${FILTER_LIST[@]}"; do
trimmed=$(echo "$filter_svc" | xargs)
for agent in "${AGENT_SERVICES[@]}"; do
if [ "$agent" = "$trimmed" ]; then
FILTERED_AGENTS+=("$agent")
fi
done
done
CHANGED_AGENTS=("${FILTERED_AGENTS[@]}")
# When a filter is active, do not auto-include CRUD unless it is in the filter
CRUD_IN_FILTER=false
for filter_svc in "${FILTER_LIST[@]}"; do
trimmed=$(echo "$filter_svc" | xargs)
if [ "$trimmed" = "crud-service" ]; then
CRUD_IN_FILTER=true
fi
done
if [ "$CRUD_IN_FILTER" = false ]; then
CRUD_CHANGED=false
else
CRUD_CHANGED=true
fi
UI_CHANGED=false
echo "Service filter applied: ${CHANGED_AGENTS[*]:-none}"
fi
if [ ${#CHANGED_AGENTS[@]} -gt 0 ]; then
AGENTS_CHANGED=true
MATRIX=$(printf '%s\n' "${CHANGED_AGENTS[@]}" | jq -Rcs 'split("\n")[:-1] | map(select(length > 0)) | map({service: .})')
fi
CHANGED_AGENT_SERVICES_CSV=""
if [ ${#CHANGED_AGENTS[@]} -gt 0 ]; then
CHANGED_AGENT_SERVICES_CSV=$(IFS=,; echo "${CHANGED_AGENTS[*]}")
fi
CHANGED_AKS_SERVICES_CSV="$CHANGED_AGENT_SERVICES_CSV"
if [ "$CRUD_CHANGED" = true ]; then
if [ -n "$CHANGED_AKS_SERVICES_CSV" ]; then
CHANGED_AKS_SERVICES_CSV="crud-service,$CHANGED_AKS_SERVICES_CSV"
else
CHANGED_AKS_SERVICES_CSV="crud-service"
fi
fi
CHANGED_AKS_MATRIX='[]'
if [ -n "$CHANGED_AKS_SERVICES_CSV" ]; then
CHANGED_AKS_MATRIX=$(printf '%s\n' "$CHANGED_AKS_SERVICES_CSV" | tr ',' '\n' | jq -Rcs 'split("\n")[:-1] | map(select(length > 0)) | map({service: .})')
fi
echo "crud_changed=$CRUD_CHANGED" >> "$GITHUB_OUTPUT"
echo "ui_changed=$UI_CHANGED" >> "$GITHUB_OUTPUT"
echo "agents_changed=$AGENTS_CHANGED" >> "$GITHUB_OUTPUT"
printf 'changed_agents_matrix=%s\n' "$MATRIX" >> "$GITHUB_OUTPUT"
echo "changed_agent_services_csv=$CHANGED_AGENT_SERVICES_CSV" >> "$GITHUB_OUTPUT"
echo "changed_aks_services_csv=$CHANGED_AKS_SERVICES_CSV" >> "$GITHUB_OUTPUT"
printf 'changed_aks_matrix=%s\n' "$CHANGED_AKS_MATRIX" >> "$GITHUB_OUTPUT"
echo "lib_changed=$LIB_CHANGED" >> "$GITHUB_OUTPUT"
echo "infra_changed=$INFRA_CHANGED" >> "$GITHUB_OUTPUT"
provision:
if: ${{ !inputs.uiOnly }}
needs: detect-changes
runs-on: ubuntu-latest
environment: ${{ inputs.githubEnvironment }}
outputs:
AI_SERVICES_NAME: ${{ steps.outputs.outputs.AI_SERVICES_NAME }}
AI_SEARCH_NAME: ${{ steps.outputs.outputs.AI_SEARCH_NAME }}
AI_SEARCH_ENDPOINT: ${{ steps.outputs.outputs.AI_SEARCH_ENDPOINT }}
AI_SEARCH_INDEX: ${{ steps.outputs.outputs.AI_SEARCH_INDEX }}
AI_SEARCH_VECTOR_INDEX: ${{ steps.outputs.outputs.AI_SEARCH_VECTOR_INDEX }}
AI_SEARCH_INDEXER_NAME: ${{ steps.outputs.outputs.AI_SEARCH_INDEXER_NAME }}
EMBEDDING_DEPLOYMENT_NAME: ${{ steps.outputs.outputs.EMBEDDING_DEPLOYMENT_NAME }}
AI_SEARCH_AUTH_MODE: ${{ steps.outputs.outputs.AI_SEARCH_AUTH_MODE }}
PROJECT_ENDPOINT: ${{ steps.outputs.outputs.PROJECT_ENDPOINT }}
PROJECT_NAME: ${{ steps.outputs.outputs.PROJECT_NAME }}
APIM_GATEWAY_URL: ${{ steps.outputs.outputs.APIM_GATEWAY_URL }}
COSMOS_ACCOUNT_URI: ${{ steps.outputs.outputs.COSMOS_ACCOUNT_URI }}
COSMOS_DATABASE: ${{ steps.outputs.outputs.COSMOS_DATABASE }}
COSMOS_CONTAINER: ${{ steps.outputs.outputs.COSMOS_CONTAINER }}
KEY_VAULT_URI: ${{ steps.outputs.outputs.KEY_VAULT_URI }}
REDIS_HOST: ${{ steps.outputs.outputs.REDIS_HOST }}
EVENT_HUB_NAMESPACE: ${{ steps.outputs.outputs.EVENT_HUB_NAMESPACE }}
APPLICATIONINSIGHTS_CONNECTION_STRING: ${{ steps.outputs.outputs.APPLICATIONINSIGHTS_CONNECTION_STRING }}
BLOB_ACCOUNT_URL: ${{ steps.outputs.outputs.BLOB_ACCOUNT_URL }}
BLOB_CONTAINER: ${{ steps.outputs.outputs.BLOB_CONTAINER }}
POSTGRES_HOST: ${{ steps.outputs.outputs.POSTGRES_HOST }}
POSTGRES_USER: ${{ steps.outputs.outputs.POSTGRES_USER }}
POSTGRES_ADMIN_USER: ${{ steps.outputs.outputs.POSTGRES_ADMIN_USER }}
POSTGRES_AUTH_MODE: ${{ steps.outputs.outputs.POSTGRES_AUTH_MODE }}
POSTGRES_DATABASE: ${{ steps.outputs.outputs.POSTGRES_DATABASE }}
AGC_SUPPORT_ENABLED: ${{ steps.outputs.outputs.AGC_SUPPORT_ENABLED }}
AGC_GATEWAY_CLASS: ${{ steps.outputs.outputs.AGC_GATEWAY_CLASS }}
AGC_SUBNET_ID: ${{ steps.outputs.outputs.AGC_SUBNET_ID }}
AGC_FRONTEND_HOSTNAME: ${{ steps.outputs.outputs.AGC_FRONTEND_HOSTNAME }}
AGC_FRONTEND_REFERENCE: ${{ steps.outputs.outputs.AGC_FRONTEND_REFERENCE }}
AGC_CONTROLLER_DEPLOYMENT_MODE: ${{ steps.outputs.outputs.AGC_CONTROLLER_DEPLOYMENT_MODE }}
AGC_CONTROLLER_IDENTITY_NAME: ${{ steps.outputs.outputs.AGC_CONTROLLER_IDENTITY_NAME }}
AGC_CONTROLLER_IDENTITY_CLIENT_ID: ${{ steps.outputs.outputs.AGC_CONTROLLER_IDENTITY_CLIENT_ID }}
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
CHANGED_AGENT_SERVICES: ${{ needs.detect-changes.outputs.changed_agent_services_csv }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.DEPLOY_SOURCE_CHECKOUT_REF }}
- name: Azure login (OIDC)
uses: azure/login@v2
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
- name: Setup azd
uses: Azure/setup-azd@v2
- name: Authenticate azd (OIDC)
run: |
azd auth login \
--client-id "${AZURE_CLIENT_ID}" \
--tenant-id "${AZURE_TENANT_ID}" \
--federated-credential-provider github \
--no-prompt
- name: Configure azd environment context
run: |
azd env set AZURE_SUBSCRIPTION_ID "${AZURE_SUBSCRIPTION_ID}" -e "${{ inputs.environment }}"
azd env set AZURE_LOCATION "${{ inputs.location }}" -e "${{ inputs.environment }}"
azd env set AZURE_ENV_NAME "${{ inputs.environment }}" -e "${{ inputs.environment }}"
azd env set AZURE_RESOURCE_GROUP "${{ inputs.projectName }}-${{ inputs.environment }}-rg" -e "${{ inputs.environment }}"
azd env set resourceGroupName "${{ inputs.projectName }}-${{ inputs.environment }}-rg" -e "${{ inputs.environment }}"
azd env set AZURE_AKS_CLUSTER_NAME "${{ inputs.projectName }}-${{ inputs.environment }}-aks" -e "${{ inputs.environment }}"
azd env set AKS_CLUSTER_NAME "${{ inputs.projectName }}-${{ inputs.environment }}-aks" -e "${{ inputs.environment }}"
azd env set AZURE_CONTAINER_REGISTRY_ENDPOINT "${{ inputs.projectName }}${{ inputs.environment }}acr.azurecr.io" -e "${{ inputs.environment }}"
azd env set deployShared true -e "${{ inputs.environment }}"
azd env set deployStatic "${{ inputs.deployStatic }}" -e "${{ inputs.environment }}"
azd env set environment "${{ inputs.environment }}" -e "${{ inputs.environment }}"
azd env set location "${{ inputs.location }}" -e "${{ inputs.environment }}"
azd env set projectName "${{ inputs.projectName }}" -e "${{ inputs.environment }}"
azd env set IMAGE_PREFIX "ghcr.io/${{ github.repository_owner }}" -e "${{ inputs.environment }}"
azd env set IMAGE_TAG "${{ inputs.imageTag }}" -e "${{ inputs.environment }}"
azd env set K8S_NAMESPACE holiday-peak -e "${{ inputs.environment }}"
azd env set K8S_CRUD_NAMESPACE holiday-peak-crud -e "${{ inputs.environment }}"
azd env set K8S_AGENTS_NAMESPACE holiday-peak-agents -e "${{ inputs.environment }}"
azd env set KEDA_ENABLED true -e "${{ inputs.environment }}"
# PostgreSQL auth: use password for dev until Entra AD admin is configured
# in Bicep (administrators param on AVM PostgreSQL module). Enabling
# activeDirectoryAuth without an admin has no effect — see ADR-017 follow-up.
azd env set POSTGRES_AUTH_MODE password -e "${{ inputs.environment }}"
- name: Install kubelogin
run: |
for attempt in 1 2 3 4 5; do
if az aks install-cli --kubelogin-version latest; then
exit 0
fi
echo "kubelogin install failed on attempt ${attempt}; retrying..."
sleep 15
done
echo "kubelogin install failed after retries"
exit 1
- name: Ensure hook scripts executable
run: chmod +x ./.infra/azd/hooks/*.sh
- name: Ensure AKS cluster is running
run: |
AKS_RG="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
AKS_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-aks"
if az aks show --resource-group "$AKS_RG" --name "$AKS_NAME" >/dev/null 2>&1; then
POWER_STATE=$(az aks show --resource-group "$AKS_RG" --name "$AKS_NAME" --query "powerState.code" -o tsv 2>/dev/null || true)
if [ "$POWER_STATE" = "Stopped" ]; then
echo "AKS cluster is stopped. Starting $AKS_NAME..."
az aks start --resource-group "$AKS_RG" --name "$AKS_NAME"
for _ in $(seq 1 40); do
CURRENT_STATE=$(az aks show --resource-group "$AKS_RG" --name "$AKS_NAME" --query "powerState.code" -o tsv 2>/dev/null || true)
if [ "$CURRENT_STATE" = "Running" ]; then
echo "AKS cluster is running."
break
fi
sleep 30
done
FINAL_STATE=$(az aks show --resource-group "$AKS_RG" --name "$AKS_NAME" --query "powerState.code" -o tsv 2>/dev/null || true)
if [ "$FINAL_STATE" != "Running" ]; then
echo "AKS cluster failed to reach Running state (current: ${FINAL_STATE:-unknown})." >&2
exit 1
fi
fi
else
echo "AKS cluster does not exist yet. Continuing."
fi
- name: Ensure deploy principal has AKS RBAC Cluster Admin
shell: bash
run: |
set -euo pipefail
AKS_RG="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
DEPLOY_SP_OBJECT_ID=$(az ad sp show --id "${AZURE_CLIENT_ID}" --query id -o tsv)
RG_ID=$(az group show --name "$AKS_RG" --query id -o tsv)
EXISTING=$(az role assignment list \
--scope "$RG_ID" \
--assignee-object-id "$DEPLOY_SP_OBJECT_ID" \
--query "[?roleDefinitionName=='Azure Kubernetes Service RBAC Cluster Admin'] | length(@)" -o tsv)
if [ "$EXISTING" = "0" ]; then
echo "Assigning Azure Kubernetes Service RBAC Cluster Admin to deploy principal at RG scope $AKS_RG."
az role assignment create \
--assignee-object-id "$DEPLOY_SP_OBJECT_ID" \
--assignee-principal-type ServicePrincipal \
--role "Azure Kubernetes Service RBAC Cluster Admin" \
--scope "$RG_ID"
else
echo "Deploy principal already has Azure Kubernetes Service RBAC Cluster Admin at RG scope $AKS_RG."
fi
VERIFIED=$(az role assignment list \
--scope "$RG_ID" \
--assignee-object-id "$DEPLOY_SP_OBJECT_ID" \
--query "[?roleDefinitionName=='Azure Kubernetes Service RBAC Cluster Admin'] | length(@)" -o tsv)
if [ "$VERIFIED" = "0" ]; then
echo "Failed to verify Azure Kubernetes Service RBAC Cluster Admin assignment for deploy principal at scope $AKS_RG."
exit 1
fi
- name: Preflight drift remediation (non-prod)
if: ${{ !inputs.skipProvision && inputs.environment != 'prod' && inputs.environment != 'production' }}
shell: bash
run: |
set -euo pipefail
RG_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
KEY_VAULT_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-kv"
POSTGRES_SERVER_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-postgres"
DESIRED_LOCATION="$(echo "${{ inputs.location }}" | tr '[:upper:]' '[:lower:]')"
echo "Running non-prod preflight drift remediation for environment '${{ inputs.environment }}'."
# Remediate soft-deleted Key Vault name conflicts that can block azd provision.
if az keyvault show --name "$KEY_VAULT_NAME" --resource-group "$RG_NAME" >/dev/null 2>&1; then
CURRENT_KV_LOCATION=$(az keyvault show \
--name "$KEY_VAULT_NAME" \
--resource-group "$RG_NAME" \
--query location -o tsv | tr '[:upper:]' '[:lower:]')
if [ "$CURRENT_KV_LOCATION" != "$DESIRED_LOCATION" ]; then
LOCATION_SUFFIX=$(echo "$DESIRED_LOCATION" | tr -cd '[:alnum:]' | cut -c1-4)
KEY_VAULT_OVERRIDE=$(echo "${{ inputs.projectName }}-${{ inputs.environment }}-kv-${LOCATION_SUFFIX}" | tr '[:upper:]' '[:lower:]' | cut -c1-24)
KEY_VAULT_OVERRIDE="${KEY_VAULT_OVERRIDE%-}"
echo "Key Vault location mismatch detected for $KEY_VAULT_NAME ($CURRENT_KV_LOCATION vs $DESIRED_LOCATION)."
echo "Setting keyVaultNameOverride to $KEY_VAULT_OVERRIDE for this deployment."
azd env set keyVaultNameOverride "$KEY_VAULT_OVERRIDE" -e "${{ inputs.environment }}"
else
echo "Key Vault $KEY_VAULT_NAME already exists in $RG_NAME with matching location $CURRENT_KV_LOCATION."
fi
else
DELETED_KV_LOCATION=$(az keyvault list-deleted \
--query "[?name=='$KEY_VAULT_NAME'] | [0].properties.location" \
-o tsv)
if [ -n "$DELETED_KV_LOCATION" ]; then
echo "Recovering soft-deleted Key Vault $KEY_VAULT_NAME."
if az keyvault recover --name "$KEY_VAULT_NAME" >/dev/null 2>&1; then
echo "Recovery initiated for $KEY_VAULT_NAME."
else
echo "Recovery failed for $KEY_VAULT_NAME. Attempting purge fallback from $DELETED_KV_LOCATION."
az keyvault purge --name "$KEY_VAULT_NAME" --location "$DELETED_KV_LOCATION"
fi
for _ in $(seq 1 20); do
if az keyvault show --name "$KEY_VAULT_NAME" --resource-group "$RG_NAME" >/dev/null 2>&1; then
echo "Key Vault $KEY_VAULT_NAME is now available in $RG_NAME."
break
fi
sleep 10
done
else
echo "No soft-deleted Key Vault conflict found for $KEY_VAULT_NAME."
fi
fi
# Start stopped PostgreSQL Flexible Server so provisioning can reconcile state.
if az postgres flexible-server show --resource-group "$RG_NAME" --name "$POSTGRES_SERVER_NAME" >/dev/null 2>&1; then
POSTGRES_STATE=$(az postgres flexible-server show \
--resource-group "$RG_NAME" \
--name "$POSTGRES_SERVER_NAME" \
--query state -o tsv)
if [ "$POSTGRES_STATE" = "Stopped" ]; then
echo "PostgreSQL server $POSTGRES_SERVER_NAME is stopped. Starting..."
az postgres flexible-server start --resource-group "$RG_NAME" --name "$POSTGRES_SERVER_NAME"
POSTGRES_READY=false
for _ in $(seq 1 40); do
CURRENT_STATE=$(az postgres flexible-server show \
--resource-group "$RG_NAME" \
--name "$POSTGRES_SERVER_NAME" \
--query state -o tsv)
if [ "$CURRENT_STATE" = "Ready" ]; then
echo "PostgreSQL server is ready."
POSTGRES_READY=true
break
fi
sleep 15
done
if [ "$POSTGRES_READY" != "true" ]; then
echo "PostgreSQL server $POSTGRES_SERVER_NAME did not reach Ready state in time."
exit 1
fi
else
echo "PostgreSQL server $POSTGRES_SERVER_NAME state is $POSTGRES_STATE. No start needed."
fi
else
echo "PostgreSQL server $POSTGRES_SERVER_NAME does not exist yet. Continuing."
fi
- name: Validate truth Event Hubs IaC declarations
if: ${{ !inputs.skipProvision }}
shell: bash
run: |
set -euo pipefail
python3 <<'PY'
import re
from pathlib import Path
bicep_path = Path('.infra/modules/shared-infrastructure/shared-infrastructure.bicep')
bicep = bicep_path.read_text(encoding='utf-8')
expected_event_hub_parents = {
'searchEnrichmentJobsEventHub': 'platformJobsNamespaceResource',
'ingestJobsEventHub': 'platformJobsNamespaceResource',
'enrichmentJobsEventHub': 'platformJobsNamespaceResource',
'completenessJobsEventHub': 'platformJobsNamespaceResource',
'exportJobsEventHub': 'platformJobsNamespaceResource',
'hitlJobsEventHub': 'platformJobsNamespaceResource',
}
expected_consumer_group_parents = {
'ingestionGroupConsumerGroup': 'ingestJobsEventHub',
'enrichmentEngineConsumerGroup': 'enrichmentJobsEventHub',
'completenessEngineConsumerGroup': 'completenessJobsEventHub',
'exportEngineConsumerGroup': 'exportJobsEventHub',
'hitlServiceConsumerGroup': 'hitlJobsEventHub',
'searchEnrichmentAgentConsumerGroup': 'searchEnrichmentJobsEventHub',
'searchEnrichmentConsumerGroup': 'searchEnrichmentJobsEventHub',
}
failures = []
for resource_name, parent_name in expected_event_hub_parents.items():
pattern = rf"resource\s+{resource_name}\s+'Microsoft\.EventHub/namespaces/eventhubs@2024-01-01'\s+existing\s*=\s*\{{\s*parent:\s*{parent_name}\s*"
if not re.search(pattern, bicep, flags=re.MULTILINE):
failures.append(f'{resource_name} -> {parent_name}')
for resource_name, parent_name in expected_consumer_group_parents.items():
pattern = rf"resource\s+{resource_name}\s+'Microsoft\.EventHub/namespaces/eventhubs/consumergroups@2024-01-01'\s*=\s*\{{\s*parent:\s*{parent_name}\s*"
if not re.search(pattern, bicep, flags=re.MULTILINE):
failures.append(f'{resource_name} -> {parent_name}')
if failures:
raise SystemExit(
'Platform jobs Event Hubs namespace ownership drift detected in '
f'{bicep_path}: ' + ', '.join(failures)
)
print('Platform jobs Event Hubs namespace ownership matches the dual-namespace contract.')
PY
- name: Validate app dependency manifest coverage
if: ${{ !inputs.skipProvision }}
shell: bash
run: |
set -euo pipefail
python3 .infra/validate_app_dependency_manifest.py \
--azure-config azure.yaml \
--manifest .infra/app-dependency-manifest.yaml
- name: Validate Event Hubs IaC declarations
if: ${{ !inputs.skipProvision }}
shell: bash
run: |
set -euo pipefail
BICEP_FILE=".infra/modules/shared-infrastructure/shared-infrastructure.bicep"
MISSING=0
for hub in order-events product-events return-events inventory-events shipment-events payment-events user-events ingest-jobs enrichment-jobs completeness-jobs export-jobs hitl-jobs search-enrichment-jobs; do
if ! grep -q "'$hub'" "$BICEP_FILE"; then
echo "Missing required Event Hub declaration in $BICEP_FILE: $hub" >&2
MISSING=1
fi
done
for group in ingestion-group enrichment-engine export-engine hitl-service search-enrichment-consumer search-enrichment-agent catalog-search-group enrichment-group acp-transform-group normalization-group assortment-group validation-group completeness-engine support-group returns-group; do
if ! grep -q "'$group'" "$BICEP_FILE"; then
echo "Missing required consumer group declaration in $BICEP_FILE: $group" >&2
MISSING=1
fi
done
if [ "$MISSING" -ne 0 ]; then
if [ "${{ inputs.environment }}" = "prod" ] || [ "${{ inputs.environment }}" = "production" ]; then
echo "Event Hub IaC validation failed in production environment." >&2
exit 1
fi
echo "Proceeding despite Event Hub IaC declaration warnings in non-production environment." >&2
fi
echo "Event Hub and consumer group declarations are present in IaC."
- name: Validate skip-provision mode
if: ${{ inputs.skipProvision }}
shell: bash
run: |
set -euo pipefail
INFRA_CHANGED="${{ needs.detect-changes.outputs.infra_changed }}"
if [ "$INFRA_CHANGED" = "true" ]; then
echo "::warning::skipProvision is active but infrastructure files changed. Provisioning will be skipped. If you need infra reconciliation, rerun with skipProvision=false."
fi
echo "skipProvision=true: reusing the current azd environment values and existing infrastructure for this deploy."
- name: Provision infrastructure
if: ${{ !inputs.skipProvision }}
shell: bash
run: |
set -euo pipefail
PROVISION_LOG="$(mktemp)"
if azd provision --no-prompt -e "${{ inputs.environment }}" 2>&1 | tee "$PROVISION_LOG"; then
exit 0
fi
if [ "${{ inputs.environment }}" != "prod" ] && [ "${{ inputs.environment }}" != "production" ] \
&& grep -q "RoleAssignmentExists" "$PROVISION_LOG" \
&& ! grep -q "BadRequest:" "$PROVISION_LOG"; then
echo "Non-prod provision hit an idempotent RoleAssignmentExists conflict." >&2
echo "Infrastructure was deployed but azd did not save outputs. Running azd env refresh to populate them." >&2
azd env refresh -e '${{ inputs.environment }}' --no-prompt
echo "azd env refresh completed after RoleAssignmentExists fallback."
exit 0
fi
echo "Provision infrastructure failed with non-ignorable errors." >&2
exit 1
- name: Ensure deploy principal has AcrPush on ACR
shell: bash
run: |
set -euo pipefail
RG_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
ACR_NAME=$(echo "${{ inputs.projectName }}${{ inputs.environment }}acr" | tr -cd '[:alnum:]' | tr '[:upper:]' '[:lower:]')
DEPLOY_SP_OBJECT_ID=$(az ad sp show --id "${AZURE_CLIENT_ID}" --query id -o tsv)
ACR_ID=$(az acr show --resource-group "$RG_NAME" --name "$ACR_NAME" --query id -o tsv)
EXISTING=$(az role assignment list \
--scope "$ACR_ID" \
--assignee-object-id "$DEPLOY_SP_OBJECT_ID" \
--query "[?roleDefinitionName=='AcrPush'] | length(@)" -o tsv)
if [ "$EXISTING" = "0" ]; then
echo "Assigning AcrPush to deploy principal on ACR $ACR_NAME."
az role assignment create \
--assignee-object-id "$DEPLOY_SP_OBJECT_ID" \
--assignee-principal-type ServicePrincipal \
--role "AcrPush" \
--scope "$ACR_ID"
else
echo "Deploy principal already has AcrPush on ACR $ACR_NAME."
fi
VERIFIED=$(az role assignment list \
--scope "$ACR_ID" \
--assignee-object-id "$DEPLOY_SP_OBJECT_ID" \
--query "[?roleDefinitionName=='AcrPush'] | length(@)" -o tsv)
if [ "$VERIFIED" = "0" ]; then
echo "Failed to verify AcrPush assignment for deploy principal on scope $ACR_ID."
exit 1
fi
- name: Ensure AKS identity can read Key Vault secrets
run: |
AKS_RG="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
AKS_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-aks"
KEY_VAULT_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-kv"
KUBELET_OBJECT_ID=$(az aks show \
--resource-group "$AKS_RG" \
--name "$AKS_NAME" \
--query "identityProfile.kubeletidentity.objectId" -o tsv)
KEY_VAULT_ID=$(az keyvault show \
--resource-group "$AKS_RG" \
--name "$KEY_VAULT_NAME" \
--query id -o tsv)
EXISTING=$(az role assignment list \
--assignee-object-id "$KUBELET_OBJECT_ID" \
--scope "$KEY_VAULT_ID" \
--query "[?roleDefinitionName=='Key Vault Secrets User'] | length(@)" -o tsv)
if [ "$EXISTING" = "0" ]; then
az role assignment create \
--assignee-object-id "$KUBELET_OBJECT_ID" \
--assignee-principal-type ServicePrincipal \
--role "Key Vault Secrets User" \
--scope "$KEY_VAULT_ID"
fi
- name: Refresh azd environment from deployed infrastructure
if: ${{ inputs.skipProvision }}
shell: bash
run: |
set -euo pipefail
echo "skipProvision=true: refreshing azd environment outputs from the last successful deployment."
azd env refresh -e '${{ inputs.environment }}' --no-prompt
echo "azd env refresh completed."
# ── Recover outputs when ARM deployment state is Failed ──────────
# azd env refresh silently returns no values when the ARM deployment
# is in a Failed state (e.g. RoleAssignmentExists conflicts cause
# the deployment to be marked Failed even though resources deployed).
# This step validates critical outputs and queries Azure directly
# for any that are missing.
- name: Validate and recover provisioned outputs
shell: bash
run: |
set -euo pipefail
ENV="${{ inputs.environment }}"
RG="${{ inputs.projectName }}-${ENV}-rg"
# Install ALB CLI extension for AGC recovery queries
az extension add --name alb --only-show-errors 2>/dev/null || true
# Load current azd env values
eval "$(azd env get-values -e "$ENV" | sed 's/^/export /')"
RECOVERED=0
AGC_RECOVERED=0
set_if_empty() {
local k="$1" v="$2"
azd env set "$k" "$v" -e "$ENV"
export "${k}=${v}"
echo " ✓ Recovered ${k}"
RECOVERED=$((RECOVERED + 1))
}
# ── PostgreSQL ─────────────────────────────────────────────
if [ -z "${POSTGRES_HOST:-}" ]; then
V=$(az postgres flexible-server list -g "$RG" \
--query "[0].fullyQualifiedDomainName" -o tsv 2>/dev/null || true)
[ -n "${V:-}" ] && set_if_empty POSTGRES_HOST "$V"
fi
if [ -z "${POSTGRES_ADMIN_USER:-}" ]; then
V=$(az postgres flexible-server list -g "$RG" \
--query "[0].administratorLogin" -o tsv 2>/dev/null || true)
[ -n "${V:-}" ] && set_if_empty POSTGRES_ADMIN_USER "$V"
fi
if [ -z "${POSTGRES_DATABASE:-}" ]; then
set_if_empty POSTGRES_DATABASE "holiday_peak_crud"
fi
if [ -z "${POSTGRES_AUTH_MODE:-}" ]; then
set_if_empty POSTGRES_AUTH_MODE "password"
fi
if [ -z "${POSTGRES_USER:-}" ]; then
if [ "${POSTGRES_AUTH_MODE:-password}" = "password" ]; then
set_if_empty POSTGRES_USER "${POSTGRES_ADMIN_USER:-crud_admin}"
else
set_if_empty POSTGRES_USER "${{ inputs.projectName }}-${ENV}-crud-identity"
fi
fi
# ── Cosmos DB ──────────────────────────────────────────────
if [ -z "${COSMOS_ACCOUNT_URI:-}" ]; then
V=$(az cosmosdb list -g "$RG" \
--query "[0].documentEndpoint" -o tsv 2>/dev/null || true)
[ -n "${V:-}" ] && set_if_empty COSMOS_ACCOUNT_URI "$V"
fi
if [ -z "${COSMOS_DATABASE:-}" ]; then
set_if_empty COSMOS_DATABASE "holiday-peak-db"
fi
# ── Key Vault ──────────────────────────────────────────────
if [ -z "${KEY_VAULT_URI:-}" ]; then
V=$(az keyvault list -g "$RG" \
--query "[0].properties.vaultUri" -o tsv 2>/dev/null || true)
[ -n "${V:-}" ] && set_if_empty KEY_VAULT_URI "$V"
fi
# ── Redis ──────────────────────────────────────────────────
if [ -z "${REDIS_HOST:-}" ]; then
V=$(az redis list -g "$RG" \
--query "[0].name" -o tsv 2>/dev/null || true)
[ -n "${V:-}" ] && set_if_empty REDIS_HOST "$V"
fi
# ── Event Hubs (main namespace, not platform-jobs) ─────────
if [ -z "${EVENT_HUB_NAMESPACE:-}" ]; then
V=$(az eventhubs namespace list -g "$RG" \
--query "[?ends_with(name, '-eventhub')].name | [0]" -o tsv 2>/dev/null || true)
[ -n "${V:-}" ] && set_if_empty EVENT_HUB_NAMESPACE "$V"
fi
# ── Application Insights ───────────────────────────────────
if [ -z "${APPLICATIONINSIGHTS_CONNECTION_STRING:-}" ]; then
V=$(az monitor app-insights component list -g "$RG" \
--query "[0].connectionString" -o tsv 2>/dev/null || true)
[ -n "${V:-}" ] && set_if_empty APPLICATIONINSIGHTS_CONNECTION_STRING "$V"
fi
# ── Storage ────────────────────────────────────────────────
if [ -z "${BLOB_ACCOUNT_URL:-}" ]; then
V=$(az storage account list -g "$RG" \
--query "[0].name" -o tsv 2>/dev/null || true)
if [ -n "${V:-}" ]; then
set_if_empty BLOB_ACCOUNT_URL "https://${V}.blob.core.windows.net"
fi
fi
# ── AI Search ──────────────────────────────────────────────
if [ -z "${AI_SEARCH_NAME:-}" ]; then
V=$(az search service list -g "$RG" \
--query "[0].name" -o tsv 2>/dev/null || true)
[ -n "${V:-}" ] && set_if_empty AI_SEARCH_NAME "$V"
fi
if [ -z "${AI_SEARCH_ENDPOINT:-}" ] && [ -n "${AI_SEARCH_NAME:-}" ]; then
set_if_empty AI_SEARCH_ENDPOINT "https://${AI_SEARCH_NAME}.search.windows.net"
fi
if [ -z "${AI_SEARCH_INDEX:-}" ]; then
set_if_empty AI_SEARCH_INDEX "catalog-products"
fi
if [ -z "${AI_SEARCH_VECTOR_INDEX:-}" ]; then
set_if_empty AI_SEARCH_VECTOR_INDEX "product_search_index"
fi
if [ -z "${AI_SEARCH_INDEXER_NAME:-}" ]; then
set_if_empty AI_SEARCH_INDEXER_NAME "search-enriched-products-indexer"
fi
if [ -z "${EMBEDDING_DEPLOYMENT_NAME:-}" ]; then
set_if_empty EMBEDDING_DEPLOYMENT_NAME "text-embedding-3-large"
fi
if [ -z "${AI_SEARCH_AUTH_MODE:-}" ]; then
set_if_empty AI_SEARCH_AUTH_MODE "managed_identity"
fi
# ── AI Services ────────────────────────────────────────────
if [ -z "${AI_SERVICES_NAME:-}" ]; then
V=$(az cognitiveservices account list -g "$RG" \
--query "[?kind=='AIServices'] | [0].name" -o tsv 2>/dev/null || true)
[ -n "${V:-}" ] && set_if_empty AI_SERVICES_NAME "$V"
fi
# ── AI Project ─────────────────────────────────────────────
if [ -z "${PROJECT_NAME:-}" ]; then
V=$(az resource list -g "$RG" \
--resource-type "Microsoft.MachineLearningServices/workspaces" \
--query "[?kind=='Project'] | [0].name" -o tsv 2>/dev/null || true)
[ -n "${V:-}" ] && set_if_empty PROJECT_NAME "$V"
fi
if [ -z "${PROJECT_ENDPOINT:-}" ] && [ -n "${AI_SERVICES_NAME:-}" ] && [ -n "${PROJECT_NAME:-}" ]; then
set_if_empty PROJECT_ENDPOINT \
"https://${AI_SERVICES_NAME}.services.ai.azure.com/api/projects/${PROJECT_NAME}"
fi
# ── Application Gateway for Containers (AGC) ──────────────
# AGC outputs are critical for validate-agc-readiness, sync-apim,
# and sync-apic jobs. Recover from Azure CLI when azd env refresh
# returns empty values due to ARM deployment state being Failed.
VNET_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-vnet"
# Detect AGC support by checking for the agc subnet
if [ -z "${AGC_SUPPORT_ENABLED:-}" ] || [ "${AGC_SUPPORT_ENABLED}" != "true" ]; then