Working from Cloud Shell
Every repo runs from Azure Cloud Shell in PowerShell, even on a tablet. These are the house rules for doing that safely.
More
Most of the rules below came out of real runs that failed, and each one links to the lesson or decision in the repo that owns it. This page states the conventions. The code stays in the repos.
One block, pasted into a clean prompt
Every command is one block that does everything itself. Wait for a clean prompt, then paste it once.
More
- Every command we give is one self-contained block. It clones the repo or updates it, moves into it, signs in if needed, and then runs the step. Nothing depends on a variable, folder or sign-in left over from an earlier session, because Cloud Shell sessions are ephemeral and disconnect when the tab loses focus (landing zone lesson 0015).
- No placeholders to fill in. The deployment portal writes the block with your values already in
it. A block with
<your-value>in it gets pasted unchanged sooner or later. - Paste into a clean prompt. Cloud Shell opens PowerShell. Wait for the prompt, and paste once. In the browser terminal, the copy shortcut can turn into a cancel, so use the menu or a right-click to copy.
- Each script prints its next command and a line before anything slow, so a session that drops can pick up from where it stood.
Pin what you run
Pin a script to a tag or commit, so you run exactly what you read.
More
- A block that clones a repo can pin it to a tag or commit. The portal does this for a published copy, so a run can be repeated exactly.
- For a single script fetched with
Invoke-WebRequestfromraw.githubusercontent.com, prefer a commit SHA in the URL overmain. Reading the script before you run it is cheaper than diagnosing a changed one afterwards.
Nothing is kept in the shell
Cloud Shell forgets everything, so where a run stands comes from Azure and anything you keep goes somewhere durable.
More
- Cloud Shell keeps files only in
~/clouddrive(and the$HOMEimage), and only when a storage account is mounted. An ephemeral session keeps nothing, and every session ends after about 20 minutes without input (Cloud Shell FAQ). - So where a run stands comes from Azure, not from the shell: deployment history, resource groups, tags. Long operations run as ARM deployments, which keep going when the session drops, and the scripts say how to check on them.
- Anything you need to keep goes somewhere durable before the session ends. That means a
mounted
~/clouddrive, a download, or the run store (next section). - Hitting the limits? What Cloud Shell keeps, and when to use GitHub Codespaces, a small VM or your own PC instead, is in Cloud Shell and its alternatives.
Session state, logs and resuming
Each step ends with a state line you paste into the portal, and a dropped session picks up where it left off.
More
The landing zone's run recorder holds these conventions. It's opt-in, and the default deployment doesn't change.
- A state line closes every step. Each script ends with one machine-readable line,
<<<AVDLZ-STATE {...} AVDLZ-STATE>>>. You paste the output into the deployment portal, and the portal reads that line to show the next step (decision 0007). - "Where did I leave off?" reads Azure.
Get-AvdRunStatus.ps1works out the last stage from deployment history and the resource groups, and prints a state line, so a reset shell or a second device picks up at the right step. While a deployment is still running, the answer is "wait and check again", never a second deploy. Anything the script can't place is reported asunknown, not guessed. - One run ID for the whole run. The portal generates it once (
run-yyyyMMdd-HHmm-xxxx), and every block sets$env:AVDLZ_RECORDand$env:AVDLZ_RUN_IDagain. A command run after a Cloud Shell reset still writes to the same journal. - A structured journal, not a screen scrape. When recording is on, each script appends events
as it runs: step start and end, each check result, API errors with status, code, body and
correlation ID, and notes you add yourself. Secrets are written as
<set>or<unset>, never as values. - The run store lives outside the deployment. It's one storage account per subscription, in
its own resource group. Journals, transcripts and teardown logs go there, so tearing down a
landing zone never takes its own evidence with it. Logs are kept by default
(
-TeardownLogs Keep). - Redact before anything leaves the tenant, and fail closed. If redaction can't run, nothing is uploaded or shared (Redact before you share).
Sign in once, and check it
Sign in to Graph once per session, and check which tenant and subscription you're in before anything writes.
More
- Cloud Shell signs you in to Azure. Microsoft Graph is a separate sign-in. The landing zone signs
in to Graph once per session with one set of scopes that every later script reuses
(
Connect-AvdLandingZone.ps1, decision 0016). - Never hide the output of
Connect-MgGraph, because the device code goes to that stream. Check a sign-in with a real request before trusting it (lesson 0007). - Check which tenant and subscription you're in before anything writes. The scripts take a subscription ID and switch to it, instead of trusting whatever context the shell had.
Read first, fix on request
Scripts only read, unless you pass -Fix. When a call fails, they print everything it returned.
More
- Checks are read-only by default. Preflight before you deploy, postflight after. A script changes
something only when you pass
-Fixand it says what it changes. - When an Azure or Graph call fails, the scripts print everything it returned: step, HTTP status, error code, body and correlation ID (lesson 0012).
Cloud Shell can't reach private endpoints
For a private Key Vault or profile share, use the opt-in jumpbox through Bastion Developer.
More
Cloud Shell sits outside the landing zone's network, so it can't reach a private Key Vault or an
SMB-only profile share. For those steps, the landing zone offers an opt-in jumpbox reached through
Bastion Developer
(decision 0019,
Connect-AvdJumpbox.ps1).
Costs
Price before you deploy, keep a budget, and prove after teardown that nothing is left billing.
More
- Price before you deploy. The pre-deployment preflight prices the landing zone from live retail prices. Every cost line must match exactly one price meter, or it lists the meters it saw. A price is never guessed (decision 0010, lesson 0025).
- A run estimate is an upper bound. Session hosts are priced as running for every hour of the run, everything else is prorated by the hour, and 20% is added for what the preflight lists as usage-based (Log Analytics, data processed, Defender). The estimate also gives the daily cost if the deployment is not torn down.
- Check caps before deploying. A run is refused if it's over a per-run cap, if it would push the month's actual spend past a monthly cap, or if a line couldn't be priced. Once a few runs of the same kind have settled, the check scales the estimate by how far past estimates were off, so estimates that run low stop letting runs through.
- Actual cost comes later. Cost Management lags up to three days. A run's actual cost is the cost of its resource groups from the start day to three days after teardown, and it's provisional until then. Charges after that day mean something was left behind.
- Teardown evidence is a diff. Before deploying, record every resource and resource group in the subscription. After teardown, compare again. Anything new is a leftover, and the run isn't done until it's gone or recorded as kept on purpose.
- Keep a standing budget on any sandbox subscription, one that teardown doesn't delete. The landing zone's preflight warns when a dev or test landing zone has none.
Leave nothing billing, delete nothing you can't get back
When a run ends, nothing keeps billing, and no data is deleted without a copy somewhere else.
More
- Never leave the meter running. Anything that bills by time is removed, stopped or on a schedule at the end of a run, unless you opt in with an expiry (decision 0017).
- Never delete the last copy. Teardown keeps logs and evidence by default, and deleting data
needs a checked copy elsewhere or an explicit
-DiscardLastCopy(decision 0016). - Estimate first, then keep teardown evidence: what was removed, and that nothing is left. Running several test runs this way is described in sandbox batches.
Where the helpers live
The helpers stay in avd-landing-zone and avd-current-state. There's no shared kit to install.
More
These stay in their repos. avd-landing-zone and avd-current-state are a self-contained pair, so neither depends on a shared kit.
| Helper | Repo |
|---|---|
| Block builder (clone or update, pin, record) | avd-landing-zone, deployment portal |
| Cloud Shell detection, subscription guard, REST wrappers with full errors | avd-landing-zone scripts/ops/AvdLandingZone.psm1 |
| One Graph sign-in per session | avd-landing-zone Connect-AvdLandingZone.ps1 |
| Run recorder, run store and "Where did I leave off?" | avd-landing-zone scripts/ops/ |
| Cost estimate and preflight pricing | avd-landing-zone preflight (decision 0010) |
| Redaction | avd-landing-zone scripts/ops/redact.mjs |
Read-only collector and validator, output to ~/clouddrive |
avd-current-state |
Linked from 9 pages
- Sandbox batches
- Control-plane modules
- Stand up and use an estate vault
- Lab walkthrough: empty subscription to validated landing zone
- Size with avd-migrate, benchmark with avd-benchmark, and check client networks
- Keep your files in Cloud Shell
- Cloud Shell and its alternatives
- A small Linux VM as your shell
- The repos