diff --git a/terraform/resource.go b/terraform/resource.go index 937efdbe4..7f1ec3ca4 100644 --- a/terraform/resource.go +++ b/terraform/resource.go @@ -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. diff --git a/terraform/shadow_resource_provider.go b/terraform/shadow_resource_provider.go index 0cf1813a5..862c77515 100644 --- a/terraform/shadow_resource_provider.go +++ b/terraform/shadow_resource_provider.go @@ -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() diff --git a/terraform/transform_resource.go b/terraform/transform_resource.go index 7a7fc223f..d53e9f951 100644 --- a/terraform/transform_resource.go +++ b/terraform/transform_resource.go @@ -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