Skip to content

Lab 17: Validate and deploy infrastructure with Bicep

Previous: Lab 16 · Catalog · Next: Lab 18

Scenario, role, and outcome

The team needs an infrastructure change that can be compiled, previewed, deployed, and independently checked in one owned resource group.

Learner role: Infrastructure delivery engineer. Outcome: Validate and deploy infrastructure with Bicep.

Item Value
Time 120 minutes
Domain pipelines
Platforms local, azure
Cost billable; explicit acknowledgement — review current pricing and cleanup before cloud execution
Exam blueprint July 27, 2026; sources reviewed October 16, 2026
Verification status offline-tested
Verification scope All five checkpoint commands, final validators and named fault/repair passed in CourseReleaseSequences.Tests.ps1. Local .NET publishing/tests, EF SQL generation and Bicep compilation are real; GitHub, Azure and readiness HTTP responses are explicit fail-closed doubles. Live release, SQL authentication and traffic routing have not run.

Completion requires all five checkpoints, the break/fix repair, successful independent validation, and a passing residual-resource audit. An unavailable external prerequisite is a visible gate; it does not become a passing result.

Architecture and service topology

Lab 17 service architecture: Bicep deployment through ARM into an owned group

PowerShell compiles Bicep and sends validate, what-if, and explicit deployment requests to ARM at the exact owned resource-group scope. The core creates a hardened StorageV2 account and user-assigned managed identity. Independent control-plane reads compare security properties and identity outputs with the local manifest; no public storage data access or SQL dependency is needed for this core.

The editable Mermaid source and accessible SVG render the same authored components and relationships. Dashed connections show separately gated integrations. Read every boundary before executing commands. Cloud changes stay inside the exact disposable GitHub repository, Azure DevOps project, and Azure resource group recorded for this run. Child objects inherit that cleanup boundary. Account creation, external integrations, and privileged organization settings belong to one-time bootstrap.

Objectives and checkpoints

Coverage levels describe the intended learning evidence: explained means reasoned understanding, practiced means an observable isolated skill, and integrated means skills connected across a delivery boundary. These labels are curriculum claims, not execution status. Verification above records what authors actually ran.

Official objective topic IDs: D3.5.3, D3.5.4

Checkpoint Measurable behavior
CP1 Compile the independent core infrastructure
CP2 Validate and preview the exact owned-group changes
CP3 Deploy the reviewed storage and identity core
CP4 Assert the deployed security properties from service reads
CP5 Check declared identity and capture post-deployment drift preview

The objective map traces every official topic to labs. The Microsoft study guide controls authoritative objective wording and domain weighting.

Inputs, permissions, and read-only preflight

Use PowerShell 7.4+, .NET 10, Git, GitHub CLI, Azure CLI with the Azure DevOps extension, and the pinned repository validation dependencies. Read the permissions matrix and evidence policy. Supply only the accounts needed by this lab. Never put a token, connection string, or private key into a command log, committed YAML, or progress export.

The examples run from the repository root. Choose a fresh lowercase run ID; demo01 is an example, not a reusable shared sandbox. Set bootstrap environment variables for the approved GitHub owner, DevOps organization, subscription, and region. Do not run both guided and automated lanes with the same run ID.

$lab = './labs/17-bicep-infrastructure/scripts/cli'
& "$lab/Preflight.ps1" -RunId 'demo01'
& "$lab/Setup.ps1" -RunId 'demo01' -ProvisionOnly
# After reviewing context, permissions, cost, and cleanup:
& "$lab/Setup.ps1" -RunId 'demo01' -ProvisionOnly -Execute -AcknowledgeCost -AcknowledgeTenantChange
. "$lab/Context.ps1" -RunId 'demo01'

Preflight performs reads only. Provisioning creates fresh run-owned top-level sandboxes and records their exact IDs. Context establishes $RepoRoot, $LabRoot, $WorkRoot, $RunId, $GhRepo, $AdoOrganization, $AdoProject, $SubscriptionId, $Location, and $ResourceGroup. A missing prerequisite or ownership mismatch must stop execution. Local build commands may restore packages and write ignored build output.

Concept primer and design decisions

Bicep describes desired ARM state; what-if previews changes but does not grant approval. The core deploys isolated Storage and a managed identity; advanced main.bicep has separate SQL/network prerequisites.

