This repository builds a working Pulumi component in Python. You
can use it as a boilerplate for creating your own component provider by search-replacing ipidp with your chosen name.
This repository is part of the guide for authoring and publishing a Pulumi Package.
Learn about the concepts behind Pulumi Packages and, more specifically, Pulumi Components
Pulumi component providers make
component resources
available to Pulumi code in all supported programming languages.
Specifically, ipidp component provider defines an example StaticPage
component resource that provisions a public AWS S3 HTML page.
The important pieces include:
-
schema.json declaring the
StaticPageinterface -
ipidp_provider package implementing
StaticPageusing typical Pulumi Python code
From here, the build generates:
-
SDKs for Python, Go, .NET, and Node (under
sdk/) -
pulumi-resource-ipidpPulumi plugin (underbin/)
Users can deploy StaticPage instances in their language of choice,
as seen in the TypeScript example. Only
two things are needed to run pulumi up:
-
the code needs to reference the
ipidpSDK package -
pulumi-resource-ipidpneeds to be onPATHforpulumito find it
- Pulumi CLI
- Python 3.6+
- Node.js
- Yarn
- Go 1.17
- Node.js (to build the Node SDK)
- .NET Code SDK (to build the .NET SDK)
# Regenerate SDKs
make generate
# Build and install the provider and SDKs
make build
make install
# Ensure the pulumi-provider-ipidp script is on PATH (for testing)
$ export PATH=$PATH:$PWD/bin
# Test Node.js SDK
$ cd examples/simple
$ yarn install
$ yarn link @pulumi/ipidp
$ pulumi stack init test
$ pulumi config set aws:region us-east-1
$ pulumi up
The ipidp plugin must be packaged as a pulumi-resource-ipidp script or
binary (in the format pulumi-resource-<provider>).
While the plugin must follow this naming convention, the SDK package naming can be custom.
The ipidp plugin can be packaged as a tarball for distribution:
$ make dist
$ ls dist/
pulumi-resource-ipidp-v0.0.1-darwin-amd64.tar.gz
pulumi-resource-ipidp-v0.0.1-windows-amd64.tar.gz
pulumi-resource-ipidp-v0.0.1-linux-amd64.tar.gzUsers can install the plugin with:
pulumi plugin install resource ipidp 0.0.1 --file dist/pulumi-resource-ipidp-v0.0.1-darwin-amd64.tar.gzThe tarball only includes the ipidp_provider sources. During the
installation phase, pulumi will use the user's system Python command
to rebuild a virtual environment and restore dependencies (such as
Pulumi SDK).
TODO explain custom server hosting in more detail.
- Follow the instructions laid out in the deployment templates.
The component resource's type token
is ipidp:index:StaticPage in the
format of <package>:<module>:<type>. In this case, it's in the ipidp
package and index module. This is the same type token passed inside
the implementation of StaticPage in
staticpage.py,
and also the same token referenced in construct in
provider.py.
This component has a required indexContent input property typed as
string, and two required output properties: bucket and
websiteUrl. Note that bucket is typed as the
aws:s3/bucket:Bucket resource from the aws provider (in the schema
the / is escaped as %2F).
Since this component returns a type from the aws provider, each SDK
must reference the associated Pulumi aws SDK for the language. For
the .NET, Node.js, and Python SDKs, dependencies are specified in the
language section of the schema.
The key method to implement is
construct
on the Provider class. It receives Inputs representing arguments the user passed,
and returns a ConstructResult with the new StaticPage resource urn an state.
It is important that the implementation aligns the structure of inptus
and outputs with the interface declared in schema.json.