Define Cloud Infrastructure with Pulumi Using Best Practices and Modular Components

Generate a modular Pulumi IaC program with reusable components, secret management, least-privilege IAM, and environment configuration.

πŸ“ The Prompt

Write a Pulumi infrastructure-as-code program in [LANGUAGE] (TypeScript, Python, Go, or C#) that provisions the following resources on [CLOUD_PROVIDER] (AWS, Azure, or GCP): **Resources to create:** - [RESOURCE_LIST] (e.g., VPC with public/private subnets, ECS Fargate service, RDS PostgreSQL instance, S3 bucket with lifecycle policies, CloudFront distribution) **Architecture requirements:** - The application serves [APPLICATION_DESCRIPTION] and expects [TRAFFIC_PATTERN] (e.g., ~1000 RPM with spikes to 5000) - Target environment: [ENVIRONMENT] (dev/staging/production) - Region: [REGION] **Pulumi best practices to follow:** 1. **Modular Design**: Create reusable ComponentResource classes for logical groupings (e.g., NetworkStack, DatabaseStack, AppStack). Each component should accept a typed args interface/class and expose relevant outputs. 2. **Configuration**: Use Pulumi.Config for environment-specific values like [CONFIG_VALUES] (e.g., instance sizes, replica counts, domain names). Provide a Pulumi.[STACK].yaml example. 3. **Security**: - Use Pulumi secrets for [SENSITIVE_VALUES] (e.g., database passwords, API keys) - Apply least-privilege IAM roles/policies - Enable encryption at rest and in transit where applicable - No hardcoded credentials anywhere 4. **Networking**: Implement proper network isolation with security groups/firewall rules allowing only necessary traffic between components. 5. **Outputs**: Export essential values (endpoints, ARNs, connection strings) using pulumi.export() with descriptive names. 6. **Tags**: Apply consistent tagging strategy: Environment, Project=[PROJECT_NAME], ManagedBy=Pulumi, CostCenter=[COST_CENTER]. Provide the complete project structure (file tree), all source files, and a README with prerequisites and deployment commands (`pulumi up` workflow).

πŸ’‘ Tips for Better Results

Specify your exact cloud provider and language upfrontβ€”Pulumi's API surface differs significantly across providers and SDKs. Use ComponentResource classes to encapsulate related resources so your main program reads like an architecture diagram. Always run `pulumi preview` and review the diff carefully before applying, especially for stateful resources like databases.

🎯 Use Cases

Cloud engineers and platform teams use this when bootstrapping new infrastructure projects or migrating from Terraform/CloudFormation to Pulumi, especially when they want strongly-typed, modular, and testable infrastructure 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.