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 {
|
all bool) error {
|
||||||
var originalN interface{}
|
var originalN interface{}
|
||||||
var os, ns string
|
var os, ns string
|
||||||
o, n, _, _ := d.diffChange(k)
|
o, n, _, computed := d.diffChange(k)
|
||||||
if schema.StateFunc != nil && n != nil {
|
if schema.StateFunc != nil && n != nil {
|
||||||
originalN = n
|
originalN = n
|
||||||
n = schema.StateFunc(n)
|
n = schema.StateFunc(n)
|
||||||
|
@ -1019,7 +1019,7 @@ func (m schemaMap) diffString(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, only continue if we're computed
|
// Otherwise, only continue if we're computed
|
||||||
if !schema.Computed {
|
if !schema.Computed && !computed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1037,6 +1037,7 @@ func (m schemaMap) diffString(
|
||||||
New: ns,
|
New: ns,
|
||||||
NewExtra: originalN,
|
NewExtra: originalN,
|
||||||
NewRemoved: removed,
|
NewRemoved: removed,
|
||||||
|
NewComputed: computed,
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -441,6 +441,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
"availability_zone": &terraform.ResourceAttrDiff{
|
"availability_zone": &terraform.ResourceAttrDiff{
|
||||||
Old: "",
|
Old: "",
|
||||||
New: "${var.foo}",
|
New: "${var.foo}",
|
||||||
|
NewComputed: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1677,6 +1678,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
"route.~1.gateway": &terraform.ResourceAttrDiff{
|
"route.~1.gateway": &terraform.ResourceAttrDiff{
|
||||||
Old: "",
|
Old: "",
|
||||||
New: "${var.foo}",
|
New: "${var.foo}",
|
||||||
|
NewComputed: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -611,6 +611,13 @@ func (d *InstanceDiff) Same(d2 *InstanceDiff) (bool, string) {
|
||||||
continue
|
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
|
// No exact match, but maybe this is a set containing computed
|
||||||
// values. So check if there is an approximate hash in the key
|
// values. So check if there is an approximate hash in the key
|
||||||
// and if so, try to match 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",
|
"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{
|
&InstanceDiff{
|
||||||
Attributes: map[string]*ResourceAttrDiff{
|
Attributes: map[string]*ResourceAttrDiff{
|
||||||
|
|
Loading…
Reference in New Issue