mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
terraform: nil diffs should not be written to the diff
This commit is contained in:
parent
32e714c41d
commit
10a216d85e
@ -442,12 +442,11 @@ func TestContext2Plan_moduleVarComputed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestContextPlan_nil(t *testing.T) {
|
||||
func TestContext2Plan_nil(t *testing.T) {
|
||||
m := testModule(t, "plan-nil")
|
||||
p := testProvider("aws")
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext(t, &ContextOpts{
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -478,6 +477,7 @@ func TestContextPlan_nil(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestContextPlan_computed(t *testing.T) {
|
||||
m := testModule(t, "plan-computed")
|
||||
p := testProvider("aws")
|
||||
|
@ -333,6 +333,10 @@ func (d *InstanceDiff) Empty() bool {
|
||||
return !d.Destroy && len(d.Attributes) == 0
|
||||
}
|
||||
|
||||
func (d *InstanceDiff) GoString() string {
|
||||
return fmt.Sprintf("*%#v", *d)
|
||||
}
|
||||
|
||||
// RequiresNew returns true if the diff requires the creation of a new
|
||||
// resource (implying the destruction of the old).
|
||||
func (d *InstanceDiff) RequiresNew() bool {
|
||||
|
@ -162,6 +162,12 @@ func (n *EvalWriteDiff) Eval(
|
||||
ctx EvalContext, args []interface{}) (interface{}, error) {
|
||||
diff, lock := ctx.Diff()
|
||||
|
||||
// The diff to write, if its empty it should write nil
|
||||
diffVal := n.Diff
|
||||
if diffVal.Empty() {
|
||||
diffVal = nil
|
||||
}
|
||||
|
||||
// Acquire the lock so that we can do this safely concurrently
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
@ -171,7 +177,11 @@ func (n *EvalWriteDiff) Eval(
|
||||
if modDiff == nil {
|
||||
modDiff = diff.AddModule(ctx.Path())
|
||||
}
|
||||
modDiff.Resources[n.Name] = n.Diff
|
||||
if diffVal != nil {
|
||||
modDiff.Resources[n.Name] = diffVal
|
||||
} else {
|
||||
delete(modDiff.Resources, n.Name)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user