mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-03 12:20:28 -06:00
terraform: error if diff during Apply returns nil
This commit is contained in:
parent
4da83b9eca
commit
79eb52eba6
@ -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
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user