2018-03-21 19:43:21 +00:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
|
2017-06-08 16:26:06 +00:00
|
|
|
|
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
2017-09-22 02:18:21 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
|
|
"github.com/pulumi/pulumi/pkg/util/contract"
|
2017-06-08 16:26:06 +00:00
|
|
|
)
|
|
|
|
|
2017-06-10 01:34:37 +00:00
|
|
|
// State is a structure containing state associated with a resource. This resource may have been serialized and
|
2017-06-08 16:26:06 +00:00
|
|
|
// deserialized, or snapshotted from a live graph of resource objects. The value's state is not, however, associated
|
|
|
|
// with any runtime objects in memory that may be actively involved in ongoing computations.
|
2017-06-10 01:34:37 +00:00
|
|
|
type State struct {
|
2018-04-13 03:34:50 +00:00
|
|
|
Type tokens.Type // the resource's type.
|
|
|
|
URN URN // the resource's object urn, a human-friendly, unique name for the resource.
|
|
|
|
Custom bool // true if the resource is custom, managed by a plugin.
|
|
|
|
Delete bool // true if this resource is pending deletion due to a replacement.
|
|
|
|
ID ID // the resource's unique ID, assigned by the resource provider (or blank if none/uncreated).
|
|
|
|
Inputs PropertyMap // the resource's input properties (as specified by the program).
|
|
|
|
Outputs PropertyMap // the resource's complete output state (as returned by the resource provider).
|
|
|
|
Parent URN // an optional parent URN that this resource belongs to.
|
|
|
|
Protect bool // true to "protect" this resource (protected resources cannot be deleted).
|
|
|
|
Dependencies []URN // the resource's dependencies
|
2017-06-08 16:26:06 +00:00
|
|
|
}
|
|
|
|
|
Overhaul resources, planning, and environments
This change, part of pulumi/lumi#90, overhauls quite a bit of the
core resource, planning, environments, and related areas.
The biggest amount of movement comes from the splitting of pkg/resource
into multiple sub-packages. This results in:
- pkg/resource: just the core resource data structures.
- pkg/resource/deployment: all planning and deployment logic.
- pkg/resource/environment: all environment, configuration, and
serialized checkpoint structures and logic.
- pkg/resource/plugin: all dynamically loaded analyzer and
provider logic, including the actual loading and RPC mechanisms.
This also splits the resource abstraction up. We now have:
- resource.Resource: a shared interface.
- resource.Object: a resource that is connected to a live object
that will periodically observe mutations due to ongoing
evaluation of computations. Snapshots of its state may be
taken; however, this is purely a "pre-planning" abstraction.
- resource.State: a snapshot of a resource's state that is frozen.
In other words, it is no longer connected to a live object.
This is what will store provider outputs (ID and properties),
and is what may be serialized into a deployment record.
The branch is in a half-baked state as of this change; more changes
are to come...
2017-06-08 23:37:40 +00:00
|
|
|
// NewState creates a new resource value from existing resource state information.
|
2017-10-05 21:08:35 +00:00
|
|
|
func NewState(t tokens.Type, urn URN, custom bool, del bool, id ID,
|
2018-04-13 03:34:50 +00:00
|
|
|
inputs PropertyMap, outputs PropertyMap, parent URN, protect bool, dependencies []URN) *State {
|
2017-12-08 16:43:39 +00:00
|
|
|
contract.Assertf(t != "", "type was empty")
|
|
|
|
contract.Assertf(custom || id == "", "is custom or had empty ID")
|
|
|
|
contract.Assertf(inputs != nil, "inputs was non-nil")
|
2017-06-10 01:34:37 +00:00
|
|
|
return &State{
|
2018-02-21 23:11:21 +00:00
|
|
|
Type: t,
|
|
|
|
URN: urn,
|
|
|
|
Custom: custom,
|
|
|
|
Delete: del,
|
|
|
|
ID: id,
|
|
|
|
Inputs: inputs,
|
|
|
|
Outputs: outputs,
|
|
|
|
Parent: parent,
|
|
|
|
Protect: protect,
|
|
|
|
Dependencies: dependencies,
|
2017-06-08 16:26:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-15 15:37:15 +00:00
|
|
|
// All returns all resource state, including the inputs and outputs, overlaid in that order.
|
2017-08-01 01:26:15 +00:00
|
|
|
func (s *State) All() PropertyMap {
|
2017-12-03 00:34:16 +00:00
|
|
|
return s.Inputs.Merge(s.Outputs)
|
2017-08-01 01:26:15 +00:00
|
|
|
}
|