helper/schema: reading a diff with computed should return zero value
This commit is contained in:
parent
73726e83b2
commit
91a57b42e8
|
@ -76,17 +76,14 @@ func (r *DiffFieldReader) readPrimitive(
|
|||
if !ok {
|
||||
return FieldReadResult{}, nil
|
||||
}
|
||||
if attrD.NewComputed {
|
||||
return FieldReadResult{
|
||||
Exists: true,
|
||||
Computed: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
result := attrD.New
|
||||
if attrD.NewExtra != nil {
|
||||
if err := mapstructure.WeakDecode(attrD.NewExtra, &result); err != nil {
|
||||
return FieldReadResult{}, err
|
||||
var result string
|
||||
if !attrD.NewComputed {
|
||||
result = attrD.New
|
||||
if attrD.NewExtra != nil {
|
||||
if err := mapstructure.WeakDecode(attrD.NewExtra, &result); err != nil {
|
||||
return FieldReadResult{}, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,8 +93,9 @@ func (r *DiffFieldReader) readPrimitive(
|
|||
}
|
||||
|
||||
return FieldReadResult{
|
||||
Value: returnVal,
|
||||
Exists: true,
|
||||
Value: returnVal,
|
||||
Exists: true,
|
||||
Computed: attrD.NewComputed,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,12 @@ func TestDiffFieldReader(t *testing.T) {
|
|||
New: "string",
|
||||
},
|
||||
|
||||
"stringComputed": &terraform.ResourceAttrDiff{
|
||||
Old: "foo",
|
||||
New: "bar",
|
||||
NewComputed: true,
|
||||
},
|
||||
|
||||
"list.#": &terraform.ResourceAttrDiff{
|
||||
Old: "0",
|
||||
New: "2",
|
||||
|
@ -172,6 +178,17 @@ func TestDiffFieldReader(t *testing.T) {
|
|||
false,
|
||||
},
|
||||
|
||||
"stringComputed": {
|
||||
[]string{"stringComputed"},
|
||||
&Schema{Type: TypeString},
|
||||
FieldReadResult{
|
||||
Value: "",
|
||||
Exists: true,
|
||||
Computed: true,
|
||||
},
|
||||
false,
|
||||
},
|
||||
|
||||
"list": {
|
||||
[]string{"list"},
|
||||
&Schema{
|
||||
|
|
Loading…
Reference in New Issue