A boilerplate showing how to create a Pulumi component provider written in Go

Overview

xyz Pulumi Component Provider (Go)

This repo is a boilerplate showing how to create a Pulumi component provider written in Go. You can search-replace xyz with the name of your desired provider as a starting point for creating a component provider for your component resources.

An example StaticPage component resource is available in provider/pkg/provider/staticPage.go. This component creates a static web page hosted in an AWS S3 Bucket. There is nothing special about StaticPage -- it is a typical component resource written in Go.

The component provider makes component resources available to other languages. The implementation is in provider/pkg/provider/provider.go. Each component resource in the provider must have an implementation in the Construct function to create an instance of the requested component resource and return its URN and state (outputs). There is an initial implementation that demonstrates an implementation of Construct for the example StaticPage component.

A code generator is available which generates SDKs in TypeScript, Python, Go and .NET which are also checked in to the sdk folder. The SDKs are generated from a schema in schema.json. This file should be kept aligned with the component resources supported by the component provider implementation.

An example of using the StaticPage component in TypeScript is in examples/simple.

Note that the generated provider plugin (pulumi-resource-xyz) must be on your PATH to be used by Pulumi deployments. If creating a provider for distribution to other users, you should ensure they install this plugin to their PATH.

Prerequisites

  • Go 1.15
  • Pulumi CLI
  • Node.js (to build the Node.js SDK)
  • Yarn (to build the Node.js SDK)
  • Python 3.6+ (to build the Python SDK)
  • .NET Core SDK (to build the .NET SDK)

Build and Test

# Build and install the provider (plugin copied to $GOPATH/bin)
make install_provider

# Regenerate SDKs
make generate

# Test Node.js SDK
$ make install_nodejs_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 provider's plugin binary must be named pulumi-resource-xyz (in the format pulumi-resource- ).

While the provider plugin must follow this naming convention, the SDK package naming can be customized. TODO explain.

Example component

Let's look at the example StaticPage component resource in more detail.

Schema

The example StaticPage component resource is defined in schema.json:

"resources": {
    "xyz:index:StaticPage": {
        "isComponent": true,
        "inputProperties": {
            "indexContent": {
                "type": "string",
                "description": "The HTML content for index.html."
            }
        },
        "requiredInputs": [
            "indexContent"
        ],
        "properties": {
            "bucket": {
                "$ref": "/aws/v3.30.0/schema.json#/resources/aws:s3%2Fbucket:Bucket",
                "description": "The bucket resource."
            },
            "websiteUrl": {
                "type": "string",
                "description": "The website URL."
            }
        },
        "required": [
            "bucket",
            "websiteUrl"
        ]
    }
}

The component resource's type token is xyz:index:StaticPage in the format of : : . In this case, it's in the xyz package and index module. This is the same type token passed to RegisterComponentResource inside the implementation of NewStaticPage in provider/pkg/provider/staticPage.go, and also the same token referenced in Construct in provider/pkg/provider/provider.go.

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:

=2.21.2,<3.0.0", "pulumi-aws": ">=3.30.0,<4.0.0" } } } ">
"language": {
    "csharp": {
        "packageReferences": {
            "Pulumi": "2.*",
            "Pulumi.Aws": "3.*"
        }
    },
    "nodejs": {
        "dependencies": {
            "@pulumi/aws": "^3.30.0"
        },
        "devDependencies": {
            "typescript": "^3.7.0"
        }
    },
    "python": {
        "requires": {
            "pulumi": ">=2.21.2,<3.0.0",
            "pulumi-aws": ">=3.30.0,<4.0.0"
        }
    }
}

For the Go SDK, dependencies are specified in the sdk/go.mod file.

Implementation

The implementation of this component is in provider/pkg/provider/staticPage.go and the structure of the component's inputs and outputs aligns with what is defined in schema.json:

// The set of arguments for creating a StaticPage component resource.
type StaticPageArgs struct {
	IndexContent pulumi.StringInput `pulumi:"indexContent"`
}

// The StaticPage component resource.
type StaticPage struct {
	pulumi.ResourceState

	Bucket     *s3.Bucket          `pulumi:"bucket"`
	WebsiteUrl pulumi.StringOutput `pulumi:"websiteUrl"`
}

// NewStaticPage creates a new StaticPage component resource.
func NewStaticPage(ctx *pulumi.Context, name string, args *StaticPageArgs, opts ...pulumi.ResourceOption) (*StaticPage, error) {
    ...
}

The provider makes this component resource available in the construct function in provider/pkg/provider/provider.go. When construct is called and the typ argument is xyz:index:StaticPage, we create an instance of the StaticPage component resource and return its URN and state.

