Skip to content

Commit

Permalink
Add edge tests, yay
Browse files Browse the repository at this point in the history
  • Loading branch information
Pam Selle committed Jul 16, 2019
1 parent 90cff2e commit 07a65d6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
76 changes: 76 additions & 0 deletions terraform/graph_builder_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,51 @@ func TestPlanGraphBuilder_targetModule(t *testing.T) {
testGraphNotContains(t, g, "module.child1.test_object.foo")
}

func TestPlanGraphBuilder_forEach(t *testing.T) {
awsProvider := &MockProvider{
GetSchemaReturn: &ProviderSchema{
Provider: simpleTestSchema(),
ResourceTypes: map[string]*configschema.Block{
"aws_instance": simpleTestSchema(),
},
},
}

components := &basicComponentFactory{
providers: map[string]providers.Factory{
"aws": providers.FactoryFixed(awsProvider),
},
}

b := &PlanGraphBuilder{
Config: testModule(t, "plan-for-each"),
Components: components,
Schemas: &Schemas{
Providers: map[string]*ProviderSchema{
"aws": awsProvider.GetSchemaReturn,
},
},
DisableReduce: true,
}

g, err := b.Build(addrs.RootModuleInstance)
if err != nil {
t.Fatalf("err: %s", err)
}

if g.Path.String() != addrs.RootModuleInstance.String() {
t.Fatalf("wrong module path %q", g.Path)
}

actual := strings.TrimSpace(g.String())
// We're especially looking for the edge here, where aws_instance.bat
// has a dependency on aws_instance.boo
expected := strings.TrimSpace(testPlanGraphBuilderForEachStr)
if actual != expected {
t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual)
}
}

const testPlanGraphBuilderStr = `
aws_instance.web
aws_security_group.firewall
Expand Down Expand Up @@ -290,3 +335,34 @@ root
provider.openstack (close)
var.foo
`
const testPlanGraphBuilderForEachStr = `
aws_instance.bar
provider.aws
aws_instance.bat
aws_instance.boo
provider.aws
aws_instance.baz
provider.aws
aws_instance.boo
provider.aws
aws_instance.foo
provider.aws
meta.count-boundary (EachMode fixup)
aws_instance.bar
aws_instance.bat
aws_instance.baz
aws_instance.boo
aws_instance.foo
provider.aws
provider.aws
provider.aws (close)
aws_instance.bar
aws_instance.bat
aws_instance.baz
aws_instance.boo
aws_instance.foo
provider.aws
root
meta.count-boundary (EachMode fixup)
provider.aws (close)
`
2 changes: 2 additions & 0 deletions terraform/node_resource_abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ func (n *NodeAbstractResource) References() []*addrs.Reference {

refs, _ := lang.ReferencesInExpr(c.Count)
result = append(result, refs...)
refs, _ = lang.ReferencesInExpr(c.ForEach)
result = append(result, refs...)
refs, _ = lang.ReferencesInBlock(c.Config, n.Schema)
result = append(result, refs...)
if c.Managed != nil {
Expand Down

0 comments on commit 07a65d6

Please sign in to comment.