terraform: nil diffs should not be written to the diff

This commit is contained in:
Mitchell Hashimoto 2015-02-11 22:44:23 -08:00
parent 32e714c41d
commit 10a216d85e
3 changed files with 18 additions and 4 deletions

View File

@ -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")

View File

@ -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 {

View File

@ -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
}