Authoring a Source-Based Plugin Package
A source-based plugin package is a Pulumi plugin package distributed as source code rather than a pre-built executable. When a consumer runs pulumi package add against your repository or a local path, Pulumi introspects the package and generates an SDK in the consumer's language.
Source-based plugin packages are the recommended way to package and share components — they enable multi-language consumption with minimal authoring overhead. For a detailed comparison against the other ways to distribute components, see Packaging Components.
INFO
Source-based packages most commonly contain components, and the rest of this guide focuses on that case. When authoring in Go via pulumi-go-provider, a source-based package can also expose custom resources and functions (invokes); see Package contents by authoring language. For custom resources or functions in other languages, or for publishing to the public Pulumi Registry, author an executable-based plugin package instead.
The key wins of the source-based model are:
- Author in your language of choice, consume in any Pulumi language. You write the package once in TypeScript, Python, Go, .NET, or Java; consumers can use it from any supported Pulumi language, including YAML.
- No pre-publishing required. You don't have to build, version, and push per-language SDKs to npm, PyPI, NuGet, Maven, and Go module proxies — a git tag (or even a local path) is enough for consumers to use the package.
INFO
SDKs can still be pre-published for a source-based package, and some teams do so to avoid regenerating the SDK on every consumer's machine or committing the generated SDK to source control. This is uncommon in practice — for internal packages it typically requires maintaining a private package feed for every consumer language (private npm registry, private PyPI index, etc.), which is a large amount of infrastructure to stand up just to avoid local SDK generation. The common path is to generate the SDK locally at pulumi package add time.
This guide covers how to author a source-based plugin package: the minimum layout, an end-to-end walkthrough, per-language discovery rules, and per-language features.
For how consumers use the package in their programs, see the Components concept page. For writing the component code itself, see Build a Component.
Minimum plugin layout
Every source-based plugin package has four ingredients:
- A
PulumiPlugin.yamlmanifest declaring the authoring language. - A language-specific project manifest (
package.json,pyproject.toml,go.mod,.csproj, orpom.xml). - An entry file that the language host launches.
- One or more
ComponentResourcesubclasses.
A single plugin package can expose multiple components; you do not need one package per component. The discovery mechanism described below picks up every component in the package.
Walkthrough
This walkthrough shows the packaging flow end-to-end. The component implementation itself is intentionally left as a stub — for how to write a component, see Build a Component.
1. Create the plugin directory
mkdir my-components && cd my-components2. Write PulumiPlugin.yaml
runtime: nodejsSee the PulumiPlugin.yaml reference for all supported fields.
3. Assemble the plugin
Below is the minimum directory layout for a plugin containing one component. The shape of the component class itself is up to you — refer to Build a Component for authoring guidance. You can add more components to the same package without changing the entry file; they'll be picked up automatically (or via explicit registration, in Go).
my-components/
├── PulumiPlugin.yaml
├── package.json # the name field determines the generated SDK name
├── tsconfig.json
└── index.ts # entry file — exports your componentsindex.ts:
import * as pulumi from "@pulumi/pulumi";
export interface MyComponentArgs {}
export class MyComponent extends pulumi.ComponentResource {
constructor(name: string, args: MyComponentArgs, opts?: pulumi.ComponentResourceOptions) {
super("my-components:index:MyComponent", name, args, opts);
this.registerOutputs({});
}
}Exporting the class from the module named by main in package.json is all that's required — Pulumi auto-discovers it.
4. Consume the package from another project
Create a separate Pulumi program — in any supported language, not just the one the plugin was authored in — and add the package by local path:
cd ..
pulumi new typescript --name consumer --dir consumer --yes
cd consumer
pulumi package add ../my-componentsPulumi reads PulumiPlugin.yaml, introspects the plugin, generates a local SDK in the consumer's language, and prints the import statement to use. Every component in the package is available under the generated SDK.
To distribute the package more broadly, push it to a Git repository and tag a release; consumers can then run pulumi package add <repo-url>@<tag>. See Distribution below for all available options.
Per-language authoring
Each language has its own rules for what the entry file must contain, how components are exposed to consumers, and how argument types are inferred for the generated SDK. These differences are a direct consequence of how each language is designed.
Two models are used across the supported languages:
- Automatic component discovery scans the plugin at load time and exposes every
ComponentResourcesubclass it finds. Depending on the language you may still need a small entry file that hands the provider host an assembly or package to scan, but no per-component registration is required — adding a new component to the package is enough to publish it. - Explicit component registration requires the author to list each component in the entry file. Only listed components are exposed.
Automatic component discovery
Export your component classes from the module named by main in your package.json. No registration code is required. A minimum plugin consists of PulumiPlugin.yaml, package.json, tsconfig.json, and an entry file like:
import * as pulumi from "@pulumi/pulumi";
export interface MyComponentArgs {
message: pulumi.Input<string>;
}
export class MyComponent extends pulumi.ComponentResource {
public readonly output: pulumi.Output<string>;
constructor(name: string, args: MyComponentArgs, opts?: pulumi.ComponentResourceOptions) {
super("my-package:index:MyComponent", name, args, opts);
this.output = pulumi.output(args.message);
this.registerOutputs({ output: this.output });
}
}INFO
Under the hood, the pulumi-language-nodejs host recursively walks the entry module's exports and collects every value whose prototype chain reaches ComponentResource. Nested objects and re-exported namespaces are traversed; non-component exports are ignored.
Your args types also appear in the generated SDK, so consumers can construct them in their own language. You don't need to export or register args classes separately — Pulumi finds them by reading the second parameter of each component's constructor using the TypeScript compiler API, then follows the property types (and any types they reference) through imports to build the schema. No decorators or base class are required on the args type.
Explicit component registration
Supported but rarely needed — to hide a component from consumers, don't export it from the entry module. If you want the explicit model anyway (for example, to expose a subset of exported classes), call componentProviderHost yourself and pass the component classes you want:
import { componentProviderHost } from "@pulumi/pulumi/provider/experimental";
import { StaticSite } from "./static-site";
import { Database } from "./database";
componentProviderHost({ components: [StaticSite, Database], name: "my-package" });Consumer runtime requirements
The runtime requirements on the consumer's machine are the same as any Pulumi program written in the authoring language.
See the JavaScript/TypeScript language docs.
Package contents by authoring language
Source-based plugins were designed around ComponentResource. Custom resources (direct CRUD against an external API) and functions (invokes) are only supported when authoring in Go via pulumi-go-provider. In every other language today, anything that isn't a ComponentResource is ignored.
| Language | ComponentResource | CustomResource | Functions (invokes) |
|---|---|---|---|
| TypeScript | Supported | Ignored | Unsupported |
| Python | Supported | Ignored | Unsupported |
| C# / .NET | Supported | Ignored | Unsupported |
| Java | Supported | Ignored | Unsupported |
| Go | Supported (WithComponents) | Supported (WithResources) | Supported (WithFunctions) |
INFO
In TypeScript and Python, a non-ComponentResource in the list passed to componentProviderHost or component_provider_host is excluded from the schema with a warning. The warning appears only in verbose logs, so run with -v=9 to see it.
Patterns shared by all languages
Despite the language-specific mechanics, every source-based plugin follows the same four patterns:
- Args are discovered transitively. You never register an args class separately — it is found by analyzing the component's constructor or struct signature.
- Schema is inferred from type information. No explicit schema declaration is needed. Python reads annotations, .NET and Java use reflection, TypeScript uses the compiler API, and Go uses struct tags.
- Decorators are optional. Go uses struct tags for metadata; .NET and Java offer
[Input]/@Importfor fine-grained control but do not require them. - All-or-nothing export. Once a component is discoverable, every public property of its args class is automatically included in the generated schema.
Distribution
Once your plugin package is working locally, you have three ways to make it available to consumers.
Sharing via Git
Storing your package in a Git repository allows for version control, collaboration, and easier integration into multiple projects. Consumers add the package to their programs with:
pulumi package add <repo_url>[/path/to/component]@<release-version>The only steps to enable this are pushing your package to a Git repo and tagging a release. Pulumi supports both GitHub and GitLab releases, and can also reference self-hosted Git servers — in that case omit the <release-version> portion.
Pulumi generates the consumer's language-specific SDK automatically. For example, if the consuming program is Python and uses the default pip toolchain, pulumi package add detects that, generates the Python SDK on-the-fly, adds the dependency to requirements.txt, and runs pip install -r requirements.txt. The output also prints the correct import statement:
$ pulumi package add https://github.com/my-org/staticpagecomponent@v0.1.0
Successfully generated an SDK for the staticpagecomponent package at /example/use-static-page-component/sdks/staticpagecomponent
[...]
You can import the SDK in your Python code with:
import pulumi_staticpagecomponent as staticpagecomponentTIP
Pulumi supports private repos in GitHub and GitLab. Pulumi reads standard environment variables like GITHUB_TOKEN and GITLAB_TOKEN to authenticate access during pulumi package add.
Publishing to the Pulumi IDP Private Registry
A source-based plugin package can be published to the IDP Private Registry so it shows up alongside the rest of your organization's infrastructure building blocks — the same components and templates that power golden path workflows in Pulumi. See the Pulumi Private Registry guide for publishing instructions.
Pre-publishing language SDKs
By default, each consumer generates the SDK locally at pulumi package add time. You can instead pre-publish SDKs to language registries (npm, PyPI, Maven, NuGet, Go module proxies) so consumers install them like any other dependency.
A typical CI/CD pipeline for TypeScript looks like:
git tag v1.0.0
git push origin v1.0.0
# Publish to Pulumi IDP Private Registry (optional)
pulumi package publish github.com/myorg/my-component@1.0.0
# Generate the SDK
pulumi package gen-sdk . --language nodejs --out sdk
# Build and publish the SDK
cd sdk/nodejs
npm install
npm run build
cp package.json bin/
npm publish bin/The gen-sdk command outputs TypeScript source files that must be compiled before publishing. The npm run build step runs tsc to compile the SDK into the bin/ directory. Since the bin/ directory does not include a package.json by default, you must copy it in before running npm publish.
TIP
Use npm pack --dry-run in the bin/ directory to inspect what will be published before running npm publish. For private registries (such as AWS CodeArtifact, GitHub Packages, or a private npm registry), configure your .npmrc with the appropriate registry URL and authentication before publishing.
Repeat the pulumi package gen-sdk and publish steps for each language you want to support. Consumers then install the SDK directly via their package manager (e.g., npm install my-component) without generating it themselves.
Troubleshooting
npm scope mismatch when switching between Git and local paths
When you add a package from a Git URL, the generated SDK uses the repository owner as the npm scope. When you later switch to a local path for development, the SDK is regenerated with a different scope. For example:
# Initially added from GitHub — SDK goes to sdks/myorg-my-components
pulumi package add github.com/myorg/my-components@v1.0.0
# package.json: "@myorg/my-components": "file:sdks/myorg-my-components"
# Code uses: import { Foo } from "@myorg/my-components";
# Later switched to local path for development — SDK goes to sdks/my-components
pulumi package add ./path/to/my-components
# package.json adds: "@pulumi/my-components": "file:sdks/my-components"After switching, there are now two SDKs in sdks/: the old one from GitHub and the new one from the local path. The @myorg/my-components entry in package.json still points at the old GitHub SDK, so your existing import statements won't pick up local changes.
Fix: Update the @myorg/my-components entry in package.json to point at the locally generated SDK:
{
"dependencies": {
"@pulumi/my-components": "file:sdks/my-components",
"@myorg/my-components": "file:sdks/my-components"
}
}Now both entries resolve to the same local SDK, and your existing imports work without changes. Run npm install after editing package.json.
Consider single-language components during early development
If the plugin packaging model is adding friction during early development (for example, dealing with SDK regeneration or scope mismatches) and your consuming project is written in the same language as your component, you can skip it entirely. Use the component as a native language package instead. For TypeScript, this means importing the component directly via a file: or path dependency in package.json, with no PulumiPlugin.yaml, no SDK generation, and no pulumi package add.
This approach is useful during early development or migration work where rapid iteration matters more than multi-language support. You can always convert to a source-based plugin package later when you need cross-language consumption or want to publish to the IDP Private Registry.
INFO
Component argument types in native language packages can use any type your language supports (including union types), since they don't need to be serializable to a Pulumi schema. When you convert to a plugin package later, you may need to adjust argument types to use only schema-compatible types.
Next steps
- PulumiPlugin.yaml reference — full field reference for the plugin manifest.
- Local SDKs — develop and iterate on a package before publishing.
- Publishing Packages — distribute your package via Git, the IDP Private Registry, or language-specific registries.
- Package Schema — the schema format that drives SDK generation.
- Components — how consumers pull your package into their programs.