diff --git a/helper/schema/resource_data.go b/helper/schema/resource_data.go index 26d607730..b079dd33c 100644 --- a/helper/schema/resource_data.go +++ b/helper/schema/resource_data.go @@ -291,6 +291,13 @@ func (d *ResourceData) getSet( return result } + // If the entire list is computed, then the entire set is + // necessarilly computed. + if raw.Computed { + result.Computed = true + return result + } + list := raw.Value.([]interface{}) if len(list) == 0 { if len(parts) > 0 { diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 23c283b38..27b685b71 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -641,6 +641,88 @@ func TestSchemaMap_Diff(t *testing.T) { Err: false, }, + { + Schema: map[string]*Schema{ + "ports": &Schema{ + Type: TypeSet, + Required: true, + Elem: &Schema{Type: TypeInt}, + Set: func(a interface{}) int { + return a.(int) + }, + }, + }, + + State: nil, + + Config: map[string]interface{}{ + "ports": []interface{}{"${var.foo}", 1}, + }, + + ConfigVariables: map[string]string{ + "var.foo": "2" + config.InterpSplitDelim + "5", + }, + + Diff: &terraform.InstanceDiff{ + Attributes: map[string]*terraform.ResourceAttrDiff{ + "ports.#": &terraform.ResourceAttrDiff{ + Old: "0", + New: "3", + }, + "ports.0": &terraform.ResourceAttrDiff{ + Old: "", + New: "1", + }, + "ports.1": &terraform.ResourceAttrDiff{ + Old: "", + New: "2", + }, + "ports.2": &terraform.ResourceAttrDiff{ + Old: "", + New: "5", + }, + }, + }, + + Err: false, + }, + + { + Schema: map[string]*Schema{ + "ports": &Schema{ + Type: TypeSet, + Required: true, + Elem: &Schema{Type: TypeInt}, + Set: func(a interface{}) int { + return a.(int) + }, + }, + }, + + State: nil, + + Config: map[string]interface{}{ + "ports": []interface{}{1, "${var.foo}"}, + }, + + ConfigVariables: map[string]string{ + "var.foo": config.UnknownVariableValue + + config.InterpSplitDelim + "5", + }, + + Diff: &terraform.InstanceDiff{ + Attributes: map[string]*terraform.ResourceAttrDiff{ + "ports.#": &terraform.ResourceAttrDiff{ + Old: "0", + New: "", + NewComputed: true, + }, + }, + }, + + Err: false, + }, + { Schema: map[string]*Schema{ "ports": &Schema{