diff --git a/helper/schema/schema.go b/helper/schema/schema.go index be5a56aa3..336292227 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -459,9 +459,10 @@ func (m schemaMap) diffList( o, n, _, computedList := d.diffChange(k) nSet := n != nil - // If we have an old value, but no new value set but we're computed, - // then nothing has changed. - if o != nil && n == nil && schema.Computed { + // If we have an old value and no new value is set or will be + // computed once all variables can be interpolated and we're + // computed, then nothing has changed. + if o != nil && n == nil && !computedList && schema.Computed { return nil } diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 5351f61d7..b55ef7dba 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -1466,6 +1466,57 @@ func TestSchemaMap_Diff(t *testing.T) { Err: false, }, + + { + Schema: map[string]*Schema{ + "internal": &Schema{ + Type: TypeBool, + Required: true, + }, + + "instances": &Schema{ + Type: TypeSet, + Elem: &Schema{Type: TypeString}, + Optional: true, + Computed: true, + Set: func(v interface{}) int { + return len(v) + }, + }, + }, + + State: &terraform.InstanceState{ + Attributes: map[string]string{ + "internal": "false", + "instances.#": "0", + }, + }, + + Config: map[string]interface{}{ + "internal": true, + "instances": []interface{}{"${var.foo}"}, + }, + + ConfigVariables: map[string]string{ + "var.foo": config.UnknownVariableValue, + }, + + Diff: &terraform.InstanceDiff{ + Attributes: map[string]*terraform.ResourceAttrDiff{ + "internal": &terraform.ResourceAttrDiff{ + Old: "0", + New: "1", + }, + + "instances.#": &terraform.ResourceAttrDiff{ + Old: "0", + NewComputed: true, + }, + }, + }, + + Err: false, + }, } for i, tc := range cases {