Pulumi Unit Testing with Resource Mocks Prompt
Write fast, offline unit tests for Pulumi programs using the runtime mocks API so you can assert resource properties and policy without ever hitting a cloud provider.
- Target user
- Developers writing Pulumi infrastructure in TypeScript, Go, or Python
- Difficulty
- Advanced
- Tools
- Claude, Copilot
The prompt
You are a senior Pulumi engineer who writes provider-free unit tests for infrastructure code. I will provide: - A Pulumi program or component (language: TypeScript, Python, or Go). - The invariants I want to enforce (required tags, encryption on, no public ingress, naming rules). - My test runner (Jest, pytest, or go test). Your job: 1. **Set up mocks** — implement the Pulumi mocks interface (`newResource`/`call`) so resources register synchronously with deterministic IDs and no real API calls. 2. **Resolve outputs** — show the correct pattern for unwrapping `Output<T>` values inside assertions (promise/apply or pulumi.all). 3. **Assert properties** — write tests checking the invariants against the mocked resource inputs. 4. **Test components** — exercise a custom ComponentResource and assert its child resources and exported outputs. 5. **Cover negative cases** — add tests that fail when a misconfigured resource (open security group, untagged bucket) is created. 6. **Mock provider calls** — stub `pulumi.runtime.invoke`/`call` results (e.g. AMI lookups) for determinism. 7. **Speed and CI** — keep the suite under a few seconds and give the CI invocation. Output as: (a) the mock-setup module, (b) the test file with positive and negative cases, (c) the runner command, (d) a note on what these tests cannot catch (real provider drift). Flag any assertion that depends on apply-time values that the mock cannot resolve.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Pulumi Secrets Provider Migration & Key Rotation Prompt
Migrate a Pulumi stack's secrets provider (passphrase to KMS/Vault or between clouds) and rotate the encryption key so all encrypted config and state secrets are re-wrapped without leaking plaintext.
-
Pulumi Transformations & Aliases Refactor Prompt
Refactor Pulumi resource names, parents, and structure at scale using aliases and stack transformations so URNs change on paper but no live resource is destroyed or replaced.
-
OpenTofu Native Test Framework Module Validation Prompt
Build a real test suite for a reusable OpenTofu module using the native `tofu test` framework — combining fast plan-only assertions, targeted apply-and-verify runs, mocked providers, and variable-validation coverage into a CI gate that catches regressions before they reach state.
-
Pulumi Refresh & Drift Remediation Prompt
Detect and safely reconcile out-of-band drift between a Pulumi stack's state and live cloud reality — deciding per resource whether to adopt, revert, or ignore the change without triggering an unwanted replace.
More Infrastructure as Code prompts & error guides
Browse every Infrastructure as Code prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.