Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Only prefix hashcode with TypeSet diff marker. #1644

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"reflect"
"sort"
"strconv"
"strings"

"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -1691,6 +1696,7 @@ func TestSchemaMap_Diff(t *testing.T) {
map[string]interface{}{
"index": "1",
"gateway": "${var.foo}",
"foo-bar": "baz",
},
},
},
Expand All @@ -1713,6 +1719,10 @@ func TestSchemaMap_Diff(t *testing.T) {
Old: "",
New: "${var.foo}",
},
"route.~1.foo-bar": &terraform.ResourceAttrDiff{
Old: "",
New: "baz",
},
},
},

Expand Down