terraform: InstanceInfo.uniqueId

This adds a new function to get a unique identifier scoped to the graph
walk in order to identify operations against the same instance. This is
used by the shadow to namespace provider function calls.
This commit is contained in:
Mitchell Hashimoto 2016-10-08 17:33:49 +08:00
parent e2fc0b518f
commit d7a5cc5b35
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 22 additions and 7 deletions

View File

@ -62,6 +62,12 @@ type InstanceInfo struct {
// Type is the resource type of this instance
Type string
// uniqueExtra is an internal field that can be populated to supply
// extra metadata that is used to identify a unique instance in
// the graph walk. This will be appended to HumanID when uniqueId
// is called.
uniqueExtra string
}
// HumanId is a unique Id that is human-friendly and useful for UI elements.
@ -76,6 +82,15 @@ func (i *InstanceInfo) HumanId() string {
i.Id)
}
func (i *InstanceInfo) uniqueId() string {
prefix := i.HumanId()
if v := i.uniqueExtra; v != "" {
prefix += " " + v
}
return prefix
}
// ResourceConfig holds the configuration given for a resource. This is
// done instead of a raw `map[string]interface{}` type so that rich
// methods can be added to it to make dealing with it easier.

View File

@ -155,7 +155,7 @@ func (p *shadowResourceProviderReal) Apply(
diffCopy := diff.DeepCopy()
result, err := p.ResourceProvider.Apply(info, state, diff)
p.Shared.Apply.SetValue(info.HumanId(), &shadowResourceProviderApply{
p.Shared.Apply.SetValue(info.uniqueId(), &shadowResourceProviderApply{
State: stateCopy,
Diff: diffCopy,
Result: result.DeepCopy(),
@ -173,7 +173,7 @@ func (p *shadowResourceProviderReal) Diff(
stateCopy := state.DeepCopy()
result, err := p.ResourceProvider.Diff(info, state, desired)
p.Shared.Diff.SetValue(info.HumanId(), &shadowResourceProviderDiff{
p.Shared.Diff.SetValue(info.uniqueId(), &shadowResourceProviderDiff{
State: stateCopy,
Desired: desired,
Result: result.DeepCopy(),
@ -190,7 +190,7 @@ func (p *shadowResourceProviderReal) Refresh(
stateCopy := state.DeepCopy()
result, err := p.ResourceProvider.Refresh(info, state)
p.Shared.Refresh.SetValue(info.HumanId(), &shadowResourceProviderRefresh{
p.Shared.Refresh.SetValue(info.uniqueId(), &shadowResourceProviderRefresh{
State: stateCopy,
Result: result.DeepCopy(),
ResultErr: err,
@ -420,7 +420,7 @@ func (p *shadowResourceProviderShadow) Apply(
state *InstanceState,
diff *InstanceDiff) (*InstanceState, error) {
// Unique key
key := info.HumanId()
key := info.uniqueId()
raw := p.Shared.Apply.Value(key)
if raw == nil {
p.ErrorLock.Lock()
@ -459,7 +459,7 @@ func (p *shadowResourceProviderShadow) Diff(
state *InstanceState,
desired *ResourceConfig) (*InstanceDiff, error) {
// Unique key
key := info.HumanId()
key := info.uniqueId()
raw := p.Shared.Diff.Value(key)
if raw == nil {
p.ErrorLock.Lock()
@ -502,7 +502,7 @@ func (p *shadowResourceProviderShadow) Refresh(
info *InstanceInfo,
state *InstanceState) (*InstanceState, error) {
// Unique key
key := info.HumanId()
key := info.uniqueId()
raw := p.Shared.Refresh.Value(key)
if raw == nil {
p.ErrorLock.Lock()

View File

@ -862,7 +862,7 @@ func (n *graphNodeExpandedResourceDestroy) ConfigType() GraphNodeConfigType {
// GraphNodeEvalable impl.
func (n *graphNodeExpandedResourceDestroy) EvalTree() EvalNode {
info := n.instanceInfo()
info.Id += " (destroy)"
info.uniqueExtra = "destroy"
var diffApply *InstanceDiff
var provider ResourceProvider