Skip to content
Open
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
8 changes: 4 additions & 4 deletions helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,10 +1320,10 @@ func (m schemaMap) diff(
}

logging.HelperSchemaDebug(ctx, "Ignoring change due to DiffSuppressFunc", map[string]interface{}{logging.KeyAttributePath: attrK})
attrV = &terraform.ResourceAttrDiff{
Old: attrV.Old,
New: attrV.Old,
}
// If the diff is suppressed, we want Old = New, but retain the other properties.
updatedAttr := *attrV
updatedAttr.New = attrV.Old
attrV = &updatedAttr
}
}
diff.Attributes[attrK] = attrV
Expand Down
74 changes: 74 additions & 0 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,80 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false,
},

{
Name: "Set with DiffSuppressFunc",
Schema: map[string]*Schema{
"rule": {
Type: TypeSet,
Required: true,
Elem: &Resource{
Schema: map[string]*Schema{
"port": {
Type: TypeInt,
Required: true,
},
"duration": {
Type: TypeString,
Optional: true,
DiffSuppressFunc: func(k, oldValue, newValue string, d *ResourceData) bool {
// Adding a DiffSuppressFunc to an element in a set changes behaviour.
// The actual suppress func doesn't matter.
return oldValue == newValue
},
},
},
},
Set: func(v interface{}) int {
m := v.(map[string]interface{})
port := m["port"].(int)
return port
},
},
},

State: &terraform.InstanceState{
Attributes: map[string]string{
"rule.#": "1",
"rule.80.port": "80",
"rule.80.duration": "",
},
},

Config: map[string]interface{}{
"rule": []interface{}{
map[string]interface{}{
"port": 90,
"duration": "30s",
},
},
},

Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"rule.80.port": {
Old: "80",
New: "0",
NewRemoved: true,
},
"rule.80.duration": {
Old: "",
New: "",
NewRemoved: true,
},
"rule.90.port": {
Old: "",
New: "90",
},
"rule.90.duration": {
Old: "",
New: "30s",
},
},
},

Err: false,
},

{
Name: "List of structure decode",
Schema: map[string]*Schema{
Expand Down
Loading