Skip to content

Commit

Permalink
resource/job: use semantic jobspec diff
Browse files Browse the repository at this point in the history
The previous implementation of the custom jobspec diff used a naive
string equality check, which can result in unnecessary plan diffs due to
inconsequential changes, like comments or spaces being added/removed.

By reusing the same logic as the `jobspec` field diff we compare the job
struct as it would be submitted to the Nomad API.
  • Loading branch information
lgfa29 committed Jul 26, 2023
1 parent 0189123 commit 665c2f9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nomad/resource_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ func resourceJobCustomizeDiff(_ context.Context, d *schema.ResourceDiff, meta in

oldSpecRaw, newSpecRaw := d.GetChange("jobspec")

if oldSpecRaw.(string) == newSpecRaw.(string) {
if jobspecEqual("jobspec", oldSpecRaw.(string), newSpecRaw.(string), d) {
// nothing to do!
return nil
}
Expand Down Expand Up @@ -937,6 +937,10 @@ func jobTaskGroupsRaw(tgs []*api.TaskGroup) []interface{} {
// jobspecDiffSuppress is the DiffSuppressFunc used by the schema to
// check if two jobspecs are equal.
func jobspecDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
return jobspecEqual(k, old, new, d)
}

func jobspecEqual(k, old, new string, d ResourceFieldGetter) bool {
var oldJob *api.Job
var newJob *api.Job
var oldErr error
Expand Down

0 comments on commit 665c2f9

Please sign in to comment.