This change adds a GetRequiredPlugins RPC method to the language host, enabling us to query it for its list of plugin requirements. This is language-specific because it requires looking at the set of dependencies (e.g., package.json files). It also adds a call up front during any update/preview operation to compute the set of plugins and require that they are present. These plugins are populated in the cache and will be used for all subsequent plugin-related operations during the engine's activity. We now cache the language plugins, so that we may load them eagerly too, which we never did previously due to the fact that we needed to pass the monitor address at load time. This was a bit bizarre anyhow, since it's really the Run RPC function that needs this information. So, to enable caching and eager loading -- which we need in order to invoke GetRequiredPlugins -- the "phone home" monitor RPC address is passed at Run time. In a subsequent change, we will switch to faulting in the plugins that are missing -- rather than erroring -- in addition to supporting the `pulumi plugin install` CLI command.
66 lines
3.6 KiB
Go
66 lines
3.6 KiB
Go
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/pulumi/pulumi/pkg/resource"
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
"github.com/pulumi/pulumi/pkg/workspace"
|
|
)
|
|
|
|
// Provider presents a simple interface for orchestrating resource create, reead, update, and delete operations. Each
|
|
// provider understands how to handle all of the resource types within a single package.
|
|
//
|
|
// This interface hides some of the messiness of the underlying machinery, since providers are behind an RPC boundary.
|
|
//
|
|
// It is important to note that provider operations are not transactional. (Some providers might decide to offer
|
|
// transactional semantics, but such a provider is a rare treat.) As a result, failures in the operations below can
|
|
// range from benign to catastrophic (possibly leaving behind a corrupt resource). It is up to the provider to make a
|
|
// best effort to ensure catastrophes do not occur. The errors returned from mutating operations indicate both the
|
|
// underlying error condition in addition to a bit indicating whether the operation was successfully rolled back.
|
|
type Provider interface {
|
|
// Closer closes any underlying OS resources associated with this provider (like processes, RPC channels, etc).
|
|
io.Closer
|
|
// Pkg fetches this provider's package.
|
|
Pkg() tokens.Package
|
|
// Configure configures the resource provider with "globals" that control its behavior.
|
|
Configure(vars map[tokens.ModuleMember]string) error
|
|
// Check validates that the given property bag is valid for a resource of the given type and returns the inputs
|
|
// that should be passed to successive calls to Diff, Create, or Update for this resource.
|
|
Check(urn resource.URN, olds, news resource.PropertyMap,
|
|
allowUnknowns bool) (resource.PropertyMap, []CheckFailure, error)
|
|
// Diff checks what impacts a hypothetical update will have on the resource's properties.
|
|
Diff(urn resource.URN, id resource.ID, olds resource.PropertyMap, news resource.PropertyMap,
|
|
allowUnknowns bool) (DiffResult, error)
|
|
// Create allocates a new instance of the provided resource and returns its unique resource.ID.
|
|
Create(urn resource.URN, news resource.PropertyMap) (resource.ID, resource.PropertyMap, resource.Status, error)
|
|
// Update updates an existing resource with new values.
|
|
Update(urn resource.URN, id resource.ID,
|
|
olds resource.PropertyMap, news resource.PropertyMap) (resource.PropertyMap, resource.Status, error)
|
|
// Delete tears down an existing resource.
|
|
Delete(urn resource.URN, id resource.ID, props resource.PropertyMap) (resource.Status, error)
|
|
// Invoke dynamically executes a built-in function in the provider.
|
|
Invoke(tok tokens.ModuleMember, args resource.PropertyMap) (resource.PropertyMap, []CheckFailure, error)
|
|
// GetPluginInfo returns this plugin's information.
|
|
GetPluginInfo() (workspace.PluginInfo, error)
|
|
}
|
|
|
|
// CheckFailure indicates that a call to check failed; it contains the property and reason for the failure.
|
|
type CheckFailure struct {
|
|
Property resource.PropertyKey // the property that failed checking.
|
|
Reason string // the reason the property failed to check.
|
|
}
|
|
|
|
// DiffResult indicates whether an operation should replace or update an existing resource.
|
|
type DiffResult struct {
|
|
ReplaceKeys []resource.PropertyKey // an optional list of replacement keys.
|
|
StableKeys []resource.PropertyKey // an optional list of property keys that are stable.
|
|
DeleteBeforeReplace bool // if true, this resource must be deleted before recreating it.
|
|
}
|
|
|
|
// Replace returns true if this diff represents a replacement.
|
|
func (r DiffResult) Replace() bool {
|
|
return len(r.ReplaceKeys) > 0
|
|
}
|