terraform: setup proper count.index value for interpolation

This commit is contained in:
Mitchell Hashimoto 2015-02-11 22:56:35 -08:00
parent cbbe9cb588
commit 14aee00bf0
2 changed files with 15 additions and 6 deletions

View File

@ -567,12 +567,11 @@ func TestContext2Plan_countComputed(t *testing.T) {
} }
} }
/* func TestContext2Plan_countIndex(t *testing.T) {
func TestContextPlan_countIndex(t *testing.T) {
m := testModule(t, "plan-count-index") m := testModule(t, "plan-count-index")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Module: m, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
@ -591,6 +590,7 @@ func TestContextPlan_countIndex(t *testing.T) {
} }
} }
/*
func TestContextPlan_countIndexZero(t *testing.T) { func TestContextPlan_countIndexZero(t *testing.T) {
m := testModule(t, "plan-count-index-zero") m := testModule(t, "plan-count-index-zero")
p := testProvider("aws") p := testProvider("aws")

View File

@ -89,13 +89,21 @@ func (n *graphNodeExpandedResource) ProvidedBy() []string {
// GraphNodeEvalable impl. // GraphNodeEvalable impl.
func (n *graphNodeExpandedResource) EvalTree() EvalNode { func (n *graphNodeExpandedResource) EvalTree() EvalNode {
resource := &Resource{CountIndex: n.Index}
// Shared node for interpolation of configuration
interpolateNode := &EvalInterpolate{
Config: n.Resource.RawConfig,
Resource: resource,
}
seq := &EvalSequence{Nodes: make([]EvalNode, 0, 5)} seq := &EvalSequence{Nodes: make([]EvalNode, 0, 5)}
// Validate the resource // Validate the resource
vseq := &EvalSequence{Nodes: make([]EvalNode, 0, 5)} vseq := &EvalSequence{Nodes: make([]EvalNode, 0, 5)}
vseq.Nodes = append(vseq.Nodes, &EvalValidateResource{ vseq.Nodes = append(vseq.Nodes, &EvalValidateResource{
Provider: &EvalGetProvider{Name: n.ProvidedBy()[0]}, Provider: &EvalGetProvider{Name: n.ProvidedBy()[0]},
Config: &EvalInterpolate{Config: n.Resource.RawConfig}, Config: interpolateNode,
ResourceName: n.Resource.Name, ResourceName: n.Resource.Name,
ResourceType: n.Resource.Type, ResourceType: n.Resource.Type,
}) })
@ -104,7 +112,8 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
for _, p := range n.Resource.Provisioners { for _, p := range n.Resource.Provisioners {
vseq.Nodes = append(vseq.Nodes, &EvalValidateProvisioner{ vseq.Nodes = append(vseq.Nodes, &EvalValidateProvisioner{
Provisioner: &EvalGetProvisioner{Name: p.Type}, Provisioner: &EvalGetProvisioner{Name: p.Type},
Config: &EvalInterpolate{Config: p.RawConfig}, Config: &EvalInterpolate{
Config: p.RawConfig, Resource: resource},
}) })
} }
@ -145,7 +154,7 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
Dependencies: n.DependentOn(), Dependencies: n.DependentOn(),
State: &EvalDiff{ State: &EvalDiff{
Info: info, Info: info,
Config: &EvalInterpolate{Config: n.Resource.RawConfig}, Config: interpolateNode,
Provider: &EvalGetProvider{Name: n.ProvidedBy()[0]}, Provider: &EvalGetProvider{Name: n.ProvidedBy()[0]},
State: &EvalReadState{Name: n.stateId()}, State: &EvalReadState{Name: n.stateId()},
Output: &diff, Output: &diff,