diff --git a/terraform/context.go b/terraform/context.go index 7d1f436488..b2cd56bf09 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -80,6 +80,10 @@ func (c *Context2) GraphBuilder() GraphBuilder { // Even in the case an error is returned, the state will be returned and // will potentially be partially updated. func (c *Context2) Refresh() (*State, []error) { + // Copy our own state + c.state = c.state.deepcopy() + + // Do the walk if _, err := c.walk(walkRefresh); err != nil { var errs error return nil, multierror.Append(errs, err).Errors diff --git a/terraform/context_test.go b/terraform/context_test.go index 8eecdf01e9..5e0938ea42 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -315,8 +315,7 @@ func TestContext2Refresh_outputPartial(t *testing.T) { } } -/* -func TestContextRefresh_state(t *testing.T) { +func TestContext2Refresh_state(t *testing.T) { p := testProvider("aws") m := testModule(t, "refresh-basic") state := &State{ @@ -333,7 +332,7 @@ func TestContextRefresh_state(t *testing.T) { }, }, } - ctx := testContext(t, &ContextOpts{ + ctx := testContext2(t, &ContextOpts{ Module: m, Providers: map[string]ResourceProviderFactory{ "aws": testProviderFuncFixed(p), @@ -356,13 +355,17 @@ func TestContextRefresh_state(t *testing.T) { t.Fatal("refresh should be called") } if !reflect.DeepEqual(p.RefreshState, originalMod.Resources["aws_instance.web"].Primary) { - t.Fatalf("bad: %#v %#v", p.RefreshState, originalMod.Resources["aws_instance.web"].Primary) + t.Fatalf( + "bad:\n\n%#v\n\n%#v", + p.RefreshState, + originalMod.Resources["aws_instance.web"].Primary) } if !reflect.DeepEqual(mod.Resources["aws_instance.web"].Primary, p.RefreshReturn) { t.Fatalf("bad: %#v", mod.Resources) } } +/* func TestContextRefresh_tainted(t *testing.T) { p := testProvider("aws") m := testModule(t, "refresh-basic")