skip to content

Your organisation's Terratest suites apply real infrastructure into sandbox accounts: who should own those accounts and their bill, and what standing rules would you set?

level: principalimportance: should knowfreq 27%

answer

  1. paying versus operating
  2. shared, per team or per run
  3. leaks bill until noticed
  4. guardrails belong to one owner
  5. revisit when the signals change

basics

~20 s

A common answer: a platform team owns the sandbox accounts, guardrails and sweep, while each team writing tests sees and answers for its share of the bill. Standing rules cover isolation, naming, budgets, mandatory cleanup and leak reporting.

solid answer

~50 s

I separate operating from paying. A platform team usually owns the sandbox accounts as a product: isolation from production, the cleanup sweep, budget alerts and the credentials tests use. Teams writing tests own their spend and their leaks, because if the platform absorbs the whole bill nobody has a reason to shrink a fixture. The model depends on scale: one shared sandbox is cheap until contention and unattributable costs bite, per-team accounts make the bill legible but multiply the guardrails, and an account per run gives the strongest isolation for the most machinery. Whichever I choose, the rules stay the same: no production credentials, per-run names with an owner marker, a deferred destroy with a realistic `-timeout`, a scheduled sweep and a named person on every budget alert. I revisit it when the bill outgrows test volume or contention causes failures.

go deeper

for a junior

Recall that these tests create real, billable resources, that they belong in an account separate from production, and that someone has to notice when cleanup fails.

for a middle

Explain how per-run names, a deferred destroy and a realistic timeout keep your own suite cheap, and what your team would do when a budget alert names it.

for a senior

Argue for specific guardrails from failures you have seen: sweep age limits, owner markers, budget alerts, and how a leak gets traced back to the suite that caused it.

for a principal

Weigh shared, per-team and per-run accounts against your scale. Separate who operates the sandbox from who pays, say what would make you change the model, and accept that attribution has a cost.

Live-account tests spend real money and call real cloud APIs, so someone has to own the place they run. No answer fits every organisation, and what follows is how a lead might weigh it. How accounts get created and how often suites run are separate decisions; here they are inputs. Terratest is the example, but the reasoning applies to any tool that drives real applies from code. ## What is at stake - **The bill.** Resources cost money from apply until destroy, and a leak costs money until someone notices. - **Blast radius.** Tests can make destructive changes, which is why Terratest's docs strongly recommend an environment totally separate from production, such as a separate AWS account. - **Contention.** Suites in one account share its quotas, so one team's leak can fail another team's apply. - **Credentials.** A test has to create and delete many resource types, so its credentials are powerful and should be useless outside the sandbox. ## Three ownership models | Model | Strength | Weakness | Tends to fit | |---|---|---|---| | One shared sandbox, run by a platform team | Cheap to run; one sweep and one budget | Contention; costs hard to attribute; one leak affects everyone | A few module authors | | One sandbox per team | The bill is legible; a team feels its own leaks | Guardrails, sweeps and alerts repeated per account | Several teams with their own modules | | A short-lived account per suite or run | Strongest isolation; removing the account clears everything | Setup overhead and slower starts; needs mature automation | High test volume | These are stages more than rivals. Many organisations start with the first and move on when it hurts. ## Separate operating from paying The question usually conflates two jobs, and they pull in different directions. - **Operating sits best with one owner.** If each team runs its own sweep, budget alerts and credentials, some will skip them, and the gap only shows when a bill arrives. A platform team can treat the sandbox as a product with a clear contract. - **Paying sits best near the people who decide.** If the platform absorbs the whole bill, a module team has no reason to shrink its fixture or fix its leaks. Showing each team its share, even without a real internal charge, changes that. The weakness of this split is that it needs attribution. Without an owner marker on every resource, a shared account's costs cannot be divided and the second half collapses. That cost is what often pushes a growing organisation towards per-team accounts. ## Standing rules Whichever model you pick, a lead can make these non-negotiable: 1. **No path to production.** Test credentials cannot reach a production account, and tests do not run there. 2. **Identifiable resources.** Every resource carries a per-run ID, through `random.UniqueID()` or similar, plus an owner marker such as a name prefix or tag. 3. **Baseline cleanup in every test.** A deferred destroy registered before the apply, and a `go test -timeout` that fits the suite. 4. **A scheduled sweep in every sandbox.** Terratest's docs describe a nightly cloud-nuke run in the maintainers' test account. It must spare anything younger than the longest allowed test. 5. **A budget alert with a named person.** An alert nobody owns is a line in a log. 6. **Leaks treated as defects.** The sweep reports what it removed, and repeated leaks from one suite go back to the team that owns it. ## Keeping the bill down Cost mostly follows how long resources live and how large they are. - **Test a small example, not production size.** Expose sizes as variables so a test fixture can be small. The trade-off is that a small fixture can miss a problem only large sizes show. - **Do not mistake availability for price.** Terratest's `aws.GetRecommendedInstanceTypeContext` returns the first listed type available in all of a region's Availability Zones. List the cheap types first, because it does not compare prices. - **Watch local stages.** `SKIP_teardown` saves deployment time and keeps expensive resources alive, so the sweep's age limit is what eventually catches a forgotten one. ## When to revisit Reopen the decision when the bill grows faster than test volume, which usually means leaks or oversized fixtures, when teams fail on each other's quotas, or when one team needs an isolation or compliance boundary the shared account cannot give.

  • A team objects that an account-level sweep once deleted a Terratest run in progress. How do you respond?
    That is a configuration fault in the sweep, and it should not lead to removing it. Set the age limit longer than the longest allowed test, which `go test -timeout` already bounds, and schedule the sweep away from peak test times. If some suites legitimately run far longer, split them into their own account rather than weakening the limit for everyone.
  • When would you move from one shared Terratest sandbox to per-team accounts?
    When contention produces failures that look like test defects, when you can no longer say which team caused a cost, or when one team's permissions or data needs differ. Before that, a shared account is cheaper to run. Expect to pay in repeated guardrails, so automate the sweep and budget setup first.

  • Sandbox accounts need no owner because tests clean up after themselves.
  • If the platform team pays the whole bill, teams will still shrink their fixtures.
  • A shared production account is fine as long as test resource names are unique.
  • GetRecommendedInstanceTypeContext picks the cheapest instance type for a test.
  • An account per run is always the right model because it isolates best.