pulumi/pkg/backend/local/stack.go
joeduffy b77403b4bb Implement a refresh command
This change implements a `pulumi refresh` command.  It operates a bit
like `pulumi update`, and friends, in that it supports `--preview` and
`--diff`, along with the usual flags, and will update your checkpoint.

It works through substitution of the deploy.Source abstraction, which
generates a sequence of resource registration events.  This new
deploy.RefreshSource takes in a prior checkpoint and will walk it,
refreshing the state via the associated resource providers by invoking
Read for each resource encountered, and merging the resulting state with
the prior checkpoint, to yield a new resource.Goal state.  This state is
then fed through the engine in the usual ways with a few minor caveats:
namely, although the engine must generate steps for the logical
operations (permitting us to get nice summaries, progress, and diffs),
it mustn't actually carry them out because the state being imported
already reflects reality (a deleted resource has *already* been deleted,
so of course the engine need not perform the deletion).  The diffing
logic also needs to know how to treat the case of refresh slightly
differently, because we are going to be diffing outputs and not inputs.

Note that support for managed stacks is not yet complete, since that
requires updates to the service to support a refresh endpoint.  That
will be coming soon ...
2018-04-18 10:57:16 -07:00

77 lines
2.8 KiB
Go

// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
package local
import (
"github.com/pulumi/pulumi/pkg/apitype"
"github.com/pulumi/pulumi/pkg/backend"
"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 local stack. This simply adds some local-specific properties atop the standard backend stack interface.
type Stack interface {
backend.Stack
Path() string // a path to the stack's checkpoint file on disk.
}
// localStack is a local stack descriptor.
type localStack struct {
name tokens.QName // the stack's name.
path string // a path to the stack's checkpoint file on disk.
config config.Map // the stack's config bag.
snapshot *deploy.Snapshot // a snapshot representing the latest deployment state.
b *localBackend // a pointer to the backend this stack belongs to.
}
func newStack(name tokens.QName, path string, config config.Map,
snapshot *deploy.Snapshot, b *localBackend) Stack {
return &localStack{
name: name,
path: path,
config: config,
snapshot: snapshot,
b: b,
}
}
func (s *localStack) Name() tokens.QName { return s.name }
func (s *localStack) Config() config.Map { return s.config }
func (s *localStack) Snapshot() *deploy.Snapshot { return s.snapshot }
func (s *localStack) Backend() backend.Backend { return s.b }
func (s *localStack) Path() string { return s.path }
func (s *localStack) Remove(force bool) (bool, error) {
return backend.RemoveStack(s, force)
}
func (s *localStack) Update(proj *workspace.Project, root string,
m backend.UpdateMetadata, opts engine.UpdateOptions, displayOpts backend.DisplayOptions) error {
return backend.UpdateStack(s, proj, root, m, opts, displayOpts)
}
func (s *localStack) Refresh(proj *workspace.Project, root string,
m backend.UpdateMetadata, opts engine.UpdateOptions, displayOpts backend.DisplayOptions) error {
return backend.RefreshStack(s, proj, root, m, opts, displayOpts)
}
func (s *localStack) Destroy(proj *workspace.Project, root string,
m backend.UpdateMetadata, opts engine.UpdateOptions, displayOpts backend.DisplayOptions) error {
return backend.DestroyStack(s, proj, root, m, opts, displayOpts)
}
func (s *localStack) GetLogs(query operations.LogQuery) ([]operations.LogEntry, error) {
return backend.GetStackLogs(s, query)
}
func (s *localStack) ExportDeployment() (*apitype.UntypedDeployment, error) {
return backend.ExportStackDeployment(s)
}
func (s *localStack) ImportDeployment(deployment *apitype.UntypedDeployment) error {
return backend.ImportStackDeployment(s, deployment)
}