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:
James Bardin 2017-04-21 17:33:10 -04:00
parent c2bd3b5fd4
commit caadb4297f
2 changed files with 47 additions and 0 deletions

View File

@ -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
} }

View File

@ -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 {