Reviewing AI-Generated Pulumi Programs: The Bugs a Terraform Checklist Won’t Catch

Rows of server racks in a data center

A Terraform review checklist looks for things like an unreviewed terraform apply diff, a hardcoded credential sitting in a .tf file, or a module pinned to a mutable version. It will not catch what goes wrong in an AI-generated Pulumi program, because Pulumi programs are written in a real programming language — TypeScript, Python, Go, or C# — and compile down to the same kind of resource graph a declarative file would, while failing in ways a declarative file structurally cannot. The checks below are the ones that matter specifically because the infrastructure code is also just code.

None of this replaces the general discipline of reviewing AI-written Terraform as a draft, not a plan to apply. It adds to it. A reviewer who only knows the Terraform failure modes — unpinned providers, drifted state, a missing lifecycle block — will sign off on a Pulumi program that has none of those problems and still ships a leaked secret or a resource count that changes between environments.

A secret marked with --secret can still leak through the resource ID

Pulumi encrypts any config value you set with pulumi config set --secret dbPassword 'S3cr37', so it never appears as plaintext in the stack’s state file. What it cannot protect is a resource’s id field: Pulumi’s own documentation states that resource IDs are always stored in plaintext in the state file, and that marking an output as secret has no effect on the ID. The concrete trap is random.RandomString, whose generated value becomes the resource’s ID — in plaintext — even if the assistant wrapped the output in additionalSecretOutputs. The fix the documentation recommends is random.RandomPassword instead, which does not expose its value through the ID.

  • Search the diff for RandomString anywhere near a password, token, or key — it is almost always the wrong primitive once the value matters.
  • Check whether additionalSecretOutputs is being used to paper over a resource whose ID is the secret itself; no secret-output flag fixes that.

An apply() callback can print the secret it was supposed to protect

Every Pulumi output — plain value, Output<T>, or Promise — eventually has to be read inside a callback to do anything with it, and Pulumi’s documentation is explicit that it “cannot guarantee that the apply callback itself will not expose the secret value.” An AI assistant debugging a failing program will often insert a console.log or a string interpolation inside exactly that callback to see what the value actually is, then leave it in once the program works. The secret then shows up in plaintext in CLI output, and in CI, in build logs that are frequently far less access-controlled than the stack’s encrypted state.

