Trace a Browser Request Through the Cloud
New to cloud infrastructure? Start with the request, not the product names. A browser asks DNS for the server's address, opens an encrypted connection, reaches a traffic director, and then talks to a running program. That program may read or write data. DNS is the name lookup, TLS is the encrypted connection, a load balancer is the traffic director, compute is where the program runs, and storage keeps data. A failure at each step has a different cause, so it helps to learn the path before trying to build it.
At 09:14 a developer opens https://api.sandbox.example.test/health and receives 200 OK in 84 ms. Six systems had to agree: a name resolved, a certificate validated, a port accepted a connection, a load balancer found a healthy target, a process answered, and a data store returned a row. Change any one and the same URL fails differently.
The browser starts with a name. The operating system's stub resolver forwards the question to a recursive resolver, which may answer from cache or walk from the root zone to the authoritative nameserver for example.test. That server returns an A record for IPv4 or AAAA for IPv6, plus a time to live (TTL); a CNAME points at another name and restarts the lookup. The TTL is a cache lifetime, not a propagation switch, and NXDOMAIN is an answer, not a network failure. The .test suffix is reserved for testing and examples, so it cannot collide with a real domain (RFC 2606).
With an address in hand, the browser opens TCP port 443 and starts a TLS handshake. The ClientHello carries the hostname in the server name indication (SNI) extension, so one address can serve many sites (RFC 6066). The server replies with a certificate, and the browser checks the chain of trust, the hostname, and the validity dates. TLS 1.3 then derives traffic keys and encrypts everything after the server hello, including the request (RFC 8446). TLS proves that the endpoint holds a certificate for that name. It does not prove that the business is honest, and it does not protect data after the load balancer decrypts it.
The request reaches a load balancer listener, which selects a target from a target group. A health check decides whether each target is eligible; a failing target leaves rotation, but only according to the check you configured. The compute target — a virtual machine, a container, or a function — handles the request on its listening port. If it needs data, it reads a cache, a database, or an object store. A cache miss is fast, a database timeout is slow, and an object-store permission error is neither.
The request also crosses a network you define. A virtual network is split into subnets; route tables decide where traffic goes, and security groups or firewall rules decide which ports may be reached. The load balancer usually sits in a public subnet and the target may sit in a private one. A missing route, or a rule that permits the browser but blocks the load balancer's health check, produces a failure that looks like a dead server.
Figure 1 traces the whole path and attaches the most common failure symptom to each hop.
flowchart TD
B["Browser"] -->|"1 DNS query"| R["Recursive resolver"]
R -->|"2 referral"| A["Authoritative nameserver"]
A -->|"3 A and AAAA records"| R
R -->|"4 address and TTL"| B
B -->|"5 TCP 443 with SNI"| E["Edge and TLS terminator"]
E -->|"6 verified certificate"| L["Load balancer"]
L -->|"7 healthy target"| C["Compute service"]
C -->|"8 read or write"| S["Cache, database or object store"]
A -.->|"name absent"| F1["NXDOMAIN"]
E -.->|"expired certificate"| F2["Browser blocks request"]
L -.->|"no healthy target"| F3["503 response"]
C -.->|"timeout or crash"| F4["502 or 504 response"]
The useful distinction is control plane versus data plane. The data plane is the request you just traced. The control plane is the set of API objects that decide how it is handled: the DNS record, the certificate, the listener, the target group, the compute service, and the bucket or database. Figure 2 places those objects next to the hops they configure. Terraform works almost entirely in the control plane; it does not sit in the request path.
The layered model also gives you a debugging order. NXDOMAIN means stop at DNS: the name does not exist. A certificate warning means stop at TLS: the name resolved, but the proof is wrong or expired. A 503 means the load balancer is reachable but has no healthy target. A 504 means the target accepted the connection and did not answer in time. A 500 means the application ran and failed on its own terms. None are interchangeable, and none is fixed by restarting the server.
A courier analogy keeps the layers separate. DNS is the address book. TLS is the nameplate and seal that verify the building before the package is handed over. The load balancer is reception, choosing which desk receives the delivery. Compute is the clerk; storage is the filing room. If the address is wrong, checking the clerk's desk does not help.
Managed services rename these layers but rarely remove them. A serverless function still has a name, a certificate, a routing rule, an execution role, and a data store. The vocabulary changes; the path does not. That is why the first Terraform configuration is not a bag of resources but control-plane objects whose attributes must agree.
Accounts, Regions and Identities Define the Boundary
An account is not a folder. In AWS it is an account, in Azure a subscription, in Google Cloud a project. Whatever the label, it is the boundary within which identities are defined, quotas are counted, bills are addressed, and API calls are authorized. Azure recommends separate subscriptions for development, testing, and production to prevent cross-environment dependencies and keep cost tracking honest (Microsoft Learn). The same reasoning applies: a sandbox belongs in its own boundary, not a folder inside production.
A region is a physical and legal choice. It determines distance to users, available services, price, and where data is stored. Availability zones within a region are independently powered and networked; spreading resources across them survives the loss of one building. Choose a region using latency, data residency, service availability, and recovery requirements, not whatever the tutorial used.
Identity is the part beginners underestimate. A principal is anything that can make an API call: a person, a service, a pipeline. Authentication answers who; authorization answers what it may do. A role is an identity assumed for a limited time, which is why short-lived credentials beat long-lived access keys. A policy grants or denies actions, optionally under conditions. Least privilege means the smallest set of actions on the smallest set of resources for the shortest time that still gets the job done (AWS IAM best practices).
Figure 3 shows the chain from a human to an API request, with the branches that produce the errors you will actually see.
flowchart TD
H["Human operator"] -->|"SSO and MFA"| I["Federated identity"]
I -->|"assume role"| P["Short-lived principal"]
P --> D{"Policy allows this action on this resource?"}
D -->|"no"| X1["AccessDenied"]
D -->|"yes"| R{"Resource in the selected region?"}
R -->|"no"| X2["Wrong-region lookup or residency breach"]
R -->|"yes"| A["API request accepted"]
A --> T["Resource created or changed"]
P -.->|"session expires"| X3["ExpiredToken"]
H -.->|"daily work in root or owner account"| X4["Unbounded blast radius"]
T -.->|"no owner or budget tag"| X5["Untracked spend"]
The sandbox should be boring on purpose. Use a separate account with no production data, no network peering to production, and no shared credentials. Require MFA for humans and short-lived credentials for automation. Name an owner and an expiry date. Restrict it to one region unless the exercise requires more. Attach a budget before the first resource exists, and tag every resource with at least owner, purpose, expires, and cost-center. A sandbox is disposable, but it is not anonymous.
The reason is not hypothetical. On 31 January 2017, a GitLab engineer meant to wipe a PostgreSQL data directory on the secondary database server; the command ran on the primary. Roughly 300 GB was removed before it was stopped, and the service was down for many hours. The engineer had permission; the target was misidentified (GitLab postmortem). GitLab's conclusion was not "add more warnings" but "an ideal environment is one in which you can make mistakes but easily and quickly recover from them with minimal to no impact." A disposable boundary buys that property.
A sandbox is not safe because nothing important lives in it. It can still generate a bill, exhaust a quota, expose a credential, or reach another network through a convenience peering rule. Isolation is a set of decisions, not a label.
Read Files, Environment Variables and Exit Codes
The shell is the execution surface for the rest of the series. Three habits are enough: know where you are (pwd), know what is set (printenv), and know what happened (the exit status).
Every process returns an integer from 0 to 255. Zero conventionally means success; anything else means failure. That is a convention, not a law: diff returns 1 for differences, and terraform plan -detailed-exitcode returns 0 for no changes, 1 for an error, and 2 for a successful plan with changes (Terraform plan). A script that treats every non-zero status as a crash will misread both.
Files are read with cat, inspected with ls -la and stat, and tested with [[ -f path ]]. Prefer printf '%s\n' "$value" over echo for values that may begin with a dash or contain backslashes, and use -- to end options. Quote every expansion unless you want word splitting or globbing: "$file" is one argument; $file can become several. Single quotes are literal, double quotes expand variables, and "$@" preserves arguments containing spaces. These rules prevent most quoting bugs.
Environment variables are strings inherited by child processes. owner="platform-team" exists only in the current shell; export owner makes it visible to programs the shell starts. Terraform later reads TF_VAR_<name>, so the mechanism returns. Treat environment variables as configuration, not as a secret store: children can read them, and they can end up in logs or crash reports. Never commit .env, and read a debug log before sharing it; TF_LOG output can contain request details.
The drill below is deliberately local. It creates a temporary directory, writes two small files, compares them, and exercises quoting and exit codes. It calls no cloud API and needs no credentials.
Run it with bash tf-drill.sh. The third block contrasts "owner=${name}" with 'owner=${name}'. The fifth prints a diff and reports exit 1 without aborting because the command sits in an if. The sixth shows the child sees the owner only after export. The seventh shows two arguments, not three. The last records Terraform's version if installed; later labs pin 1.17.1, but record what you run.
set -euo pipefail is a useful default, not a guarantee. -e stops on an unchecked failing command, but commands used in if, while, &&, or || are exempt by design. -u turns an unset variable into an error, which is why ${VAR:-default} appears above. -o pipefail makes a pipeline fail if any stage fails. On Windows, use WSL or Git Bash; the commands target bash 3.2, not PowerShell.
Use a Branch and Review the Infrastructure Diff
Git does not review infrastructure; people do, using the diff as the place where intent becomes visible. A branch gives review a stable name, a small commit a boundary, and a pull request a context where someone can ask why a security group now allows 0.0.0.0/0 before the change reaches an API.
Start with git switch -c sandbox/request-path. git status --short shows what is modified, staged, or untracked; git diff shows unstaged changes; git diff --staged shows the next commit. git add -p stages one hunk at a time, keeping a formatting cleanup separate from a behavior change. Then git add <path>, git commit -m "<intended effect>", and git push -u origin sandbox/request-path. Open a pull request. If you work alone, read the pull-request diff anyway.
Two diffs matter. The Git diff shows what you changed in configuration. The Terraform plan shows what Terraform proposes remotely, including replacements, destroyed resources, and values known only after apply. A one-line change can still replace a database. Review both, and re-check the final plan immediately before applying, because a speculative plan can be invalidated by later changes (Terraform plan).
Ignore generated and sensitive artifacts from the first commit. A practical .gitignore includes .terraform/, *.tfstate, *.tfstate.*, *.tfplan, tfplan, crash.log, crash.*.log, .env, .env.*, *.pem, and usually *.tfvars, with an !.env.example or terraform.tfvars.example exception. State can contain sensitive attribute values, and saved plan files contain the full configuration and planned values in cleartext, so neither belongs in Git. The exception is .terraform.lock.hcl: commit it so provider selections and checksums are reviewed like any other dependency change (HashiCorp).
Verify the rules. git check-ignore -v path/to/file prints the matching pattern and its source. A file already tracked stays tracked; git rm --cached path removes it from the index without deleting the copy. Figure 4 shows the review path and the failure route that begins with one committed secret.
The failure path deserves one more sentence. If a real credential reaches a remote, assume it is public. Deleting the commit or rewriting history reduces exposure but does not un-disclose what was fetched or indexed. Rotate the credential, revoke the session, check the audit log, then clean the repository. A clean git status proves artifacts stayed out of the change, not that nothing sensitive was typed.
Keep a pull request to one intention. Separate a mechanical rename from a behavior change. Put the plan summary in the description with identifiers removed. Reviewers who see intent and action together catch more than reviewers handed a 900-line diff.
Set a Budget and Write the Cleanup Checklist
Cost is a property of the design. Before a resource exists, predict what will bill: compute time, storage, public addresses, load balancer hours, managed databases, log retention, DNS queries, and data transfer out. Some bill while idle: a load balancer with no traffic bills hourly, an idle public address can still bill on some providers, a NAT gateway bills for existence and data processed, and a disk outlives its server. Check current pricing for your provider and region; a blog number is not a budget.
Service quotas are often regional and lower for new accounts, which is why a tutorial that works in an established account can fail in a fresh sandbox. Inventory what you need and request increases early; a support request is a scheduling dependency.
Tags make a shared bill attributable. Use owner, purpose, expires, and cost-center everywhere. Tags are metadata, not a security boundary, and not every resource supports them. Shared transfer, support fees, taxes, and untagged resources resist attribution. Treat the tag report as a signal and the bill as truth.
A budget alert is a notification, not a spending cap. AWS Budgets can notify on actual or forecast spend and trigger actions, but data updates a few times a day and can lag hours; existing resources keep running. Configure several thresholds, add an anomaly alert, and route it to someone who can act.
The cleanup checklist is part of the design:
- Run the documented destroy from the same configuration and state that created the resources.
- List the resources again through the console or API; do not assume success.
- Check orphans: unattached disks, snapshots, public addresses, load balancers, NAT gateways, DNS records, certificates, secret stores, and log groups.
- Check the billing page the next day, after data catches up.
- Revoke temporary credentials, delete lab access keys, and remove local credential files.
- Archive or securely remove local state and plan files; never attach them to a ticket.
- Close one-time sandbox accounts and remove their budgets and alerts.
- Record what was created, deleted, and left behind, with date and owner.
Prepare the sandbox
Lab status: design-only for the cloud portion; the local drill was executed. The shell and Git drill ran on macOS with bash 5.2.21 and Git 2.54.0; no cloud API was called and no resource was created. Later labs pin CLI 1.17.1 (verified 5 November 2026), but this lab does not require Terraform.
Prerequisites. Git 2.23+, bash 3.2+ on Linux, macOS, or WSL, a text editor, and a non-production cloud account or a documented plan for one. Never use production credentials or customer data.
Minimal setup. Create an empty directory, run git init, add the ignore patterns above, and create sandbox/README.md and sandbox/cleanup.md. No provider or cloud CLI is required locally.
Actions.
- Run the shell drill and record
bash --version,git --version, andterraform versionif installed insandbox/tooling.txt. - In
sandbox/README.md, record the account alias or a local label such assandbox-01(never the raw account, subscription, or tenant ID), region, owner, purpose, expiry, and budget thresholds. - Capture read-only identity and region evidence:
aws sts get-caller-identityandaws configure get region,az account showand location, orgcloud auth listandgcloud config get-value project. Redact identifiers; the evidence is that both are expected, not publishable. - Write
sandbox/cleanup.mdfrom the eight-step checklist with exact commands or console paths. - Create
sandbox/request-path, commit, and push. Open a pull request if you use a remote; otherwise reviewgit diffagainst the default branch. - Confirm that no
.env, state, plan, or credential file appears ingit status --short. - Create the cloud budget and alert before any resource, and set a reminder for the expiry date.
- Ask a reviewer to find the owner, region, budget, and cleanup route.
Expected observation. git status --short is empty after the commit; the tree contains only text; identity evidence shows the expected account and region with identifiers removed; and the cleanup file names a command for every billable object you might create.
Failure check. If git status --short shows state, a plan, .env, or a credential, stop. Run git rm --cached <path>, rotate any real credential, and fix the ignore rule. If identity shows the wrong account or region, correct the context first. If the budget alert cannot be created, do not create resources.
Cost dimensions. This lab provisions nothing. The optional account may have free-tier limits and verification requirements; no domain or certificate is needed. The real costs are your time and the risk of leaving an account without an owner.
Cleanup. Delete the drill directory (rm -rf -- "${TMPDIR:-/tmp}/tf-sandbox-drill"), remove temporary credentials, and close or hand over the account per policy. Nothing here needs terraform destroy.
Acceptance evidence. Clean git status; sandbox/tooling.txt; redacted identity and region evidence in sandbox/README.md; and a written sandbox/cleanup.md.
This is not ceremony. It establishes the three habits the series depends on: proving which identity and region you are talking to, seeing a change before it runs, and removing what you created. Those habits make a first terraform apply deliberate rather than hopeful.
Next in the Series
In Why Infrastructure as Code Changes the Workflow, we'll explore Compare repeatable infrastructure changes with manual provisioning and choose the right tool boundary.