Skip to content

Commit 4b72ca2

Browse files
fix(resource_dashboard): force recreate grafana_dashboard if uid changes (#2145)
Signed-off-by: Paulo Dias <[email protected]> Co-authored-by: Igor Suleymanov <[email protected]>
1 parent 973671c commit 4b72ca2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

internal/resources/grafana/resource_dashboard.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ Manages Grafana dashboards.
3838
StateContext: schema.ImportStatePassthroughContext,
3939
},
4040

41+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
42+
oldVal, newVal := d.GetChange("config_json")
43+
oldUID := extractUID(oldVal.(string))
44+
newUID := extractUID(newVal.(string))
45+
if oldUID != newUID {
46+
d.ForceNew("config_json")
47+
}
48+
return nil
49+
},
50+
4151
Schema: map[string]*schema.Schema{
4252
"org_id": orgIDAttribute(),
4353
"uid": {
@@ -301,3 +311,14 @@ func NormalizeDashboardConfigJSON(config interface{}) string {
301311
return string(j)
302312
}
303313
}
314+
315+
func extractUID(jsonStr string) string {
316+
var parsed map[string]interface{}
317+
if err := json.Unmarshal([]byte(jsonStr), &parsed); err != nil {
318+
return ""
319+
}
320+
if uid, ok := parsed["uid"].(string); ok {
321+
return uid
322+
}
323+
return ""
324+
}

0 commit comments

Comments
 (0)