Skip to main content

This is a proof of concept to build a provider from Python code using type annotations to define the schema.

Project description

Python Component as Component

This is a proof of concept to build a provider from Python code using type annotations to define the schema.

Usage

Subclass pulumi.ComponentResource and use type annotations to define the schema:

# A class defining the inputs for the component
@dataclass
class ServiceArgs:
    region: pulumi.Input[str]
    project: pulumi.Input[str]
    app_path: Optional[pulumi.Input[str]] = "./app"
    image_name: Optional[pulumi.Input[str]] = "image"

# The component class that will be constructed by the provider
class Service(pulumi.ComponentResource):
    # Define the outputs of the component
    url: pulumi.Output[Optional[str]]
    image_digest: pulumi.Output[str]

    def __init__(
        self,
        name: str,
        args: ServiceArgs,
        opts: Optional[pulumi.ResourceOptions] = None,
    ):
        super().__init__("cloudrun:index:Service", name, {}, opts)
        # Create your resources etc.

Create a hosting provider for the class by adding a __main__.py file that uses componentProviderHost:

from component.host import componentProviderHost
from component.metadata import Metadata

componentProviderHost(
    Metadata(name="my-component", version="1.2.3", display_name="My Component")
)

Example

The example folder contains a component in my-component that generates a self-signed certificate. The pulumi_project_yaml folder contains a Pulumi YAML project that uses The pulumi_project_py folder contains a Pulumi Python project that uses the component via the generated SDK.

cd example/pulumi_project_py
pulumi package gen-sdk ../my-component --out ../generated-sdk --language python
uv add --editable ../generated-sdk/python
pulumi preview
Updating (dev)

View in Browser (Ctrl+O): https://app.pulumi.com/v-julien-pulumi-corp/example/dev/updates/27

     Type                                         Name         Status
 +   pulumi:pulumi:Stack                          example-dev  created (9s)
 +   └─ my-component:index:SelfSignedCertificate  cert         created
 +      └─ tls:index:PrivateKey                   cert-ca      created (0.31s)
 +         ├─ tls:index:PrivateKey                cert-key     created (0.55s)
 +         └─ tls:index:SelfSignedCert            cert-ca      created (1s)

Outputs:
    cert: {
        algorithm  : "ECDSA"
        ca_cert_pem: "-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----\n"
        ecdsa_curve: "P224"
        private_key: [secret]
        rsa_bits   : 2048
        urn        : "urn:pulumi:dev::example::my-component:index:SelfSignedCertificate::cert"
    }

Resources:
    + 5 created

Duration: 11s

Alternatively, add the package with package add, but this requires the Python Pulumi SDK to handle parameterization in sdk/python/lib/pulumi/provider/provider.py.

pulumi package add ../my-component

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pulumi_components_test-0.0.7.tar.gz (59.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pulumi_components_test-0.0.7-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pulumi_components_test-0.0.7.tar.gz.

File metadata

  • Download URL: pulumi_components_test-0.0.7.tar.gz
  • Upload date:
  • Size: 59.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for pulumi_components_test-0.0.7.tar.gz
Algorithm Hash digest
SHA256 cd7cbfc3a1c36c82e2e4894f9aef80ada0e7b8293e2589c8d033a6993c11d8b7
MD5 15f78d1ddb482cec91b7cfc7af28023f
BLAKE2b-256 1927c23d16261543d3adfa37b28d9de690d0c9e5403014146ef47a051c494d27

See more details on using hashes here.

File details

Details for the file pulumi_components_test-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for pulumi_components_test-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1a091d9b9e33d9a5a5240f43638625683612ed5c542d15332acfa50413acd53d
MD5 c92757b2e2a18eb7f8d83169bcd23b83
BLAKE2b-256 0b0465f729771a70f3214d185cd265582c22e718ac64d2410e42c9ea4d323c1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page