Merge pull request #9618 from hashicorp/b-computed-prim
helper/schema,terraform: handle computed primitives in diffs
This commit is contained in:
commit
3f36787207
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue