diff --git a/provider.go b/provider.go index 08cbaed..d7d9ec5 100644 --- a/provider.go +++ b/provider.go @@ -26,6 +26,7 @@ import ( "io" "os" + "github.com/blang/semver" "github.com/hashicorp/go-multierror" "github.com/pulumi/pulumi/pkg/v3/codegen/schema" pprovider "github.com/pulumi/pulumi/pkg/v3/resource/provider" @@ -315,6 +316,9 @@ type Provider struct { // GetSchema fetches the schema for this resource provider. GetSchema func(context.Context, GetSchemaRequest) (GetSchemaResponse, error) + + Parameterize func(context.Context, ParameterizeRequest) (ParameterizeResponse, error) + // Cancel signals the provider to gracefully shut down and abort any ongoing resource operations. // Operations aborted in this way will return an error (e.g., `Update` and `Create` will either return a // creation error or an initialization error). Since Cancel is advisory and non-blocking, it is up @@ -380,6 +384,13 @@ func (d Provider) WithDefaults() Provider { return nyi("Cancel") } } + + if d.Parameterize == nil { + d.Parameterize = func(context.Context, ParameterizeRequest) (ParameterizeResponse, error) { + return ParameterizeResponse{}, nyi("Parameterize") + } + } + if d.CheckConfig == nil { d.CheckConfig = func(context.Context, CheckRequest) (CheckResponse, error) { return CheckResponse{}, nyi("CheckConfig") @@ -1091,6 +1102,61 @@ func (p *provider) Cancel(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty } +type ParameterizeRequest struct { + Args *ParameterizeRequestArgs + Value *ParameterizeRequestValue +} + +type ParameterizeRequestArgs struct { + Args []string +} + +type ParameterizeRequestValue struct { + Name string + Version semver.Version + Value []byte +} + +type ParameterizeResponse struct { + Name string + Version *semver.Version +} + +func (p *provider) Parameterize(ctx context.Context, req *rpc.ParameterizeRequest) (*rpc.ParameterizeResponse, error) { + var parsedRequest ParameterizeRequest + + switch params := req.Parameters.(type) { + case *rpc.ParameterizeRequest_Args: + parsedRequest.Args = &ParameterizeRequestArgs{ + Args: params.Args.GetArgs(), + } + case *rpc.ParameterizeRequest_Value: + version, err := semver.Parse(params.Value.Version) + if err != nil { + return nil, rpcerror.Wrap(codes.InvalidArgument, err, "invalid version") + } + parsedRequest.Value = &ParameterizeRequestValue{ + Name: params.Value.Name, + Version: version, + Value: params.Value.Value, + } + } + + resp, err := p.client.Parameterize(p.ctx(ctx, ""), parsedRequest) + if err != nil { + return nil, err + } + var version string + if resp.Version != nil { + version = resp.Version.String() + } + + return &rpc.ParameterizeResponse{ + Name: resp.Name, + Version: version, + }, nil +} + func (p *provider) GetPluginInfo(context.Context, *emptypb.Empty) (*rpc.PluginInfo, error) { return &rpc.PluginInfo{ Version: p.version,