Component resources & reuse
Package infra into classes.
A ComponentResource packages several resources into one reusable, higher-level building block — the Pulumi equivalent of a module, but expressed as a class. You subclass pulumi.ComponentResource, create the child resources in the constructor, parent them to the component, and expose a clean set of outputs. Consumers instantiate your class and get a whole vetted pattern (a bucket with logging, encryption, and public-access blocks) in one line.
export class SecureBucket extends pulumi.ComponentResource {readonly bucket: aws.s3.BucketV2;constructor(name: string, opts?: pulumi.ComponentResourceOptions) {super("acme:storage:SecureBucket", name, {}, opts);this.bucket = new aws.s3.BucketV2(name, {}, { parent: this });new aws.s3.BucketServerSideEncryptionConfigurationV2(`${name}-enc`, {bucket: this.bucket.id,rules: [{ applyServerSideEncryptionByDefault: { sseAlgorithm: "aws:kms" } }],}, { parent: this });new aws.s3.BucketPublicAccessBlock(`${name}-block`, {bucket: this.bucket.id, blockPublicAcls: true, blockPublicPolicy: true,ignorePublicAcls: true, restrictPublicBuckets: true,}, { parent: this });this.registerOutputs({ bucketId: this.bucket.id });}}
Use it like any class
Now a secure bucket is a one-liner, and because it is real code you distribute it like any package — an npm/PyPI module your teams import. Components are how an organization encodes its golden paths: the secure, tagged, logged defaults become the easy option, so doing the right thing is less typing than doing the wrong thing.
import { SecureBucket } from "./securebucket";const logs = new SecureBucket("logs"); // encrypted + private by constructionconst data = new SecureBucket("data");