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

Custom metadata DiffSuppressFunc - issue #5014 #6734

Merged
merged 4 commits into from May 4, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -85,7 +85,7 @@ func resourceArmPolicySetDefinition() *schema.Resource {
Optional: true,
Computed: true,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: structure.SuppressJsonDiff,
DiffSuppressFunc: policySetDefinitionsMetadataDiffSuppressFunc,
},

"parameters": {
Expand All @@ -105,6 +105,29 @@ func resourceArmPolicySetDefinition() *schema.Resource {
}
}

func policySetDefinitionsMetadataDiffSuppressFunc(_, old, new string, _ *schema.ResourceData) bool {
var oldPolicySetDefinitionsMetadata map[string]interface{}
errOld := json.Unmarshal([]byte(old), &oldPolicySetDefinitionsMetadata)
if errOld != nil {
return false
}

var newPolicySetDefinitionsMetadata map[string]interface{}
errNew := json.Unmarshal([]byte(new), &newPolicySetDefinitionsMetadata)
if errNew != nil {
return false
}

// Ignore the following keys if they're found in the metadata JSON
ignoreKeys := [4]string{"createdBy", "createdOn", "updatedBy", "updatedOn"}
for _, key := range ignoreKeys {
delete(oldPolicySetDefinitionsMetadata, key)
delete(newPolicySetDefinitionsMetadata, key)
}

return reflect.DeepEqual(oldPolicySetDefinitionsMetadata, newPolicySetDefinitionsMetadata)
}

func policyDefinitionsDiffSuppressFunc(_, old, new string, _ *schema.ResourceData) bool {
var oldPolicyDefinitions []policy.DefinitionReference
errOld := json.Unmarshal([]byte(old), &oldPolicyDefinitions)
Expand Down