core: restore data resource creation diffs

cd0c452 contained a bug where the creation diff for a data resource was
put into a new local variable within the else block rather than into the
diff variable in the parent scope, causing a null diff to always be
produced.

This restores the expected behavior: a computed data resource appears in
the diff, so it can then be fetched during the apply walk.
This commit is contained in:
Martin Atkins 2016-05-21 13:23:28 -07:00
parent d9c137555f
commit b255c389e2
2 changed files with 19 additions and 2 deletions

View File

@ -889,10 +889,26 @@ func TestContext2Plan_computedDataResource(t *testing.T) {
if _, ok := moduleDiff.Resources["aws_instance.foo"]; !ok {
t.Fatalf("missing diff for aws_instance.foo")
}
_, ok := moduleDiff.Resources["data.aws_vpc.bar"]
iDiff, ok := moduleDiff.Resources["data.aws_vpc.bar"]
if !ok {
t.Fatalf("missing diff for data.aws_vpc.bar")
}
expectedDiff := &InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"id": {
NewComputed: true,
RequiresNew: true,
Type: DiffAttrOutput,
},
},
}
if same, _ := expectedDiff.Same(iDiff); !same {
t.Fatalf(
"incorrect diff for data.aws_vpc.bar\ngot: %#v\nwant: %#v",
iDiff, expectedDiff,
)
}
}
func TestContext2Plan_computedList(t *testing.T) {

View File

@ -38,7 +38,8 @@ func (n *EvalReadDataDiff) Eval(ctx EvalContext) (interface{}, error) {
provider := *n.Provider
config := *n.Config
diff, err := provider.ReadDataDiff(n.Info, config)
var err error
diff, err = provider.ReadDataDiff(n.Info, config)
if err != nil {
return nil, err
}