terraform: error if diff during Apply returns nil

This commit is contained in:
Mitchell Hashimoto 2014-07-22 18:58:22 -07:00
parent 4da83b9eca
commit 79eb52eba6
2 changed files with 30 additions and 6 deletions

View File

@ -487,13 +487,12 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
}
}
// TODO(mitchellh): we need to verify the diff doesn't change
// anything and that the diff has no computed values (pre-computed)
// If we don't have a diff, just make an empty one
// This should never happen because we check if Diff.Empty above.
// If this happened, then the diff above returned a bad diff.
if diff == nil {
diff = new(ResourceDiff)
diff.init()
return fmt.Errorf(
"%s: diff became nil during Apply. This is a bug with " +
"the resource provider. Please report a bug.")
}
// If we do not have any connection info, initialize

View File

@ -408,6 +408,31 @@ func TestContextApply_compute(t *testing.T) {
}
}
func TestContextApply_nilDiff(t *testing.T) {
c := testConfig(t, "apply-good")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{
Config: c,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
if _, err := ctx.Plan(nil); err != nil {
t.Fatalf("err: %s", err)
}
p.DiffFn = func(*ResourceState, *ResourceConfig) (*ResourceDiff, error) {
return nil, nil
}
if _, err := ctx.Apply(); err == nil {
t.Fatal("should error")
}
}
func TestContextApply_Provisioner_compute(t *testing.T) {
c := testConfig(t, "apply-provisioner-compute")
p := testProvider("aws")