GithubHelp home page GithubHelp logo

isabella232 / pulumi-component-provider-py-boilerplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pulumi/pulumi-component-provider-py-boilerplate

0.0 0.0 0.0 94 KB

Demonstrates building a multi-lang Pulumi component provider in Python

License: Apache License 2.0

Shell 0.27% Python 38.19% Go 30.14% C# 12.07% TypeScript 12.02% Makefile 7.11% Batchfile 0.19%

pulumi-component-provider-py-boilerplate's Introduction

Pulumi Component Boilerplate (Python)

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 xyz with your chosen name.

Background

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

Sample xyz Component Provider

Pulumi component providers make component resources available to Pulumi code in all supported programming languages. Specifically, xyz component provider defines an example StaticPage component resource that provisions a public AWS S3 HTML page.

The important pieces include:

  • schema.json declaring the StaticPage interface

  • xyz_provider package implementing StaticPage using typical Pulumi Python code

From here, the build generates:

  • SDKs for Python, Go, .NET, and Node (under sdk/)

  • pulumi-resource-xyz Pulumi plugin (under bin/)

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 xyz SDK package

  • pulumi-resource-xyz needs to be on PATH for pulumi to find it

Prerequisites

  • 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)

Build and Test

# Regenerate SDKs
make generate

# Build and install the provider and SDKs
make build
make install

# Ensure the pulumi-provider-xyz script is on PATH (for testing)
$ export PATH=$PATH:$PWD/bin

# Test Node.js SDK
$ cd examples/simple
$ yarn install
$ yarn link @pulumi/xyz
$ pulumi stack init test
$ pulumi config set aws:region us-east-1
$ pulumi up

Naming

The xyz plugin must be packaged as a pulumi-resource-xyz script or binary (in the format pulumi-resource-<provider>).

While the plugin must follow this naming convention, the SDK package naming can be custom.

Packaging

The xyz plugin can be packaged as a tarball for distribution:

$ make dist

$ ls dist/
pulumi-resource-xyz-v0.0.1-darwin-amd64.tar.gz
pulumi-resource-xyz-v0.0.1-windows-amd64.tar.gz
pulumi-resource-xyz-v0.0.1-linux-amd64.tar.gz

Users can install the plugin with:

pulumi plugin install resource xyz 0.0.1 --file dist/pulumi-resource-xyz-v0.0.1-darwin-amd64.tar.gz

The tarball only includes the xyz_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.

Configuring CI and releases

  1. Follow the instructions laid out in the deployment templates.

StaticPage Example

Schema

The component resource's type token is xyz:index:StaticPage in the format of <package>:<module>:<type>. In this case, it's in the xyz 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.

Implementation

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.

pulumi-component-provider-py-boilerplate's People

Contributors

evanboyle avatar guineveresaenger avatar jkisk avatar stack72 avatar t0yv0 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.