mirror of https://github.com/pulumi/pulumi.git
80 lines
1.9 KiB
Go
80 lines
1.9 KiB
Go
// Copyright 2016-2024, Pulumi Corporation. All rights reserved.
|
|
//go:build !all
|
|
// +build !all
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v3/resource/provider"
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
|
|
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
|
|
pulumiprovider "github.com/pulumi/pulumi/sdk/v3/go/pulumi/provider"
|
|
)
|
|
|
|
type Component struct {
|
|
pulumi.ResourceState
|
|
|
|
Foo pulumi.StringOutput `pulumi:"foo"`
|
|
}
|
|
|
|
type ComponentArgs struct {
|
|
Foo pulumi.StringInput `pulumi:"foo"`
|
|
}
|
|
|
|
func NewComponent(ctx *pulumi.Context, name string, args *ComponentArgs, opts ...pulumi.ResourceOption) (*Component, error) {
|
|
component := &Component{}
|
|
err := ctx.RegisterComponentResource("testcomponent:index:Component", name, component, opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := ctx.RegisterResourceOutputs(component, pulumi.Map{
|
|
"foo": args.Foo,
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return component, nil
|
|
}
|
|
|
|
const (
|
|
providerName = "testcomponent"
|
|
version = "0.0.1"
|
|
)
|
|
|
|
func main() {
|
|
if err := provider.MainWithOptions(provider.Options{
|
|
Name: providerName,
|
|
Version: version,
|
|
Construct: func(ctx *pulumi.Context, typ, name string, inputs pulumiprovider.ConstructInputs,
|
|
options pulumi.ResourceOption,
|
|
) (*pulumiprovider.ConstructResult, error) {
|
|
if typ != "testcomponent:index:Component" {
|
|
return nil, fmt.Errorf("unknown resource type %s", typ)
|
|
}
|
|
|
|
args := &ComponentArgs{}
|
|
if err := inputs.CopyTo(args); err != nil {
|
|
return nil, fmt.Errorf("setting args: %w", err)
|
|
}
|
|
|
|
component, err := NewComponent(ctx, name, args, options)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("creating component: %w", err)
|
|
}
|
|
|
|
failures := []pulumiprovider.ConstructFailure{
|
|
{
|
|
Property: "foo",
|
|
Reason: "the failure reason",
|
|
},
|
|
}
|
|
return pulumiprovider.NewConstructResult(component, pulumiprovider.Failures(failures))
|
|
},
|
|
}); err != nil {
|
|
cmdutil.ExitError(err.Error())
|
|
}
|
|
}
|