Merge pull request #9618 from hashicorp/b-computed-prim

helper/schema,terraform: handle computed primitives in diffs
This commit is contained in:
Mitchell Hashimoto 2016-10-28 10:44:13 -04:00 committed by GitHub
commit 3f36787207
4 changed files with 61 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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