Skip to main content

Pulumi TypeScript Infrastructure

Build cloud infrastructure using Pulumi with TypeScript — leveraging real programming constructs for loops, conditionals, and abstractions.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Build infrastructure using Pulumi with TypeScript for a containerized microservices platform on AWS. The stack serves ECS Fargate services with ALB and RDS with 99.9% with multi-AZ availability requirements. Implement: 1) Pulumi project structure: Pulumi.yaml, Pulumi.<stack>.yaml for dev, staging, production, index.ts as entry point, and a /components directory for custom ComponentResources. 2) A ComponentResource class for FargateService that encapsulates ECS Task Definition, Service, Target Group, ALB Listener Rule, CloudWatch Log Group, IAM Role — accept typed configuration via an interface, set proper parent/child relationships, and expose outputs as pulumi.Output<T>. 3) Use TypeScript features that Terraform cannot: map/filter over a services config array, generating ECS service + ALB rules + DNS for each to generate resources programmatically, use async/await for fetching latest AMI ID, looking up existing resources by tag, and implement NAT Gateway only in production, Redis cluster only if cache_enabled in config with real if/else instead of count hacks. 4) Stack configuration using pulumi.Config with typed getters, secret values for database password, API keys for third-party services, and environment-specific defaults. 5) Stack references to share outputs between stacks: VPC ID and subnet IDs from network stack, RDS endpoint from database stack — use StackReference with proper typing. 6) Custom providers for Datadog monitors and dashboards alongside AWS resources where native cloud resources are insufficient. 7) Testing using @pulumi/pulumi/testing — unit tests that mock cloud providers and verify resource properties match expectations for security group does not allow 0.0.0.0/0, ECS tasks have memory limits, all S3 buckets are encrypted. Run with Jest.

What this prompt does

This prompt builds cloud infrastructure with Pulumi and TypeScript for [infrastructure_purpose] on [cloud_provider], serving [application_type] with [availability_requirement] availability. It lays out the project structure (Pulumi.yaml, per-stack config for [stack_names], index.ts as entry point, and a components directory) and a typed ComponentResource class for [component_name] that encapsulates [component_resources] with proper parent/child relationships and exposes outputs as pulumi.Output<T>.

The distinguishing point is using real language features Terraform's HCL lacks: map/filter over [dynamic_resources] to generate resources programmatically, async/await for [async_operations], and genuine if/else for [conditional_logic] instead of count hacks. It uses typed pulumi.Config getters, secret values for [secret_configs], typed StackReference for [cross_stack_outputs], custom providers for [custom_provider_needs] where native resources fall short, and unit tests via @pulumi/pulumi/testing that mock the cloud provider to verify [test_scenarios], run with [test_framework]. The payoff is infrastructure expressed as ordinary typed code, where loops, conditionals, and abstractions read the way the rest of your application does.

When to use it

  • You need loops or conditionals that HCL makes awkward (generating per-service resources)
  • You want typed, reusable ComponentResources with real interfaces
  • You need async lookups (latest AMI, resource-by-tag) during provisioning
  • You want true if/else conditional infrastructure instead of count tricks
  • You need to share outputs between stacks with type safety
  • You want unit tests that mock the cloud and assert resource properties
  • Your team already knows TypeScript and prefers it over learning HCL idioms
  • You want secrets typed and encrypted in config rather than passed around as plain strings

Example output

The AI returns the Pulumi project layout, a ComponentResource class for [component_name] exposing pulumi.Output<T> outputs, map/filter loops generating [dynamic_resources], async/await examples for [async_operations], typed Config usage with secrets, StackReference code for [cross_stack_outputs], and [test_framework] unit tests mocking the provider for [test_scenarios]. Expect TypeScript code blocks grouped by the seven concerns, with typed interfaces so misuse is caught at compile time.

Pro tips

  • Model [dynamic_resources] as a typed config array and map over it, so adding a service is a one-line data change
  • Use async/await only where you genuinely need a lookup ([async_operations]); overusing it complicates the resource graph
  • Express [conditional_logic] with real if/else and return different resources, which reads far cleaner than Terraform count hacks
  • Mark [secret_configs] as secrets in pulumi.Config so they're encrypted in state and config files
  • Type your StackReference outputs for [cross_stack_outputs] so a renamed output fails at compile time, not runtime
  • Set explicit parent relationships in your ComponentResource so the resource graph and previews stay readable
  • Reach for a custom provider in [custom_provider_needs] only when a native resource genuinely can't express what you need
  • Keep [test_scenarios] focused on security-relevant assertions (no 0.0.0.0/0, encryption on) where mocked tests add the most value

Frequently Asked Questions

What can Pulumi with TypeScript do that Terraform HCL can't here?
The prompt leverages real language constructs: map/filter to generate `[dynamic_resources]` programmatically, async/await for `[async_operations]` like AMI lookups, and genuine if/else for `[conditional_logic]` instead of Terraform's count-based workarounds. Typed interfaces and compile-time checks are additional benefits.
How does it share values between separate stacks?
It uses Pulumi StackReference with typing to read `[cross_stack_outputs]`, such as VPC and subnet IDs from a network stack or an RDS endpoint from a database stack. Typing these references means a renamed or removed output surfaces as a compile error rather than a runtime failure.
Are secrets handled safely in the config?
Yes. Values in `[secret_configs]` are stored as secrets via pulumi.Config, which encrypts them in the stack configuration and state. This keeps database passwords and third-party API keys out of plaintext config files committed to your repo.
Can I unit test the infrastructure without deploying it?
It includes tests using `@pulumi/pulumi/testing` that mock the cloud provider and assert resource properties for `[test_scenarios]`, run with `[test_framework]`. These verify things like security groups not allowing 0.0.0.0/0 and S3 buckets being encrypted, without creating real cloud resources.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Terraform & Infrastructure as Code Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support