core: StateReferences method should return []addrs.Referenceable

We no longer use strings to represent addresses, so this method was a
leftover outlier from previous refactoring efforts.

At this time the result is not actually being used due to the state type
refactoring, which is a bug we'll address in a subsequent commit.
This commit is contained in:
Martin Atkins 2018-08-31 10:43:50 -07:00
parent 59175e466e
commit 40f00d8db5
4 changed files with 13 additions and 23 deletions

View File

@ -269,16 +269,15 @@ func dottedInstanceAddr(tr addrs.ResourceInstance) string {
// StateReferences returns the dependencies to put into the state for // StateReferences returns the dependencies to put into the state for
// this resource. // this resource.
func (n *NodeAbstractResource) StateReferences() []string { func (n *NodeAbstractResource) StateReferences() []addrs.Referenceable {
selfAddrs := n.ReferenceableAddrs() selfAddrs := n.ReferenceableAddrs()
depsRaw := n.References() depsRaw := n.References()
deps := make([]string, 0, len(depsRaw)) deps := make([]addrs.Referenceable, 0, len(depsRaw))
for _, d := range depsRaw { for _, d := range depsRaw {
switch tr := d.Subject.(type) { switch tr := d.Subject.(type) {
case addrs.ResourceInstance: case addrs.ResourceInstance:
key := dottedInstanceAddr(tr) deps = append(deps, tr)
deps = append(deps, key)
case addrs.Resource: case addrs.Resource:
depStr := tr.String() depStr := tr.String()
selfRef := false selfRef := false
@ -289,16 +288,16 @@ func (n *NodeAbstractResource) StateReferences() []string {
} }
} }
if !selfRef { // Don't create self-references if !selfRef { // Don't create self-references
deps = append(deps, tr.String()) deps = append(deps, tr)
} }
case addrs.ModuleCallInstance: case addrs.ModuleCallInstance:
deps = append(deps, tr.String()) deps = append(deps, tr)
case addrs.ModuleCallOutput: case addrs.ModuleCallOutput:
// For state dependencies, we simplify outputs to just refer // For state dependencies, we simplify outputs to just refer
// to the module as a whole. It's not really clear why we do this, // to the module as a whole. It's not really clear why we do this,
// but this logic is preserved from before the 0.12 rewrite of // but this logic is preserved from before the 0.12 rewrite of
// this function. // this function.
deps = append(deps, tr.Call.String()) deps = append(deps, tr)
default: default:
// No other reference types are recorded in the state. // No other reference types are recorded in the state.
} }

View File

@ -100,14 +100,6 @@ func (n *NodeApplyableResourceInstance) EvalTree() EvalNode {
// Determine the dependencies for the state. // Determine the dependencies for the state.
stateDeps := n.StateReferences() stateDeps := n.StateReferences()
// filter out self-references
filtered := []string{}
for _, d := range stateDeps {
if d != dottedInstanceAddr(addr.Resource) {
filtered = append(filtered, d)
}
}
stateDeps = filtered
// Eval info is different depending on what kind of resource this is // Eval info is different depending on what kind of resource this is
switch n.Config.Mode { switch n.Config.Mode {
@ -120,7 +112,7 @@ func (n *NodeApplyableResourceInstance) EvalTree() EvalNode {
} }
} }
func (n *NodeApplyableResourceInstance) evalTreeDataResource(addr addrs.AbsResourceInstance, stateId string, stateDeps []string) EvalNode { func (n *NodeApplyableResourceInstance) evalTreeDataResource(addr addrs.AbsResourceInstance, stateId string, stateDeps []addrs.Referenceable) EvalNode {
var provider providers.Interface var provider providers.Interface
var providerSchema *ProviderSchema var providerSchema *ProviderSchema
var change *plans.ResourceInstanceChange var change *plans.ResourceInstanceChange
@ -195,7 +187,7 @@ func (n *NodeApplyableResourceInstance) evalTreeDataResource(addr addrs.AbsResou
} }
} }
func (n *NodeApplyableResourceInstance) evalTreeManagedResource(addr addrs.AbsResourceInstance, stateId string, stateDeps []string) EvalNode { func (n *NodeApplyableResourceInstance) evalTreeManagedResource(addr addrs.AbsResourceInstance, stateId string, stateDeps []addrs.Referenceable) EvalNode {
// Declare a bunch of variables that are used for state during // Declare a bunch of variables that are used for state during
// evaluation. Most of this are written to by-address below. // evaluation. Most of this are written to by-address below.
var provider providers.Interface var provider providers.Interface

View File

@ -51,7 +51,7 @@ func (n *NodePlannableResourceInstance) EvalTree() EvalNode {
} }
} }
func (n *NodePlannableResourceInstance) evalTreeDataResource(addr addrs.AbsResourceInstance, stateId string, stateDeps []string) EvalNode { func (n *NodePlannableResourceInstance) evalTreeDataResource(addr addrs.AbsResourceInstance, stateId string, stateDeps []addrs.Referenceable) EvalNode {
config := n.Config config := n.Config
var provider providers.Interface var provider providers.Interface
var providerSchema *ProviderSchema var providerSchema *ProviderSchema
@ -107,7 +107,7 @@ func (n *NodePlannableResourceInstance) evalTreeDataResource(addr addrs.AbsResou
} }
} }
func (n *NodePlannableResourceInstance) evalTreeManagedResource(addr addrs.AbsResourceInstance, stateId string, stateDeps []string) EvalNode { func (n *NodePlannableResourceInstance) evalTreeManagedResource(addr addrs.AbsResourceInstance, stateId string, stateDeps []addrs.Referenceable) EvalNode {
config := n.Config config := n.Config
var provider providers.Interface var provider providers.Interface
var providerSchema *ProviderSchema var providerSchema *ProviderSchema

View File

@ -2,6 +2,7 @@ package terraform
import ( import (
"fmt" "fmt"
"log"
"github.com/hashicorp/terraform/plans" "github.com/hashicorp/terraform/plans"
"github.com/hashicorp/terraform/providers" "github.com/hashicorp/terraform/providers"
@ -133,8 +134,10 @@ func (n *NodeRefreshableManagedResourceInstance) EvalTree() EvalNode {
switch addr.Resource.Resource.Mode { switch addr.Resource.Resource.Mode {
case addrs.ManagedResourceMode: case addrs.ManagedResourceMode:
if n.ResourceState == nil { if n.ResourceState == nil {
log.Printf("[TRACE] NodeRefreshableManagedResourceInstance: %s has no existing state to refresh", addr)
return n.evalTreeManagedResourceNoState() return n.evalTreeManagedResourceNoState()
} }
log.Printf("[TRACE] NodeRefreshableManagedResourceInstance: %s will be refreshed", addr)
return n.evalTreeManagedResource() return n.evalTreeManagedResource()
case addrs.DataResourceMode: case addrs.DataResourceMode:
@ -233,10 +236,6 @@ func (n *NodeRefreshableManagedResourceInstance) evalTreeManagedResourceNoState(
var change *plans.ResourceInstanceChange var change *plans.ResourceInstanceChange
var state *states.ResourceInstanceObject var state *states.ResourceInstanceObject
// Determine the dependencies for the state.
// TODO: Update StateReferences to return []addrs.Referenceable
//state.Dependencies = n.StateReferences()
return &EvalSequence{ return &EvalSequence{
Nodes: []EvalNode{ Nodes: []EvalNode{
&EvalGetProvider{ &EvalGetProvider{