diff --git a/helper/schema/schema.go b/helper/schema/schema.go index ed8b0ac94a4e..4674eb17661d 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -17,7 +17,6 @@ import ( "reflect" "sort" "strconv" - "strings" "github.com/hashicorp/terraform/terraform" "github.com/mitchellh/mapstructure" @@ -817,7 +816,11 @@ func (m schemaMap) diffSet( // This is a complex resource for k2, schema := range t.Schema { subK := fmt.Sprintf("%s.%d.%s", k, code, k2) - subK = strings.Replace(subK, "-", "~", -1) + // Replace a negative hashcode (computed) with a tilde. The + // tilde is used as a marker when diffing computed keys. + if code < 0 { + subK = fmt.Sprintf("%s.~%d.%s", k, -code, k2) + } err := m.diff(subK, schema, diff, d, true) if err != nil { return err @@ -832,7 +835,11 @@ func (m schemaMap) diffSet( // This is just a primitive element, so go through each and // just diff each. subK := fmt.Sprintf("%s.%d", k, code) - subK = strings.Replace(subK, "-", "~", -1) + // Replace a negative hashcode (computed) with a tilde. The + // tilde is used as a marker when diffing computed keys. + if code < 0 { + subK = fmt.Sprintf("%s.~%d", k, -code) + } err := m.diff(subK, &t2, diff, d, true) if err != nil { return err diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 52980ad80afd..12e543c20a6a 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -1675,6 +1675,11 @@ func TestSchemaMap_Diff(t *testing.T) { Type: TypeString, Optional: true, }, + + "foo-bar": &Schema{ + Type: TypeString, + Optional: true, + }, }, }, Set: func(v interface{}) int { @@ -1691,6 +1696,7 @@ func TestSchemaMap_Diff(t *testing.T) { map[string]interface{}{ "index": "1", "gateway": "${var.foo}", + "foo-bar": "baz", }, }, }, @@ -1713,6 +1719,10 @@ func TestSchemaMap_Diff(t *testing.T) { Old: "", New: "${var.foo}", }, + "route.~1.foo-bar": &terraform.ResourceAttrDiff{ + Old: "", + New: "baz", + }, }, },