Compile validates Bicep syntax and types; ARM validation checks the request; what-if previews a particular scope; deployment changes the provider state. These are separate gates. Use the journal-owned resource group and explicit subscription on every operation.

The independent core deploys a secure StorageV2 account and user-assigned identity. Storage data-plane access is disabled deliberately, so service reads validate control-plane security and ownership rather than requiring a public network path. The advanced application template is a separate SQL/network exercise. Reapplying the same declarative core should preserve resource identity and repair permitted tag drift.

Task 1 — Compile the independent core infrastructure

Checkpoint: CP1

Foundation/supporting task; no additional exam-objective coverage is claimed.

$file=Join-Path $LabRoot 'artifacts/core.bicep';az bicep lint --file $file
 az bicep build --file $file --outfile (Join-Path $WorkRoot 'core.json')
 if($LASTEXITCODE -ne 0){throw 'Core Bicep compilation failed.'}

Expected state: The core template compiles to exactly a storage account and an RG-contained identity.

Positive validation:

$t=Get-Content (Join-Path $WorkRoot 'core.json') -Raw|ConvertFrom-Json
 if(@($t.resources).Count -ne 2){throw 'Unexpected core resource count.'}

Negative validation:

$t=Get-Content (Join-Path $WorkRoot 'core.json') -Raw|ConvertFrom-Json
 if('Microsoft.Sql/servers' -in $t.resources.type -or 'Microsoft.KeyVault/vaults' -in $t.resources.type){throw 'Core must not create database or soft-delete vault prerequisites.'}

Evidence to retain: Compiled template SHA and resource-type allowlist.

Common failure and safe retry: Use core.bicep for the independent lane; main.bicep is the advanced SQL-integrated workload.

Cleanup dependency: retain this checkpoint's evidence until final validation; remove run-owned children before their recorded parent boundary.

Task 2 — Validate and preview the exact owned-group changes

Checkpoint: CP2

Foundation/supporting task; no additional exam-objective coverage is claimed.

$file=Join-Path $LabRoot 'artifacts/core.bicep'
 az deployment group validate --subscription $SubscriptionId --resource-group $ResourceGroup --template-file $file --parameters "labRunId=$RunId" -o json|Set-Content (Join-Path $WorkRoot 'template-validation.json')
 az deployment group what-if --subscription $SubscriptionId --resource-group $ResourceGroup --template-file $file --parameters "labRunId=$RunId" --result-format FullResourcePayloads -o json|Set-Content (Join-Path $WorkRoot 'what-if.json')

Expected state: ARM validates the core inputs and what-if lists only changes scoped to the run-owned group.

Positive validation:

$w=Get-Content (Join-Path $WorkRoot 'what-if.json') -Raw|ConvertFrom-Json
 if($w.status -ne 'Succeeded'){throw 'What-if did not succeed.'}

Negative validation:

$w=Get-Content (Join-Path $WorkRoot 'what-if.json') -Raw|ConvertFrom-Json
 $prefix="/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroup/"
 if(@($w.changes|Where-Object { $_.resourceId -notlike "$prefix*" }).Count){throw 'What-if escaped owned scope.'}

Evidence to retain: What-if resource IDs/change types and validation outcome.

Common failure and safe retry: Stop on unexpected deletes, SKU changes, or scope. A successful what-if is a preview, not deployment authorization.

Cleanup dependency: retain this checkpoint's evidence until final validation; remove run-owned children before their recorded parent boundary.

Task 3 — Deploy the reviewed storage and identity core

Checkpoint: CP3

Objective Evidence level Observation and limits
D3.5.3 integrated Apply the reviewed Bicep deployment and assert exact owned resource IDs and outputs.
$file=Join-Path $LabRoot 'artifacts/core.bicep'
 az deployment group create --subscription $SubscriptionId --resource-group $ResourceGroup --name "core-$RunId" --mode Incremental --template-file $file --parameters "labRunId=$RunId" -o json|Set-Content (Join-Path $WorkRoot 'core-deployment.json')
 if($LASTEXITCODE -ne 0){throw 'Owned core deployment failed; retain partial-state manifest.'}

Expected state: The declared two-resource core reaches Succeeded inside the owned group.

Positive validation:

$d=az deployment group show --subscription $SubscriptionId --resource-group $ResourceGroup --name "core-$RunId" -o json|ConvertFrom-Json
 if($d.properties.provisioningState -ne 'Succeeded'){throw 'Core deployment not successful.'}

