2017-06-26 23:46:34 +02:00
|
|
|
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
2017-06-08 18:26:06 +02:00
|
|
|
|
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pulumi/lumi/pkg/tokens"
|
|
|
|
"github.com/pulumi/lumi/pkg/util/contract"
|
|
|
|
)
|
|
|
|
|
2017-06-10 03:34:37 +02:00
|
|
|
// State is a structure containing state associated with a resource. This resource may have been serialized and
|
2017-06-08 18:26:06 +02: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 03:34:37 +02:00
|
|
|
type State struct {
|
2017-08-01 03:26:15 +02:00
|
|
|
T tokens.Type // the resource's type.
|
|
|
|
U URN // the resource's object urn, a human-friendly, unique name for the resource.
|
|
|
|
ID ID // the resource's unique ID, assigned by the resource provider (or blank if uncreated).
|
|
|
|
Inputs PropertyMap // the resource's input properties (as specified by the program).
|
|
|
|
Defaults PropertyMap // the resource's default property values (if any, given by the provider).
|
|
|
|
Outputs PropertyMap // the resource's complete output state (as returned by the resource provider).
|
2017-06-08 18:26:06 +02:00
|
|
|
}
|
|
|
|
|
2017-06-10 03:34:37 +02:00
|
|
|
var _ Resource = (*State)(nil)
|
|
|
|
|
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-09 01:37:40 +02:00
|
|
|
// NewState creates a new resource value from existing resource state information.
|
2017-08-01 03:26:15 +02:00
|
|
|
func NewState(t tokens.Type, urn URN, id ID, inputs PropertyMap, defaults PropertyMap, outputs PropertyMap) *State {
|
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-09 01:37:40 +02:00
|
|
|
contract.Assert(t != "")
|
|
|
|
contract.Assert(inputs != nil)
|
2017-06-10 03:34:37 +02:00
|
|
|
return &State{
|
2017-08-01 03:26:15 +02:00
|
|
|
T: t,
|
|
|
|
U: urn,
|
|
|
|
ID: id,
|
|
|
|
Inputs: inputs,
|
|
|
|
Defaults: defaults,
|
|
|
|
Outputs: outputs,
|
2017-06-08 18:26:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-01 03:26:15 +02:00
|
|
|
func (s *State) Type() tokens.Type { return s.T }
|
|
|
|
func (s *State) URN() URN { return s.U }
|
|
|
|
|
|
|
|
// All returns all resource state, including the inputs, defaults, and outputs, overlaid in that order.
|
|
|
|
func (s *State) All() PropertyMap {
|
|
|
|
return s.AllInputs().Merge(s.Outputs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AllInputs returns just the resource state's inputs plus any defaults supplied by the provider. This is to be used
|
|
|
|
// when diffing resource states that are entirely under the control of the developer, instead of a cloud provider.
|
|
|
|
func (s *State) AllInputs() PropertyMap {
|
|
|
|
return s.Defaults.Merge(s.Inputs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Synthesized returns all of the resource's "synthesized" state; this includes all properties that appeared in the
|
|
|
|
// default and output set, which may or may not override some or all of those that appeared in the input set.
|
|
|
|
func (s *State) Synthesized() PropertyMap {
|
|
|
|
return s.Defaults.Merge(s.Outputs)
|
|
|
|
}
|