Skip to content
Open
Changes from 1 commit
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
18 changes: 13 additions & 5 deletions dashboards/resource_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ type Dashboard struct {
DashboardChangeDetected bool `json:"dashboard_change_detected,omitempty"`
}

func customDiffSerializedDashboard(k, old, new string, d *schema.ResourceData) bool {
_, newHash, err := common.ReadSerializedJsonContent(new, d.Get("file_path").(string))
func customDiffDashboardContent(k, old, new string, d *schema.ResourceData) bool {
// Read both serialized_dashboard and file_path from the new config
serializedDashboard := d.Get("serialized_dashboard").(string)
filePath := d.Get("file_path").(string)

Comment on lines +24 to +27
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function ignores the new parameter passed to it and always reads from d.Get(). This means when the file_path attribute changes, the function will still read the old path value from the resource data instead of the new value. Consider using the new parameter when k is 'file_path' to ensure the updated file content is read: if k == \"file_path\" { filePath = new }

Suggested change
// Read both serialized_dashboard and file_path from the new config
serializedDashboard := d.Get("serialized_dashboard").(string)
filePath := d.Get("file_path").(string)
// Use the new value for the attribute being diffed
serializedDashboard := d.Get("serialized_dashboard").(string)
filePath := d.Get("file_path").(string)
// If the diff is for serialized_dashboard or file_path, use the new value
if k == "serialized_dashboard" {
serializedDashboard = new
}
if k == "file_path" {
filePath = new
}

Copilot uses AI. Check for mistakes.
_, newHash, err := common.ReadSerializedJsonContent(serializedDashboard, filePath)
if err != nil {
return false
return false // Show diff on error
}
// Suppress diff if: stored MD5 matches new hash AND no external changes detected
return d.Get("md5").(string) == newHash && !d.Get("dashboard_change_detected").(bool)
}

Expand Down Expand Up @@ -53,8 +58,11 @@ func (Dashboard) CustomizeSchema(s *common.CustomizableSchema) *common.Customiza
// Default values
s.SchemaPath("embed_credentials").SetDefault(true)

// DiffSuppressFunc
s.SchemaPath("serialized_dashboard").SetCustomSuppressDiff(customDiffSerializedDashboard)
// DiffSuppressFunc - Custom diff logic for serialized_dashboard
s.SchemaPath("serialized_dashboard").SetCustomSuppressDiff(customDiffDashboardContent)

// Apply same custom diff to file_path to enable content change detection
s.SchemaPath("file_path").SetCustomSuppressDiff(customDiffDashboardContent)

return s
}
Expand Down
Loading