Skip to content

Commit 347dce5

Browse files
committed
Adjust folder handling
1 parent f2d4f60 commit 347dce5

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

internal/resources/grafana/resource_dashboard.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ Manages Grafana dashboards.
189189
}
190190

191191
func (r *dashboardResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
192-
// Force replacement when config_json UID changes (matches SDK CustomizeDiff behavior)
192+
// No state during create - return immediately to avoid req.State.Get which fails when
193+
// Framework tries to convert null state to resourceDashboardModel
194+
if req.State.Raw.IsNull() || !req.State.Raw.IsKnown() {
195+
return
196+
}
193197
if req.Plan.Raw.IsNull() {
194198
return
195199
}
@@ -201,11 +205,6 @@ func (r *dashboardResource) ModifyPlan(ctx context.Context, req resource.ModifyP
201205
return
202206
}
203207

204-
// No state during create
205-
if state.ConfigJSON.ValueString() == "" && state.ID.ValueString() == "" {
206-
return
207-
}
208-
209208
oldUID := extractUID(state.ConfigJSON.ValueString())
210209
newUID := extractUID(plan.ConfigJSON.ValueString())
211210
if oldUID != "" && newUID != "" && oldUID != newUID {
@@ -471,14 +470,27 @@ func (r *dashboardResource) readDashboard(ctx context.Context, client *goapi.Gra
471470
urlStr = r.commonClient.GrafanaSubpath(dashboard.Meta.URL)
472471
}
473472

473+
var folderVal types.String
474+
switch {
475+
case dashboard.Meta.FolderUID != "":
476+
// Return org-prefixed format to match grafana_folder.xxx.id (e.g. "1:folder-uid")
477+
folderVal = types.StringValue(MakeOrgResourceID(orgID, dashboard.Meta.FolderUID))
478+
case prior.Folder.IsNull():
479+
// Preserve null when folder was not set and dashboard is in General folder
480+
folderVal = types.StringNull()
481+
default:
482+
// Preserve prior format when empty (e.g. "" or "0")
483+
folderVal = prior.Folder
484+
}
485+
474486
data := &resourceDashboardModel{
475487
ID: types.StringValue(MakeOrgResourceID(orgID, uid)),
476488
OrgID: types.StringValue(strconv.FormatInt(orgID, 10)),
477489
UID: types.StringValue(model["uid"].(string)),
478490
DashboardID: types.Int64Value(int64(model["id"].(float64))),
479491
URL: types.StringValue(urlStr),
480492
Version: types.Int64Value(int64(model["version"].(float64))),
481-
Folder: types.StringValue(dashboard.Meta.FolderUID),
493+
Folder: folderVal,
482494
ConfigJSON: types.StringValue(configJSON),
483495
Overwrite: prior.Overwrite,
484496
Message: prior.Message,

0 commit comments

Comments
 (0)