You need to build an internal developer platform that provisions infrastructure on-demand via an API (not CLI). How do you use the Pulumi Automation API to create a self-service infrastructure provisioning system?
Quick Answer
The Pulumi Automation API embeds Pulumi's deployment engine as a library, allowing you to create, configure, and deploy stacks programmatically from application code. Build a REST API that accepts infrastructure requests, runs `stack.up()` asynchronously, and returns status via webhooks or polling.
Detailed Answer
What is the Automation API
The Pulumi Automation API is a programmatic interface to Pulumi's engine, available in TypeScript, Python, Go, and C#. Instead of running pulumi up from the CLI, you call LocalWorkspace.createOrSelectStack() and stack.up() from your application code. This enables building platforms, CI/CD integrations, and self-service portals that provision infrastructure without shelling out to CLI commands.
Architecture of a Self-Service Platform
Build a REST API (Express/FastAPI/Go) that accepts infrastructure requests (e.g., 'create a dev environment with RDS and Redis'). The API validates the request, creates a Pulumi stack with the appropriate configuration, runs stack.up() asynchronously in a background worker, and stores the deployment status in a database. Users poll for status or receive a webhook callback when provisioning completes. Each user's environment gets its own Pulumi stack for isolation.
Key Automation API Features
Inline programs let you define infrastructure as a function passed directly to the Automation API, rather than requiring a separate Pulumi project directory. Stack configuration is set programmatically via stack.setConfig(). You can stream deployment logs in real-time by passing a callback to stack.up({ onOutput: callback }). The stack.outputs() method retrieves outputs after deployment. stack.destroy() and stack.workspace.removeStack() handle cleanup.
Production Considerations
Run deployments in isolated workers (Kubernetes Jobs or Lambda) to prevent one deployment from affecting others. Implement request queuing (SQS/Redis) to handle burst traffic. Set deployment timeouts. Store stack state in a shared backend (Pulumi Cloud or S3) accessible from any worker. Implement RBAC to control who can provision what. Add cost estimation by running stack.preview() before stack.up() and parsing the resource count.