Negative validation:

$d=az deployment group show --subscription $SubscriptionId --resource-group $ResourceGroup --name "core-$RunId" -o json|ConvertFrom-Json
 if($d.properties.mode -ne 'Incremental'){throw 'Unexpected destructive complete-mode deployment.'}

Evidence to retain: Deployment ID, result, template digest, and explicit parameter/run identity.

Common failure and safe retry: Inspect deployment operations before retry; retain owned group so cleanup can recover partial resource creation.

Cleanup dependency: retain this checkpoint's evidence until final validation; remove run-owned children before their recorded parent boundary.

Task 4 — Assert the deployed security properties from service reads

Checkpoint: CP4

Foundation/supporting task; no additional exam-objective coverage is claimed.

$d=Get-Content (Join-Path $WorkRoot 'core-deployment.json') -Raw|ConvertFrom-Json;$o=$d.properties.outputs
 az storage account show --subscription $SubscriptionId --ids $o.storageAccountId.value -o json|Set-Content (Join-Path $WorkRoot 'deployed-storage.json')
 az identity show --subscription $SubscriptionId --ids $o.identityId.value -o json|Set-Content (Join-Path $WorkRoot 'deployed-identity.json')

Expected state: Storage enforces HTTPS/TLS, disables shared keys/public networking, and matches the declared identity output.

Positive validation:

$d=Get-Content (Join-Path $WorkRoot 'core-deployment.json') -Raw|ConvertFrom-Json
 $s=az storage account show --subscription $SubscriptionId --ids $d.properties.outputs.storageAccountId.value -o json|ConvertFrom-Json
 if(-not $s.enableHttpsTrafficOnly -or $s.minimumTlsVersion -ne 'TLS1_2' -or $s.tags.'az400-run' -ne $RunId){throw 'Storage hardening or ownership mismatch.'}

Negative validation:

$d=Get-Content (Join-Path $WorkRoot 'core-deployment.json') -Raw|ConvertFrom-Json
 $s=az storage account show --subscription $SubscriptionId --ids $d.properties.outputs.storageAccountId.value -o json|ConvertFrom-Json
 if($s.allowSharedKeyAccess -or $s.publicNetworkAccess -ne 'Disabled'){throw 'Storage exposed a denied access path.'}

Evidence to retain: Queried storage settings and identity principal, with IDs redacted for sharing.

Common failure and safe retry: Control-plane assertions need no storage data access; public-network denial is intentional.

Cleanup dependency: retain this checkpoint's evidence until final validation; remove run-owned children before their recorded parent boundary.

Task 5 — Check declared identity and capture post-deployment drift preview

Checkpoint: CP5

Objective Evidence level Observation and limits
D3.5.4 practiced Read the storage account run tag and detect actual drift against the desired run ownership.
$file=Join-Path $LabRoot 'artifacts/core.bicep'
 az deployment group what-if --subscription $SubscriptionId --resource-group $ResourceGroup --template-file $file --parameters "labRunId=$RunId" -o json|Set-Content (Join-Path $WorkRoot 'what-if-after.json')
 $d=Get-Content (Join-Path $WorkRoot 'core-deployment.json') -Raw|ConvertFrom-Json
 [ordered]@{deployment=$d.id;coreTemplateSha=(Get-FileHash (Join-Path $WorkRoot 'core.json')).Hash;advancedSqlLane='not executed; separate SQL/network prerequisites'}|ConvertTo-Json|Set-Content (Join-Path $WorkRoot 'iac-evidence.json')

Expected state: Independent identity reads agree with outputs, and post-deployment what-if is available for drift review.

Positive validation:

$d=Get-Content (Join-Path $WorkRoot 'core-deployment.json') -Raw|ConvertFrom-Json
 $m=az identity show --subscription $SubscriptionId --ids $d.properties.outputs.identityId.value -o json|ConvertFrom-Json
 if($m.principalId -ne $d.properties.outputs.identityPrincipalId.value -or $m.tags.'az400-run' -ne $RunId){throw 'Identity output/ownership mismatch.'}

Negative validation:

$w=Get-Content (Join-Path $WorkRoot 'what-if-after.json') -Raw|ConvertFrom-Json
 if(@($w.changes|Where-Object changeType -eq 'Delete').Count){throw 'Unexpected destructive post-deployment drift.'}

