Define Cloud Infrastructure with Pulumi Using Best Practices

Generate a well-structured Pulumi infrastructure-as-code program with networking, compute, database, and security best practices.

๐Ÿ“ The Prompt

Write a Pulumi program in [LANGUAGE] (TypeScript, Python, Go, or C#) to provision the following cloud infrastructure on [CLOUD_PROVIDER] for a [APPLICATION_DESCRIPTION]: **Resources to create:** - [RESOURCE_LIST] (e.g., VPC with public/private subnets, ECS Fargate service, RDS PostgreSQL instance, S3 bucket, CloudFront distribution) **Architecture Requirements:** 1. **Networking**: Create a VPC with [NUMBER_OF_AZS] availability zones, public subnets for load balancers, private subnets for compute and databases. Include NAT Gateway for outbound internet from private subnets. 2. **Compute**: Deploy [COMPUTE_TYPE] (e.g., ECS Fargate, Lambda, EKS, GKE) running [CONTAINER_IMAGE_OR_RUNTIME] with auto-scaling configured for min [MIN_INSTANCES] to max [MAX_INSTANCES] based on [SCALING_METRIC]. 3. **Data**: Provision [DATABASE_TYPE] with [INSTANCE_SIZE], automated backups with [RETENTION_DAYS]-day retention, encryption at rest, and placement in private subnets only. 4. **Security**: - Least-privilege IAM roles/policies for each service - Security groups restricting traffic to only necessary ports - Secrets stored in [SECRETS_MANAGER] and referenced dynamically - Enable encryption in transit and at rest for all applicable resources **Pulumi Best Practices:** - Organize resources using `ComponentResource` classes for logical grouping - Use `pulumi.Config` for environment-specific values (instance sizes, counts) - Export critical outputs (endpoints, ARNs, connection strings) via `pulumi.export` - Apply consistent tagging: `project`, `environment`, `managed-by: pulumi` - Use `dependsOn` only when implicit dependencies are insufficient - Include a `Pulumi.dev.yaml` stack config example Structure the code in separate files: `index.[ext]` for orchestration, `networking.[ext]`, `compute.[ext]`, and `database.[ext]` for resource modules. Add docstrings explaining architectural decisions.

๐Ÿ’ก Tips for Better Results

Specify exact resource sizes and counts in placeholders to get cost-appropriate infrastructure. Always define your target environment (dev/staging/prod) since resource configurations differ significantly. Test the generated code with `pulumi preview` before applying to catch dependency or permission issues early.

๐ŸŽฏ Use Cases

Cloud engineers and platform teams provisioning repeatable, version-controlled infrastructure for new services or migrating existing manually-created resources to infrastructure as code.

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