Define Cloud Infrastructure with Pulumi Using Programming Language Constructs

Generate a complete Pulumi infrastructure program with reusable components, stack configs, and cloud best practices in your language.

๐Ÿ“ The Prompt

Write a Pulumi program in [LANGUAGE (e.g., TypeScript, Python, Go, C#)] that provisions [INFRASTRUCTURE_DESCRIPTION (e.g., a Kubernetes cluster with managed node groups, a serverless API with Lambda and API Gateway, a data pipeline with S3, Glue, and Athena)] on [CLOUD_PROVIDER (e.g., AWS, Azure, GCP)]. Project Setup: - Pulumi project name: [PROJECT_NAME] - Stack names: [STACKS (e.g., dev, staging, prod)] - State backend: [BACKEND (e.g., Pulumi Cloud, S3, Azure Blob)] Infrastructure Requirements: 1. **Networking**: [NETWORK_DETAILS (e.g., VPC with 3 public and 3 private subnets across AZs, or use existing VPC ID)]. 2. **Compute/Service**: [COMPUTE_DETAILS (e.g., EKS 1.28 with t3.medium nodes, min 2 max 10 autoscaling)]. 3. **Storage**: [STORAGE_DETAILS (e.g., encrypted S3 bucket with lifecycle rules, RDS with automated backups)]. 4. **Security**: [SECURITY_DETAILS (e.g., IAM roles with OIDC, security groups, KMS keys for encryption)]. Code Structure โ€” generate the following: 1. **Pulumi.yaml** and **Pulumi.[STACK].yaml**: Project definition and per-stack configuration values. 2. **index.ts / __main__.py / main.go**: Main infrastructure code organized with: - ComponentResource classes/functions that encapsulate related resources into reusable abstractions. - Pulumi Config for stack-specific settings (instance sizes, feature flags, domain names). - Strong typing for all resource inputs and outputs. - Proper use of `pulumi.Output` transformations and `apply()` for derived values. 3. **config.ts / config.py**: Centralized configuration loading with defaults and validation. 4. **Stack outputs**: Export all critical endpoints, ARNs, and connection strings. Best Practices to Follow: - Use `ComponentResource` to group related resources and avoid monolithic code. - Implement tagging via a helper function that applies standard tags to all resources. - Handle secrets using `pulumi.secret()` and never hardcode credentials. - Add `protect: true` for stateful resources (databases, storage). - Include error handling for missing configuration values. Provide the complete, runnable code with comments explaining the Pulumi-specific patterns used (Output chaining, ComponentResource lifecycle, stack references).

๐Ÿ’ก Tips for Better Results

Specify your preferred language in [LANGUAGE] since Pulumi's patterns differ significantly between TypeScript and Python. Use ComponentResource to break infrastructure into testable units โ€” treat them like classes in application code. Always set `protect: true` on databases and persistent storage to prevent accidental deletion during stack updates.

๐ŸŽฏ Use Cases

Platform engineers and full-stack developers use this when they prefer defining infrastructure with familiar programming languages instead of DSLs, especially for complex deployments requiring loops, conditionals, and reusable abstractions.

๐Ÿ”— 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.