From b255c389e214ef184f2e8e003a76728115be75a2 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Sat, 21 May 2016 13:23:28 -0700 Subject: [PATCH] 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. --- terraform/context_plan_test.go | 18 +++++++++++++++++- terraform/eval_read_data.go | 3 ++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index f7e8cf5d0c..a0dd442ab6 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -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) { diff --git a/terraform/eval_read_data.go b/terraform/eval_read_data.go index 61fa3e1253..4fd8431234 100644 --- a/terraform/eval_read_data.go +++ b/terraform/eval_read_data.go @@ -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 }