Grep the diff for .apply( or .then( chained onto anything that traces back to a secret config value or a secret output, and read what the callback body actually does with the argument before approving the change. The same scrutiny applies to a pulumi env open call anywhere in a script, since Pulumi ESC prints secrets as plaintext JSON by design — useful for a human debugging locally, dangerous left inside an automated script’s output.

--plaintext is the easy way out when a config value won’t parse

pulumi config set --plaintext aws:region us-west-2 is the correct call for a region name. It is also the call an assistant reaches for when a --secret value is throwing a type or encoding error it doesn’t want to debug, because switching to --plaintext makes the error go away. The result is a connection string, API token, or credential sitting unencrypted in Pulumi.<stack>.yaml, which gets committed to the same repository as everything else.

Diff the stack’s YAML config file directly rather than trusting the program code — a reviewer who only reads the TypeScript or Python will never see this, because the leak is entirely in a file the program just reads from. The same pattern deserves the same secret-scanning discipline described in configuring Gitleaks as a pre-commit hook: a pre-commit scanner catches a plaintext config value exactly as well as it catches a hardcoded key in application code.

A StackReference that compiles cleanly can still resolve to nothing

A StackReference is how one Pulumi stack reads another stack’s exported outputs — new pulumi.StackReference("acmecorp/infra/networking") in TypeScript, StackReference("acmecorp/infra/networking") in Python — and it is how most multi-stack Pulumi setups wire a shared VPC or database into the stacks that depend on it. Reading an output from it has two forms with different failure behavior: getOutput("vpcId") resolves to undefined if the referenced stack never exported that key, while requireOutput("vpcId") throws immediately if it’s missing. An assistant writing code that has to “just work” during iteration tends to reach for getOutput, because it never interrupts a build — and that same leniency means a renamed export, a stack that hasn’t been deployed yet, or a typo in the output key quietly wires undefined into whatever resource consumes it, instead of failing where the mistake actually is.

Check every getOutput call in AI-generated code and ask whether a missing value should fail loudly — in nearly every case outside of truly optional configuration, it should, which means it belongs on requireOutput instead. Separately, remember that these outputs are Output or Promise values in TypeScript, Python, and Go — they only resolve after the dependent update runs, and have to be read through .apply() rather than used directly, a step HCL-based Pulumi programs don’t need. Code that treats a StackReference output as an immediately available string will type-check in a dynamically typed language and fail only at runtime.

A clean pulumi preview is not the same guarantee as a clean Terraform plan

By default, pulumi up runs a preview first and asks for confirmation before applying — --skip-preview (or -f) turns that off, and -y skips only the confirmation prompt. What a reviewer has to understand is what that preview can and cannot see. Pulumi’s own update-plans documentation (marked experimental) states that a value unknown at preview time is recorded simply as "unknown", and — the part that matters most for review — any resource created inside an apply() callback whose input is unknown at preview time is not recorded in the plan at all. It shows up, and can only fail, once the actual update runs. A plan-constrained update also fails immediately on any discrepancy rather than applying part of the change, which is a different failure mode than Terraform’s partial-apply-and-report behavior.

Practically: when an AI-generated program chains resource creation inside .apply() — a common pattern for “create resource B using an ID that only exists after resource A is up” — the preview a reviewer is looking at may not include resource B at all. Approving a program on the strength of its preview output is only valid once the reviewer has confirmed nothing downstream of an unknown value was supposed to show up and didn’t.

Secrets providerSet withFits
Passphrase (default)pulumi stack init <name> with no --secrets-provider flagSolo, local development only
AWS KMS--secrets-provider="awskms://<key-id>"Teams already standardized on AWS KMS
Azure Key Vault--secrets-provider="azurekeyvault://<vault>"Teams already standardized on Azure Key Vault
Google Cloud KMS--secrets-provider="gcpkms://<key>"Teams already standardized on GCP KMS
HashiCorp Vault--secrets-provider="hashivault://<server>" plus VAULT_SERVER_URL and VAULT_SERVER_TOKENTeams already running Vault

No --secrets-provider flag means an AI-generated setup script defaults to passphrase

An assistant asked to scaffold a new stack will usually write pulumi stack init production and stop there, because that’s the command that works without asking the user for anything else. Left unspecified, that stack uses the default passphrase-based local encryption provider — fine for one developer’s throwaway stack, not fine for a stack several people and a CI pipeline will touch, where a shared passphrase becomes one more credential to rotate and distribute by hand. pulumi stack change-secrets-provider "<secrets-provider>" switches an existing stack to one of the KMS-backed providers in the table above without re-encrypting every secret by hand. Any AI-generated bootstrap script for a shared or production stack that doesn’t pass --secrets-provider explicitly should be treated as incomplete, not as a style preference.

A real language means resource counts can depend on runtime data, not just a variable

Terraform’s count and for_each meta-arguments are declarative — a reviewer can always find the exact expression that determines how many of a resource get created. Pulumi has no equivalent meta-argument, because a program can just write a for loop over whatever array it has in scope, and that array can come from a static config file, from a StackReference output, or from an API call the program itself made earlier in the same run. A review checklist built around “check for hardcoded counts” has nothing to look for here, because there’s no dedicated syntax to grep — the question that matters is where the loop’s source array comes from, and whether that source is guaranteed to look the same during preview and during up. The same discipline that applies to reviewing AI-drafted GitHub Actions workflows and to checking an AI-generated Kubernetes manifest before kubectl apply applies here too: trace every generated value back to its actual source before trusting what the tool shows you, rather than trusting the tool’s summary of its own output.

Running the checklist

  • Diff Pulumi.<stack>.yaml directly for any --plaintext value that looks like a credential, token, or connection string.
  • Grep the program for RandomString next to anything security-sensitive, and for any .apply( or .then( that logs, writes, or interpolates a value derived from a secret.
  • Confirm every getOutput call on a StackReference should really tolerate a silent undefined, or switch it to requireOutput.
  • Read pulumi preview output while asking what’s inside an apply() callback that the preview can’t see yet.
  • Confirm the stack has an explicit --secrets-provider if more than one person or a CI pipeline will ever run it.
  • Trace every loop that creates a variable number of resources back to where its source array actually comes from.

Most of this still ends in a human sign-off, the same way reviewing an AI-generated pull request does for application code — a Pulumi program just hides its riskiest behavior one layer further down, inside callbacks and loops that look like ordinary code because they are ordinary code.

Sources

Data center photo: “Racks Amravati Data Center” by PiDatacenters, licensed CC BY-SA 4.0, via Wikimedia Commons.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top