From caadb4297f74c7df58a49caaee9874ab7c4385bb Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 21 Apr 2017 17:33:10 -0400 Subject: [PATCH] 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. --- helper/schema/schema.go | 1 + helper/schema/schema_test.go | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index d04f05b35..7eac81d21 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -744,6 +744,7 @@ func (m schemaMap) diffList( diff.Attributes[k+".#"] = &terraform.ResourceAttrDiff{ Old: oldStr, NewComputed: true, + RequiresNew: schema.ForceNew, } return nil } diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index d2f667576..44af1bfb4 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -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 {