Define Cloud Infrastructure with Pulumi Using TypeScript or Python

Create a Pulumi infrastructure program with reusable components, stack configs, secrets management, and multi-environment support.

๐Ÿ“ The Prompt

Write a Pulumi program in [LANGUAGE] (TypeScript or Python) that provisions the following cloud infrastructure on [CLOUD_PROVIDER] (AWS, Azure, or GCP): **Target Architecture**: [ARCHITECTURE_DESCRIPTION] (e.g., a containerized web app with a load balancer, managed database, and CDN; a serverless API with Lambda, API Gateway, and DynamoDB). Requirements: 1. **Project Structure**: - Organize resources into logical modules/files: networking, compute, database, and monitoring. - Use a `Pulumi.dev.yaml` and `Pulumi.prod.yaml` stack configuration for environment-specific values like instance sizes, replica counts, and feature flags. - Read configuration values using `pulumi.Config()` rather than hardcoding. 2. **Core Resources**: - Provision [RESOURCE_LIST] (e.g., VPC with public/private subnets, ECS service, RDS instance, S3 bucket). - Enable encryption, logging, and monitoring by default. - Use [CLOUD_PROVIDER]'s managed services where possible. 3. **Reusable Components**: - Create at least one Pulumi `ComponentResource` class for [COMPONENT_NAME] (e.g., a `WebService` that bundles an ALB, ECS service, and target group) with configurable properties. - Show how to instantiate this component multiple times with different configurations. 4. **Secrets and Config**: - Store sensitive values (database passwords, API keys) using `pulumi.Config().requireSecret()`. - Pass secrets to resources without exposing them in plain text in state. 5. **Outputs and Stack References**: - Export key outputs: endpoint URLs, resource IDs, connection strings. - Show how another Pulumi stack can consume these outputs using `StackReference`. 6. **Error Handling**: - Add input validation for component arguments. - Use `pulumi.log` for informational messages during deployment. Include inline comments explaining design decisions and a README snippet describing how to deploy with `pulumi up`.

๐Ÿ’ก Tips for Better Results

Specify your preferred language clearly โ€” Pulumi's TypeScript and Python APIs differ significantly in patterns and idioms. Describe your target architecture in detail in [ARCHITECTURE_DESCRIPTION] to get properly connected resources instead of isolated ones. Use `pulumi preview` to validate the generated code before deploying.

๐ŸŽฏ Use Cases

Platform engineers and full-stack developers use this when they prefer defining infrastructure in a general-purpose programming language with type safety, loops, and conditionals instead of declarative HCL.

๐Ÿ”— Related Prompts

๐Ÿ’ป Coding beginner

Explain Code Like Im a Beginner

Get any code explained in plain English with line-by-line breakdowns, analogies, and learning suggestions.

๐Ÿ’ป Coding beginner

Debug My Code and Explain the Fix

Get your code debugged with clear explanations of what went wrong and why, plus the corrected version.

๐Ÿ’ป Coding intermediate

Write Unit Tests for My Code

Generate thorough unit tests covering edge cases, error handling, and both positive and negative scenarios.

๐Ÿ’ป Coding intermediate

Convert Code Between Languages

Convert code between any programming languages while maintaining idiomatic patterns and best practices.

๐Ÿ’ป Coding intermediate

Write a REST API Endpoint

Generate production-ready REST API endpoints with validation, error handling, and documentation.

๐Ÿ’ป Coding advanced

Create a GitHub Actions CI/CD Workflow for Automated Testing and Deployment

Generate a complete GitHub Actions CI/CD workflow with build, test, deploy, and notification jobs for your project.