Evidence to retain: Before/after what-if, output assertions, and explicit advanced-lane status.

Common failure and safe retry: Investigate noisy provider defaults separately from real drift; never treat all Modify output as harmless.

Cleanup dependency: retain this checkpoint's evidence until final validation; remove run-owned children before their recorded parent boundary.

Deterministic break/fix

Run the journaled operation after all five checkpoints. It proves the healthy assertion, injects the named fault, requires its rejection, repairs it, and proves health again. Provider doubles used in author tests are not live enforcement evidence.

& './labs/17-bicep-infrastructure/scripts/cli/BreakFix.ps1' -RunId 'demo01' -Execute

Expected rejection marker: AZ400-L17-FAULT. The assertion must catch the changed behavior, not merely an exception from an unavailable CLI.

Inspect the independent assertion:

$d=Get-Content (Join-Path $WorkRoot 'core-deployment.json') -Raw|ConvertFrom-Json;$s=az storage account show --subscription $SubscriptionId --ids $d.properties.outputs.storageAccountId.value -o json|ConvertFrom-Json
if($s.tags.'az400-run' -ne $RunId){throw 'AZ400-L17-FAULT'}

Fault trigger (executed by BreakFix):

$d=Get-Content (Join-Path $WorkRoot 'core-deployment.json') -Raw|ConvertFrom-Json
az tag update --subscription $SubscriptionId --resource-id $d.properties.outputs.storageAccountId.value --operation Merge --tags az400-run=wrong-run -o none

Diagnose the precise difference:

$d=Get-Content (Join-Path $WorkRoot 'core-deployment.json') -Raw|ConvertFrom-Json
az storage account show --subscription $SubscriptionId --ids $d.properties.outputs.storageAccountId.value --query tags -o json

Repair (executed by BreakFix):

az deployment group create --subscription $SubscriptionId --resource-group $ResourceGroup --name "repair-$RunId" --template-file (Join-Path $LabRoot 'artifacts/core.bicep') --parameters "labRunId=$RunId" -o none

Optional job-style challenge

Execute advanced main.bicep only with separately approved Entra SQL/database users, network prerequisites, federation, pricing, and a vault soft-delete residual audit; no prerequisite means this advanced integration stays partial.

Final validation and result interpretation

& './labs/17-bicep-infrastructure/scripts/cli/Validate.ps1' -RunId 'demo01'

A complete result requires five passing read-only checkpoint assertions, a journaled repaired fault, and any required integration evidence. Pending hosted runs, missing licensed features, and unexecuted integration lanes remain visible. Review validation.json; successful command exit alone does not establish the asserted behavior.

Troubleshooting

  • 401/403: inspect the explicit account/project/repository scope and required role; do not broaden a token reflexively.
  • Resource or artifact missing: confirm the exact run ID and prerequisite checkpoint; retry reads after eventual consistency.
  • Unsupported SKU/runtime/tool: consult the specific current source, record the gate, and obtain approval before changing cost or architecture.
  • Validation mismatch: inspect the positive and negative assertions separately, repair the named fault, and rerun validation.
  • Ownership refusal: stop; never edit a manifest to claim an unrelated resource.

Cleanup and residual checks

& './labs/17-bicep-infrastructure/scripts/cli/Cleanup.ps1' -RunId 'demo01'
# Review the exact owned-object deletion plan first.
& './labs/17-bicep-infrastructure/scripts/cli/Cleanup.ps1' -RunId 'demo01' -Execute

Cleanup must verify ownership, delete only recorded sandbox objects in dependency order, and prove parent/child absence. Retain run.json, validation.json, and cleanup.json locally until the audit passes. Soft-deleted or deliberately retained items must remain reported. Never purge a shared vault or delete an account, organization, or pre-existing service connection to finish a lab.

Exam debrief and assessment

Explain why each checkpoint's denied path matters, which scope authorizes it, what evidence proves it, and how it is reversed. Complete the 50-question assessment, then review rationales and repeat weak checkpoints.

Microsoft and platform sources

Lifecycle scripts and worked solution

Use scripts/cli/Preflight.ps1, Setup.ps1, BreakFix.ps1, Integration.ps1 (capstones), Validate.ps1, Cleanup.ps1, and Context.ps1 from this lab folder. Setup and cleanup preview until -Execute; -ProvisionOnly creates only fresh ownership-tracked containers. The worked solution lists expected results and repair reasoning.