Pulumi ComponentResource Children Not Created
In this tutorial, you'll learn about Pulumi ComponentResource Children Not Created. We cover key concepts, practical examples, and best practices.
A Pulumi ComponentResource children are not created or the component returns unexpected outputs.
Wrong ❌
// Wrong: ComponentResource without registering children
export class MyComponent extends pulumi.ComponentResource {
constructor(name: string, opts?: pulumi.ComponentResourceOptions) {
super("my:component:MyComponent", name, {}, opts);
// Children created without proper parent/child relationship
const bucket = new aws.s3.Bucket(`${name}-bucket`);
const queue = new aws.sqs.Queue(`${name}-queue`);
}
}
Wrong Output
pulumi preview
+ aws:s3:Bucket "my-bucket"
+ aws:sqs:Queue "my-queue"
# Note: resources are not nested under the component in the state
# They appear as top-level resources
Right ✅
export class MyComponent extends pulumi.ComponentResource {
public readonly bucket: aws.s3.Bucket;
public readonly queue: aws.sqs.Queue;
constructor(name: string, opts?: pulumi.ComponentResourceOptions) {
const defaults = { parent: this };
super("my:component:MyComponent", name, {}, { ...opts, ...defaults });
// Children created with parent reference
this.bucket = new aws.s3.Bucket(`${name}-bucket`, {}, { parent: this });
this.queue = new aws.sqs.Queue(`${name}-queue`, {}, { parent: this });
// Register outputs
this.registerOutputs({
bucketName: this.bucket.bucketName,
queueUrl: this.queue.url,
});
}
}
Right Output
pulumi preview
+ my:component:MyComponent "my-infra"
+ aws:s3:Bucket "my-infra-bucket"
+ aws:sqs:Queue "my-infra-queue"
Outputs:
bucketName: output<string>
queueUrl: output<string>
Prevention
- Always pass { parent: this } to child resources created inside a ComponentResource.
- Call registerOutputs() with the component's outputs for proper dependency tracking.
- Expose child resources as public properties for external access.
- Use the ComponentResourceOptions to forward provider and dependsOn to the component.
- Wrap async initialization in an async factory pattern when the component needs async setup.
DodaTech applies similar defensive patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro infrastructure for production reliability.
Common Mistakes with component resource
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists - Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad
These mistakes appear frequently in real-world PULUMI code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
This quick fix is part of the DodaTech infrastructure engineering series. Learn more at DodaTech tutorials.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro