helper/schema: When having a StateFunc, make sure NewExtra contains
original
This commit is contained in:
parent
ba68be5672
commit
50026a6d5c
|
@ -201,10 +201,6 @@ func (d *ResourceData) diffChange(k string) (interface{}, interface{}, bool) {
|
|||
n.Value = nil
|
||||
}
|
||||
|
||||
if n.Exists && n.Schema.StateFunc != nil {
|
||||
n.Value = n.Schema.StateFunc(n.Value)
|
||||
}
|
||||
|
||||
// Return the old, new, and whether there is a change
|
||||
return o.Value, n.Value, !reflect.DeepEqual(o.Value, n.Value)
|
||||
}
|
||||
|
@ -512,6 +508,13 @@ func (d *ResourceData) getPrimitive(
|
|||
attrD, ok := d.diff.Attributes[k]
|
||||
if ok && !attrD.NewComputed {
|
||||
result = attrD.New
|
||||
if attrD.NewExtra != nil {
|
||||
err := mapstructure.WeakDecode(attrD.NewExtra, &result)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
resultSet = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,32 @@ func TestResourceDataGet(t *testing.T) {
|
|||
Value: "foo",
|
||||
},
|
||||
|
||||
{
|
||||
Schema: map[string]*Schema{
|
||||
"availability_zone": &Schema{
|
||||
Type: TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
|
||||
State: nil,
|
||||
|
||||
Diff: &terraform.ResourceDiff{
|
||||
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||
"availability_zone": &terraform.ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "foo!",
|
||||
NewExtra: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Key: "availability_zone",
|
||||
Value: "foo",
|
||||
},
|
||||
|
||||
{
|
||||
Schema: map[string]*Schema{
|
||||
"availability_zone": &Schema{
|
||||
|
|
|
@ -386,8 +386,13 @@ func (m schemaMap) diffString(
|
|||
schema *Schema,
|
||||
diff *terraform.ResourceDiff,
|
||||
d *ResourceData) error {
|
||||
var originalN interface{}
|
||||
var os, ns string
|
||||
o, n, _ := d.diffChange(k)
|
||||
if schema.StateFunc != nil {
|
||||
originalN = n
|
||||
n = schema.StateFunc(n)
|
||||
}
|
||||
if err := mapstructure.WeakDecode(o, &os); err != nil {
|
||||
return fmt.Errorf("%s: %s", k, err)
|
||||
}
|
||||
|
@ -411,6 +416,7 @@ func (m schemaMap) diffString(
|
|||
diff.Attributes[k] = schema.finalizeDiff(&terraform.ResourceAttrDiff{
|
||||
Old: os,
|
||||
New: ns,
|
||||
NewExtra: originalN,
|
||||
NewRemoved: removed,
|
||||
})
|
||||
|
||||
|
|
|
@ -98,8 +98,9 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
Diff: &terraform.ResourceDiff{
|
||||
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||
"availability_zone": &terraform.ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "foo!",
|
||||
Old: "",
|
||||
New: "foo!",
|
||||
NewExtra: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue