make sure a computed list is can be RequiresNew
If a schema.TypeList had a Schema with ForceNew, and if that list was NewComputed, the diff would not have RequiresNew set. This causes apply to fail when the diffs didn't match because of the change to RequiresNew. Set the RequiresNew field on the list's ResourceAttrDiff based on the Schema value.
This commit is contained in:
parent
c2bd3b5fd4
commit
caadb4297f
|
@ -744,6 +744,7 @@ func (m schemaMap) diffList(
|
||||||
diff.Attributes[k+".#"] = &terraform.ResourceAttrDiff{
|
diff.Attributes[k+".#"] = &terraform.ResourceAttrDiff{
|
||||||
Old: oldStr,
|
Old: oldStr,
|
||||||
NewComputed: true,
|
NewComputed: true,
|
||||||
|
RequiresNew: schema.ForceNew,
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2777,6 +2777,52 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
Name: "List with computed schema and ForceNew",
|
||||||
|
Schema: map[string]*Schema{
|
||||||
|
"config": &Schema{
|
||||||
|
Type: TypeList,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
Elem: &Schema{
|
||||||
|
Type: TypeString,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
State: &terraform.InstanceState{
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"config.#": "2",
|
||||||
|
"config.0": "a",
|
||||||
|
"config.1": "b",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Config: map[string]interface{}{
|
||||||
|
"config": []interface{}{"${var.a}", "${var.b}"},
|
||||||
|
},
|
||||||
|
|
||||||
|
ConfigVariables: map[string]ast.Variable{
|
||||||
|
"var.a": interfaceToVariableSwallowError(
|
||||||
|
config.UnknownVariableValue),
|
||||||
|
"var.b": interfaceToVariableSwallowError(
|
||||||
|
config.UnknownVariableValue),
|
||||||
|
},
|
||||||
|
|
||||||
|
Diff: &terraform.InstanceDiff{
|
||||||
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||||
|
"config.#": &terraform.ResourceAttrDiff{
|
||||||
|
Old: "2",
|
||||||
|
New: "",
|
||||||
|
RequiresNew: true,
|
||||||
|
NewComputed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Err: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range cases {
|
for i, tc := range cases {
|
||||||
|
|
Loading…
Reference in New Issue