func constructStaticPage(ctx *pulumi.Context, name string, inputs provider.ConstructInputs,
	options pulumi.ResourceOption) (*provider.ConstructResult, error) {

	// Copy the raw inputs to StaticPageArgs. `inputs.CopyTo` uses the types and `pulumi:` tags
	// on the struct's fields to convert the raw values to the appropriate Input types.
	args := &StaticPageArgs{}
	if err := inputs.CopyTo(args); err != nil {
		return nil, errors.Wrap(err, "setting args")
	}

	// Create the component resource.
	staticPage, err := NewStaticPage(ctx, name, args, options)
	if err != nil {
		return nil, errors.Wrap(err, "creating component")
	}

	// Return the component resource's URN and state. `NewConstructResult` automatically sets the
	// ConstructResult's state based on resource struct fields tagged with `pulumi:` tags with a value
	// that is convertible to `pulumi.Input`.
	return provider.NewConstructResult(staticPage)
}
Owner
Pulumi
Pulumi
Pulumi Terraform provider for Artifactory

Terraform Bridge Provider Boilerplate This repository contains boilerplate code for building a new Pulumi provider which wraps an existing Terraform p

Pulumi 1 Nov 18, 2021
Deploy TiDB with Pulumi effortlessly.

TiDB ❤️ Pulumi Deploy TiDB with Pulumi effortlessly. It should be easy to spin up some virtual machines, and deploy a TiDB cluster there for developme

Yilong Li 5 Sep 20, 2021
A tool to generate Pulumi Package schemas from Go type definitions

MkSchema A tool to generate Pulumi Package schemas from Go type definitions. This tool translates annotated Go files into Pulumi component schema meta

Joe Duffy 1 Oct 18, 2021
create a provider to get atlassian resources

Terraform Provider Scaffolding This repository is a template for a Terraform provider. It is intended as a starting point for creating Terraform provi

null 0 Nov 24, 2021
A toaster component for hogosuru framework

Toaster component for hogosuru Toaster implementation for hogosuru How to use? Create a hogosurutoaster.Toaster or attach it to a hogosuru container a

Manuel BARRAUD 3 Oct 23, 2021
Entitas-Go is a fast Entity Component System Framework (ECS) Go 1.17 port of Entitas v1.13.0 for C# and Unity.

Entitas-Go Entitas-GO is a fast Entity Component System Framework (ECS) Go 1.17 port of Entitas v1.13.0 for C# and Unity. Code Generator Install the l

Vladislav Fedotov 6 Nov 21, 2021
Automatically generate Go test boilerplate from your source code.

gotests gotests makes writing Go tests easy. It's a Golang commandline tool that generates table driven tests based on its target source files' functi

Charles Weill 3.6k Dec 7, 2021
A Visual Go REST API boilerplate builder.

A Visual Go REST API boilerplate builder. The boilerplate builder will export a Go web server with 0 dependencies, besides the ones you add.

The Strukture IDE 49 Nov 4, 2021
A boilerplate for Go fiber versioning

Fiber Versioning Boilerplate Prerequisite Make sure you have the following installed outside the current project directory and available in your GOPAT

Visarut Phusua 14 Nov 23, 2021
Golang Fiber boilerplate with MySQL resource.

Fibo - Go Fiber API Boilerplate A starter project with Golang, Fiber and Gorm Golang Fiber boilerplate with MySQL resource. Supports multiple configur

TDP Software 4 Nov 5, 2021
Example hello-world service uses go-fx-grpc-starter boilerplate code

About Example hello-world service uses https://github.com/srlk/go-fx-grpc-starter boilerplate code. Implementation A hello world grpc service is creat

null 0 Nov 14, 2021
Boilerplate for building a monolighic Go and React application

Monolithic Go and React Application Boilerplate This repository provides a simple and monolithic service with a server written in Go and frontend with

Shin'ya Ueoka 9 Nov 23, 2021
Go Clean Architecture Boilerplate

Go Clean-Architecture Simple Go Clean-Architecture Boilerplate Overview The purpose of the template is to show: How to organize a project and prevent

Muhammad Naufal Rachfian Djamhur 0 Nov 27, 2021
A golang boilerplate for Mixin Bot

go-boilerplate This is a golang boilerplate for Mixin Bot. run ./go-boilerplate -f YOUR_KEYSTORE_FILE help to see the help. It enables several widely

Lyric Wai 4 Dec 4, 2021
Person is a simple CRUD application written in go which exposes API endpoint to create the person.

Person Person is a simple CRUD application written in go which exposes API endpoint to create the person. Installation Install docker in your local sy

null 0 Oct 18, 2021
Terraform Algolia Provider

Terraform Provider Algolia Terraform Provider for Algolia. Documentation Full, comprehensive documentation is available on the Terraform

Kanji Yomoda 11 Nov 23, 2021
A terraform provider for Sparkpost

terraform-provider-sparkpost A terraform provider for Sparkpost Local Development Run the following command to build the provider make build Test Exam

SurveyMonkey 4 Sep 7, 2021
Terraform Provider for cascading runs across multiple workspaces.

Terraform Multispace Provider The multispace Terraform provider implements resources to help work with multi-workspace workflows in Terraform Cloud (o

Mitchell Hashimoto 123 Nov 23, 2021
Terraform Provider for PGP Actions

Terraform Provider PGP Warning: Use of this provider will result in secrets being in terraform state in PLAIN TEXT (aka NOT ENCRYPTED). You've been wa

Erik Kristensen 5 Nov 27, 2021