diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 452f0e08d8..1a56ad5a3d 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -995,7 +995,7 @@ func (m schemaMap) diffString( all bool) error { var originalN interface{} var os, ns string - o, n, _, _ := d.diffChange(k) + o, n, _, computed := d.diffChange(k) if schema.StateFunc != nil && n != nil { originalN = n n = schema.StateFunc(n) @@ -1019,7 +1019,7 @@ func (m schemaMap) diffString( } // Otherwise, only continue if we're computed - if !schema.Computed { + if !schema.Computed && !computed { return nil } } @@ -1033,10 +1033,11 @@ func (m schemaMap) diffString( } diff.Attributes[k] = schema.finalizeDiff(&terraform.ResourceAttrDiff{ - Old: os, - New: ns, - NewExtra: originalN, - NewRemoved: removed, + Old: os, + New: ns, + NewExtra: originalN, + NewRemoved: removed, + NewComputed: computed, }) return nil diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index bb96c6a719..9511f363b3 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -439,8 +439,9 @@ func TestSchemaMap_Diff(t *testing.T) { Diff: &terraform.InstanceDiff{ Attributes: map[string]*terraform.ResourceAttrDiff{ "availability_zone": &terraform.ResourceAttrDiff{ - Old: "", - New: "${var.foo}", + Old: "", + New: "${var.foo}", + NewComputed: true, }, }, }, @@ -1675,8 +1676,9 @@ func TestSchemaMap_Diff(t *testing.T) { New: "1", }, "route.~1.gateway": &terraform.ResourceAttrDiff{ - Old: "", - New: "${var.foo}", + Old: "", + New: "${var.foo}", + NewComputed: true, }, }, }, diff --git a/terraform/diff.go b/terraform/diff.go index a50c0b82b3..488b63b68a 100644 --- a/terraform/diff.go +++ b/terraform/diff.go @@ -611,6 +611,13 @@ func (d *InstanceDiff) Same(d2 *InstanceDiff) (bool, string) { continue } + // If the last diff was a computed value then the absense of + // that value is allowed since it may mean the value ended up + // being the same. + if diffOld.NewComputed { + continue + } + // No exact match, but maybe this is a set containing computed // values. So check if there is an approximate hash in the key // and if so, try to match the key. diff --git a/terraform/diff_test.go b/terraform/diff_test.go index 0970609aa7..9f7816f63c 100644 --- a/terraform/diff_test.go +++ b/terraform/diff_test.go @@ -567,6 +567,47 @@ func TestInstanceDiffSame(t *testing.T) { "diff RequiresNew; old: true, new: false", }, + // NewComputed on primitive + { + &InstanceDiff{ + Attributes: map[string]*ResourceAttrDiff{ + "foo": &ResourceAttrDiff{ + Old: "", + New: "${var.foo}", + NewComputed: true, + }, + }, + }, + &InstanceDiff{ + Attributes: map[string]*ResourceAttrDiff{ + "foo": &ResourceAttrDiff{ + Old: "0", + New: "1", + }, + }, + }, + true, + "", + }, + + // NewComputed on primitive, removed + { + &InstanceDiff{ + Attributes: map[string]*ResourceAttrDiff{ + "foo": &ResourceAttrDiff{ + Old: "", + New: "${var.foo}", + NewComputed: true, + }, + }, + }, + &InstanceDiff{ + Attributes: map[string]*ResourceAttrDiff{}, + }, + true, + "", + }, + { &InstanceDiff{ Attributes: map[string]*ResourceAttrDiff{