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:
parent
e2fc0b518f
commit
d7a5cc5b35
|
@ -62,6 +62,12 @@ type InstanceInfo struct {
|
||||||
|
|
||||||
// Type is the resource type of this instance
|
// Type is the resource type of this instance
|
||||||
Type string
|
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.
|
// 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)
|
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
|
// ResourceConfig holds the configuration given for a resource. This is
|
||||||
// done instead of a raw `map[string]interface{}` type so that rich
|
// done instead of a raw `map[string]interface{}` type so that rich
|
||||||
// methods can be added to it to make dealing with it easier.
|
// methods can be added to it to make dealing with it easier.
|
||||||
|
|
|
@ -155,7 +155,7 @@ func (p *shadowResourceProviderReal) Apply(
|
||||||
diffCopy := diff.DeepCopy()
|
diffCopy := diff.DeepCopy()
|
||||||
|
|
||||||
result, err := p.ResourceProvider.Apply(info, state, diff)
|
result, err := p.ResourceProvider.Apply(info, state, diff)
|
||||||
p.Shared.Apply.SetValue(info.HumanId(), &shadowResourceProviderApply{
|
p.Shared.Apply.SetValue(info.uniqueId(), &shadowResourceProviderApply{
|
||||||
State: stateCopy,
|
State: stateCopy,
|
||||||
Diff: diffCopy,
|
Diff: diffCopy,
|
||||||
Result: result.DeepCopy(),
|
Result: result.DeepCopy(),
|
||||||
|
@ -173,7 +173,7 @@ func (p *shadowResourceProviderReal) Diff(
|
||||||
stateCopy := state.DeepCopy()
|
stateCopy := state.DeepCopy()
|
||||||
|
|
||||||
result, err := p.ResourceProvider.Diff(info, state, desired)
|
result, err := p.ResourceProvider.Diff(info, state, desired)
|
||||||
p.Shared.Diff.SetValue(info.HumanId(), &shadowResourceProviderDiff{
|
p.Shared.Diff.SetValue(info.uniqueId(), &shadowResourceProviderDiff{
|
||||||
State: stateCopy,
|
State: stateCopy,
|
||||||
Desired: desired,
|
Desired: desired,
|
||||||
Result: result.DeepCopy(),
|
Result: result.DeepCopy(),
|
||||||
|
@ -190,7 +190,7 @@ func (p *shadowResourceProviderReal) Refresh(
|
||||||
stateCopy := state.DeepCopy()
|
stateCopy := state.DeepCopy()
|
||||||
|
|
||||||
result, err := p.ResourceProvider.Refresh(info, state)
|
result, err := p.ResourceProvider.Refresh(info, state)
|
||||||
p.Shared.Refresh.SetValue(info.HumanId(), &shadowResourceProviderRefresh{
|
p.Shared.Refresh.SetValue(info.uniqueId(), &shadowResourceProviderRefresh{
|
||||||
State: stateCopy,
|
State: stateCopy,
|
||||||
Result: result.DeepCopy(),
|
Result: result.DeepCopy(),
|
||||||
ResultErr: err,
|
ResultErr: err,
|
||||||
|
@ -420,7 +420,7 @@ func (p *shadowResourceProviderShadow) Apply(
|
||||||
state *InstanceState,
|
state *InstanceState,
|
||||||
diff *InstanceDiff) (*InstanceState, error) {
|
diff *InstanceDiff) (*InstanceState, error) {
|
||||||
// Unique key
|
// Unique key
|
||||||
key := info.HumanId()
|
key := info.uniqueId()
|
||||||
raw := p.Shared.Apply.Value(key)
|
raw := p.Shared.Apply.Value(key)
|
||||||
if raw == nil {
|
if raw == nil {
|
||||||
p.ErrorLock.Lock()
|
p.ErrorLock.Lock()
|
||||||
|
@ -459,7 +459,7 @@ func (p *shadowResourceProviderShadow) Diff(
|
||||||
state *InstanceState,
|
state *InstanceState,
|
||||||
desired *ResourceConfig) (*InstanceDiff, error) {
|
desired *ResourceConfig) (*InstanceDiff, error) {
|
||||||
// Unique key
|
// Unique key
|
||||||
key := info.HumanId()
|
key := info.uniqueId()
|
||||||
raw := p.Shared.Diff.Value(key)
|
raw := p.Shared.Diff.Value(key)
|
||||||
if raw == nil {
|
if raw == nil {
|
||||||
p.ErrorLock.Lock()
|
p.ErrorLock.Lock()
|
||||||
|
@ -502,7 +502,7 @@ func (p *shadowResourceProviderShadow) Refresh(
|
||||||
info *InstanceInfo,
|
info *InstanceInfo,
|
||||||
state *InstanceState) (*InstanceState, error) {
|
state *InstanceState) (*InstanceState, error) {
|
||||||
// Unique key
|
// Unique key
|
||||||
key := info.HumanId()
|
key := info.uniqueId()
|
||||||
raw := p.Shared.Refresh.Value(key)
|
raw := p.Shared.Refresh.Value(key)
|
||||||
if raw == nil {
|
if raw == nil {
|
||||||
p.ErrorLock.Lock()
|
p.ErrorLock.Lock()
|
||||||
|
|
|
@ -862,7 +862,7 @@ func (n *graphNodeExpandedResourceDestroy) ConfigType() GraphNodeConfigType {
|
||||||
// GraphNodeEvalable impl.
|
// GraphNodeEvalable impl.
|
||||||
func (n *graphNodeExpandedResourceDestroy) EvalTree() EvalNode {
|
func (n *graphNodeExpandedResourceDestroy) EvalTree() EvalNode {
|
||||||
info := n.instanceInfo()
|
info := n.instanceInfo()
|
||||||
info.Id += " (destroy)"
|
info.uniqueExtra = "destroy"
|
||||||
|
|
||||||
var diffApply *InstanceDiff
|
var diffApply *InstanceDiff
|
||||||
var provider ResourceProvider
|
var provider ResourceProvider
|
||||||
|
|
Loading…
Reference in New Issue