Package: pulumi-gomigrate
Pulumi Component Provider Boilerplate (Go)pulumi plugin install resource gomigrate --server github://api.github.com/LuxChanLu/pulumi-gomigrate
This repo is a boilerplate showing how to create a Pulumi component provider written in Go. You can search-replacegomigratewith the name of your desired provider as a starting point for creating a component provider for your component resources.BackgroundThis repository is part of theguide for authoring and publishing a Pulumi Package.Learn about the concepts behindPulumi Packagesand, more specifically,Pulumi ComponentsSample gomigrate Component ProviderAn exampleStaticPagecomponent resourceis available inprovider/pkg/provider/staticPage.go. This component creates a static web page hosted in an AWS S3 Bucket. There is nothing special aboutStaticPage-- it is a typical component resource written in Go.The component provider makes component resources available to other languages. The implementation is inprovider/pkg/provider/provider.go. Each component resource in the provider must have an implementation in theConstructfunction to create an instance of the requested component resource and return itsURNand state (outputs). There is an initial implementation that demonstrates an implementation ofConstructfor the exampleStaticPagecomponent.A code generator is available which generates SDKs in TypeScript, Python, Go and .NET which are also checked in to thesdkfolder. The SDKs are generated from a schema inschema.yaml. This file should be kept aligned with the component resources supported by the component provider implementation.An example of using theStaticPagecomponent in TypeScript is inexamples/simple.Note that the generated provider plugin (pulumi-resource-gomigrate) must be on yourPATHto be used by Pulumi deployments. If creating a provider for distribution to other users, you should ensure they install this plugin to theirPATH.PrerequisitesGo 1.17Pulumi CLINode.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)makeinstall_provider# Regenerate SDKsmakegenerate# Test Node.js SDK$makeinstall_nodejs_sdk
$cdexamples/simple
$yarninstall
$yarnlink@pulumi/gomigrate
$pulumistackinittest$pulumiconfigsetaws:regionus-east-1
$pulumiupNamingThegomigrateprovider's plugin binary must be namedpulumi-resource-gomigrate(in the formatpulumi-resource-<provider>).While the provider plugin must follow this naming convention, the SDK package naming can be customized. TODO explain.Configuring CI and releasesFollow the instructions laid out in thedeployment templates.Example componentLet's look at the exampleStaticPagecomponent resource in more detail.SchemaThe exampleStaticPagecomponent resource is defined inschema.yaml:resources:gomigrate:index:StaticPage:isComponent:trueinputProperties:indexContent:type:stringdescription:The HTML content for index.html.requiredInputs:-indexContentproperties:bucket:"$ref":"/aws/v4.0.0/schema.json#/resources/aws:s3%2Fbucket:Bucket"description:The bucket resource.websiteUrl:type:stringdescription:The website URL.required:-bucket-websiteUrlThe component resource's type token isgomigrate:index:StaticPagein the format of<package>:<module>:<type>. In this case, it's in thegomigratepackage andindexmodule. This is the same type token passed toRegisterComponentResourceinside the implementation ofNewStaticPageinprovider/pkg/provider/staticPage.go, and also the same token referenced inConstructinprovider/pkg/provider/provider.go.This component has a requiredindexContentinput property typed asstring, and two required output properties:bucketandwebsiteUrl. Note thatbucketis typed as theaws:s3/bucket:Bucketresource from theawsprovider (in the schema the/is escaped as%2F).Since this component returns a type from theawsprovider, each SDK must reference the associated PulumiawsSDK for the language. For the .NET, Node.js, and Python SDKs, dependencies are specified in thelanguagesection of the schema:language:csharp:packageReferences:Pulumi:3.*Pulumi.Aws:4.*go:generateResourceContainerTypes:trueimportBasePath:github.com/LuxChanLu/pulumi-gomigrate/sdk/go/gomigratenodejs:dependencies:"@pulumi/aws":"^4.0.0"devDependencies:typescript:"^3.7.0"python:requires:pulumi:">=3.0.0,<4.0.0"pulumi-aws:">=4.0.0,<5.0.0"For the Go SDK, dependencies are specified in thesdk/go.modfile.ImplementationThe implementation of this component is inprovider/pkg/provider/staticPage.goand the structure of the component's inputs and outputs aligns with what is defined inschema.yaml:// The set of arguments for creating a StaticPage component resource.typeStaticPageArgsstruct{IndexContentpulumi.StringInput`pulumi:"indexContent"`}// The StaticPage component resource.typeStaticPagestruct{pulumi.ResourceStateBucket*s3.Bucket`pulumi:"bucket"`WebsiteUrlpulumi.StringOutput`pulumi:"websiteUrl"`}// NewStaticPage creates a new StaticPage component resource.funcNewStaticPage(ctx*pulumi.Context,namestring,args*StaticPageArgs,opts...pulumi.ResourceOption)(*StaticPage,error){...}The provider makes this component resource available in theconstructfunction inprovider/pkg/provider/provider.go. Whenconstructis called and thetypargument isgomigrate:index:StaticPage, we create an instance of theStaticPagecomponent resource and return itsURNand state.funcconstructStaticPage(ctx*pulumi.Context,namestring,inputsprovider.ConstructInputs,optionspulumi.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{}iferr:=inputs.CopyTo(args);err!=nil{returnnil,errors.Wrap(err,"setting args")}// Create the component resource.staticPage,err:=NewStaticPage(ctx,name,args,options)iferr!=nil{returnnil,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`.returnprovider.NewConstructResult(staticPage)}