Skip to content

Commit

Permalink
Add a rule for removing diff suppress functions (GoogleCloudPlatform#…
Browse files Browse the repository at this point in the history
…10167)

* Add a rule for removing diff suppress functions

* Add rule link to docs
  • Loading branch information
trodge authored Mar 19, 2024
1 parent 676288e commit d58db7c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/content/develop/breaking-changes/breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ For more information, see
and modifying examples and modules may achieve the intended effect with a smaller blast radius.
* <a name="field-changing-data-format"></a> Modifying how field data is stored in state
* For example, changing the case of a value returned by the API in a flattener or decorder
* Removing diff suppression from a field.
* <a name="field-removing-diff-suppress"></a> Removing diff suppression from a field.
* For MMv1 resources, removing `diff_suppress_func` from a field.
* For handwritten resources, removing `DiffSuppressFunc` from a field.
* Removing update support from a field.
Expand Down
20 changes: 20 additions & 0 deletions tools/diff-processor/rules/rules_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var FieldRules = []FieldRule{
fieldRule_DefaultModification,
fieldRule_GrowingMin,
fieldRule_ShrinkingMax,
fieldRule_RemovingDiffSuppress,
fieldRule_ChangingFieldDataFormat,
}

Expand Down Expand Up @@ -211,6 +212,25 @@ func fieldRule_ShrinkingMax_func(old, new *schema.Schema, mc MessageContext) str
return ""
}

var fieldRule_RemovingDiffSuppress = FieldRule{
name: "Removing Diff Suppress Function",
definition: "Diff suppress functions cannot be removed. Otherwise terraform configurations that previously had no diffs would show diffs.",
message: "Field {{field}} lost its diff suppress function",
identifier: "field-removing-diff-suppress",
isRuleBreak: fieldRule_RemovingDiffSuppress_func,
}

func fieldRule_RemovingDiffSuppress_func(old, new *schema.Schema, mc MessageContext) string {
// ignore for added / removed fields
if old == nil || new == nil {
return ""
}
if old.DiffSuppressFunc != nil && new.DiffSuppressFunc == nil {
return populateMessageContext(mc.message, mc)
}
return ""
}

func fieldRulesToRuleArray(frs []FieldRule) []Rule {
var rules []Rule
for _, fr := range frs {
Expand Down

0 comments on commit d58db7c

Please sign in to comment.