github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/resource/deploy/source.go (about)

     1  // Copyright 2016-2018, Pulumi Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package deploy
    16  
    17  import (
    18  	"context"
    19  	"io"
    20  
    21  	pbempty "github.com/golang/protobuf/ptypes/empty"
    22  	"github.com/pulumi/pulumi/pkg/v3/resource/deploy/providers"
    23  	"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
    24  	"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
    25  	"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
    26  	"github.com/pulumi/pulumi/sdk/v3/go/common/util/result"
    27  	pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"
    28  )
    29  
    30  // A ProviderSource allows a Source to lookup provider plugins.
    31  type ProviderSource interface {
    32  	// GetProvider fetches the provider plugin for the given reference.
    33  	GetProvider(ref providers.Reference) (plugin.Provider, bool)
    34  }
    35  
    36  // A Source can generate a new set of resources that the planner will process accordingly.
    37  type Source interface {
    38  	io.Closer
    39  
    40  	// Project returns the package name of the Pulumi project we are obtaining resources from.
    41  	Project() tokens.PackageName
    42  	// Info returns a serializable payload that can be used to stamp snapshots for future reconciliation.
    43  	Info() interface{}
    44  
    45  	// Iterate begins iterating the source. Error is non-nil upon failure; otherwise, a valid iterator is returned.
    46  	Iterate(ctx context.Context, opts Options, providers ProviderSource) (SourceIterator, result.Result)
    47  }
    48  
    49  // A SourceIterator enumerates the list of resources that a source has to offer and tracks associated state.
    50  type SourceIterator interface {
    51  	io.Closer
    52  
    53  	// Next returns the next event from the source.
    54  	Next() (SourceEvent, result.Result)
    55  }
    56  
    57  // SourceResourceMonitor directs resource operations from the `Source` to various resource
    58  // providers.
    59  type SourceResourceMonitor interface {
    60  	// NOTE: This interface does not implement pulumirpc.ResourceMonitorClient because the eval and
    61  	// query implementations of `Source` do not implement precisely the same signatures.
    62  
    63  	Address() string
    64  	Cancel() error
    65  	Invoke(ctx context.Context, req *pulumirpc.ResourceInvokeRequest) (*pulumirpc.InvokeResponse, error)
    66  	Call(ctx context.Context, req *pulumirpc.CallRequest) (*pulumirpc.CallResponse, error)
    67  	ReadResource(ctx context.Context,
    68  		req *pulumirpc.ReadResourceRequest) (*pulumirpc.ReadResourceResponse, error)
    69  	RegisterResource(ctx context.Context,
    70  		req *pulumirpc.RegisterResourceRequest) (*pulumirpc.RegisterResourceResponse, error)
    71  	RegisterResourceOutputs(ctx context.Context,
    72  		req *pulumirpc.RegisterResourceOutputsRequest) (*pbempty.Empty, error)
    73  }
    74  
    75  // SourceEvent is an event associated with the enumeration of a plan.  It is an intent expressed by the source
    76  // program, and it is the responsibility of the engine to make it so.
    77  type SourceEvent interface {
    78  	event()
    79  }
    80  
    81  // RegisterResourceEvent is a step that asks the engine to provision a resource.
    82  type RegisterResourceEvent interface {
    83  	SourceEvent
    84  	// Goal returns the goal state for the resource object that was allocated by the program.
    85  	Goal() *resource.Goal
    86  	// Done indicates that we are done with this step.  It must be called to perform cleanup associated with the step.
    87  	Done(result *RegisterResult)
    88  }
    89  
    90  // RegisterResult is the state of the resource after it has been registered.
    91  type RegisterResult struct {
    92  	State *resource.State // the resource state.
    93  }
    94  
    95  // RegisterResourceOutputsEvent is an event that asks the engine to complete the provisioning of a resource.
    96  type RegisterResourceOutputsEvent interface {
    97  	SourceEvent
    98  	// URN is the resource URN that this completion applies to.
    99  	URN() resource.URN
   100  	// Outputs returns a property map of output properties to add to a resource before completing.
   101  	Outputs() resource.PropertyMap
   102  	// Done indicates that we are done with this step.  It must be called to perform cleanup associated with the step.
   103  	Done()
   104  }
   105  
   106  // ReadResourceEvent is an event that asks the engine to read the state of an existing resource.
   107  type ReadResourceEvent interface {
   108  	SourceEvent
   109  
   110  	// ID is the requested ID of this read.
   111  	ID() resource.ID
   112  	// Name is the requested name of this read.
   113  	Name() tokens.QName
   114  	// Type is type of the resource being read.
   115  	Type() tokens.Type
   116  	// Provider is a reference to the provider instance to use for this read.
   117  	Provider() string
   118  	// Parent is the parent resource of the resource being read.
   119  	Parent() resource.URN
   120  	// Properties is the property bag that will be passed to Read as search parameters.
   121  	Properties() resource.PropertyMap
   122  	// Dependencies returns the list of URNs upon which this read depends.
   123  	Dependencies() []resource.URN
   124  	// Done indicates that we are done with this event.
   125  	Done(result *ReadResult)
   126  	// The names of any additional outputs that should be treated as secrets.
   127  	AdditionalSecretOutputs() []resource.PropertyKey
   128  }
   129  
   130  type ReadResult struct {
   131  	State *resource.State
   132  }