Despite our good progress moving towards having an apitype package, where our exchange types live and can be shared among the engine and our services, there were a few major types that were still duplciated. Resource was the biggest example -- and indeed, the apitype varirant was missing the new Dependencies property -- but there were others, like Manfiest, PluginInfo, etc. These too had semi-random omissions. This change merges all of these types into the apitype package. This not only cleans up the redundancy and missing properties, but will "force the issue" with respect to keeping them in sync and properly versioning the information in a backwards compatible way. The resource/stack package still exists as a simple marshaling layer to and from the engine's core data types. Finally, I've made the controversial change to share the actual Deployment data structure at the apitype layer also. This will force us to confront differences in that data structure similarly, and will allow us to leverage the strong typing throughout to catch issues.
79 lines
3.5 KiB
Go
79 lines
3.5 KiB
Go
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
package backend
|
|
|
|
import (
|
|
"github.com/pulumi/pulumi/pkg/apitype"
|
|
"github.com/pulumi/pulumi/pkg/engine"
|
|
"github.com/pulumi/pulumi/pkg/operations"
|
|
"github.com/pulumi/pulumi/pkg/resource/config"
|
|
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
"github.com/pulumi/pulumi/pkg/workspace"
|
|
)
|
|
|
|
// Stack is a stack associated with a particular backend implementation.
|
|
type Stack interface {
|
|
Name() tokens.QName // this stack's name.
|
|
Config() config.Map // the current config map.
|
|
Snapshot() *deploy.Snapshot // the latest deployment snapshot.
|
|
Backend() Backend // the backend this stack belongs to.
|
|
|
|
// Preview changes to this stack.
|
|
Preview(proj *workspace.Project, root string,
|
|
debug bool, opts engine.UpdateOptions, displayOpts DisplayOptions) error
|
|
// Update this stack.
|
|
Update(proj *workspace.Project, root string,
|
|
debug bool, m UpdateMetadata, opts engine.UpdateOptions, displayOpts DisplayOptions) error
|
|
// Destroy this stack's resources.
|
|
Destroy(proj *workspace.Project, root string,
|
|
debug bool, m UpdateMetadata, opts engine.UpdateOptions, displayOpts DisplayOptions) error
|
|
|
|
Remove(force bool) (bool, error) // remove this stack.
|
|
GetLogs(query operations.LogQuery) ([]operations.LogEntry, error) // list log entries for this stack.
|
|
ExportDeployment() (*apitype.Deployment, error) // export this stack's deployment.
|
|
ImportDeployment(deployment *apitype.Deployment) error // import the given deployment into this stack.
|
|
}
|
|
|
|
// RemoveStack returns the stack, or returns an error if it cannot.
|
|
func RemoveStack(s Stack, force bool) (bool, error) {
|
|
return s.Backend().RemoveStack(s.Name(), force)
|
|
}
|
|
|
|
// PreviewStack initiates a preview of the current workspace's contents.
|
|
func PreviewStack(s Stack, proj *workspace.Project, root string,
|
|
debug bool, opts engine.UpdateOptions, displayOpts DisplayOptions) error {
|
|
return s.Backend().Preview(s.Name(), proj, root, debug, opts, displayOpts)
|
|
}
|
|
|
|
// UpdateStack updates the target stack with the current workspace's contents (config and code).
|
|
func UpdateStack(s Stack, proj *workspace.Project, root string,
|
|
debug bool, m UpdateMetadata, opts engine.UpdateOptions, displayOpts DisplayOptions) error {
|
|
return s.Backend().Update(s.Name(), proj, root, debug, m, opts, displayOpts)
|
|
}
|
|
|
|
// DestroyStack destroys all of this stack's resources.
|
|
func DestroyStack(s Stack, proj *workspace.Project, root string,
|
|
debug bool, m UpdateMetadata, opts engine.UpdateOptions, displayOpts DisplayOptions) error {
|
|
return s.Backend().Destroy(s.Name(), proj, root, debug, m, opts, displayOpts)
|
|
}
|
|
|
|
// GetStackCrypter fetches the encrypter/decrypter for a stack.
|
|
func GetStackCrypter(s Stack) (config.Crypter, error) {
|
|
return s.Backend().GetStackCrypter(s.Name())
|
|
}
|
|
|
|
// GetStackLogs fetches a list of log entries for the current stack in the current backend.
|
|
func GetStackLogs(s Stack, query operations.LogQuery) ([]operations.LogEntry, error) {
|
|
return s.Backend().GetLogs(s.Name(), query)
|
|
}
|
|
|
|
// ExportStackDeployment exports the given stack's deployment as an opaque JSON message.
|
|
func ExportStackDeployment(s Stack) (*apitype.Deployment, error) {
|
|
return s.Backend().ExportDeployment(s.Name())
|
|
}
|
|
|
|
// ImportStackDeployment imports the given deployment into the indicated stack.
|
|
func ImportStackDeployment(s Stack, deployment *apitype.Deployment) error {
|
|
return s.Backend().ImportDeployment(s.Name(), deployment)
|
|
}
|