Skip to content

Commit

Permalink
WIP computed map perpetual diff debugging
Browse files Browse the repository at this point in the history
refs #1607
  • Loading branch information
phinze committed Apr 20, 2015
1 parent 4d82d0a commit efb3b73
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion helper/schema/field_reader_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func (r *MapFieldReader) readMap(k string) (FieldReadResult, error) {
prefix := k + "."
r.Map.Range(func(k, v string) bool {
if strings.HasPrefix(k, prefix) {
resultSet = true
key := k[len(prefix):]
if key != "#" {
result[key] = v
resultSet = true
}
}

Expand Down
1 change: 1 addition & 0 deletions helper/schema/field_writer_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (w *MapFieldWriter) setMap(
if len(vs) == 0 {
// The empty string here means the map is removed.
w.result[k] = ""
w.result[k+".#"] = "0"
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions helper/schema/field_writer_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,11 @@ func TestMapFieldWriter(t *testing.T) {

"map delete": {
[]string{"map"},
nil,
map[string]interface{}{},
false,
map[string]string{
"map": "",
"map.#": "0",
"map": "",
},
},

Expand Down
4 changes: 3 additions & 1 deletion helper/schema/resource_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2512,7 +2512,9 @@ func TestResourceDataState(t *testing.T) {
},

Result: &terraform.InstanceState{
Attributes: map[string]string{},
Attributes: map[string]string{
"tags.#": "0",
},
},
},

Expand Down
4 changes: 4 additions & 0 deletions helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package schema

import (
"fmt"
"log"
"os"
"reflect"
"sort"
Expand Down Expand Up @@ -634,6 +635,9 @@ func (m schemaMap) diffMap(
return fmt.Errorf("%s: %s", k, err)
}

log.Printf("configMap: %#v", configMap)
log.Printf("stateMap: %#v", stateMap)

// Delete any count values, since we don't use those
delete(configMap, "#")
delete(stateMap, "#")
Expand Down
22 changes: 22 additions & 0 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,28 @@ func TestSchemaMap_Diff(t *testing.T) {

Err: false,
},

// #57 - Computed map known to be empty doesn't generate diff
{
Schema: map[string]*Schema{
"tags": &Schema{
Type: TypeMap,
Computed: true,
},
},

Config: nil,

State: &terraform.InstanceState{
Attributes: map[string]string{
"tags.#": "0",
},
},

Diff: nil,

Err: false,
},
}

for i, tc := range cases {
Expand Down

0 comments on commit efb3b73

Please sign in to comment.