Skip to content

Commit 51a9b92

Browse files
authored
Migrate grafana_playlist to use Framework SDK (#2573)
* Replace sdkv2 with framework for grafana_playlist * Address doc check * Model playlist items as nested blocks * Centralize org-scoped id parsing
1 parent 3e77e12 commit 51a9b92

File tree

3 files changed

+341
-119
lines changed

3 files changed

+341
-119
lines changed

agent-docs/resources/sdkv2-to-framework-migration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ func (r *fooResource) Delete(ctx context.Context, req resource.DeleteRequest, re
196196

197197
Factoring out a private `r.read(ctx, id string) (*resourceFooModel, diag.Diagnostics)` method is strongly recommended — it is reused by `Read`, `Create` (read-back), `Update` (read-back), and `ImportState`.
198198

199+
**Org-scoped IDs — avoid copy-paste parsing:** If `read`, `Update`, and `Delete` all call `r.clientFromExistingOrgResource(resourceFooID, ...)` and then validate `split` length, type-assert the resource-local id (string, int, etc.), and surface the same diagnostics, extract a **single private helper** (for example `(client, orgID, uid, diags)` for a uid-based resource). That keeps behavior aligned and matches what reviewers expect after several migrations.
200+
201+
**Create — string UID vs numeric fallback:** Some APIs return a primary string identifier and sometimes a legacy numeric id. If you mirror the old SDK pattern `uid := payload.UID; if uid == "" { uid = strconv.FormatInt(payload.ID, 10) }`, only use the numeric branch when **`payload.ID != 0`**. If both are empty/zero, **return a diagnostic** instead of building a composite Terraform id containing `"0"` or another bogus value.
202+
199203
#### 2g. ImportState
200204

201205
```go

docs/resources/playlist.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
page_title: "grafana_playlist Resource - terraform-provider-grafana"
44
subcategory: "Grafana OSS"
55
description: |-
6+
Manages Grafana playlists.
67
Official documentation https://grafana.com/docs/grafana/latest/dashboards/create-manage-playlists/HTTP API https://grafana.com/docs/grafana/latest/developers/http_api/playlist/
78
---
89

910
# grafana_playlist (Resource)
1011

12+
Manages Grafana playlists.
13+
1114
* [Official documentation](https://grafana.com/docs/grafana/latest/dashboards/create-manage-playlists/)
1215
* [HTTP API](https://grafana.com/docs/grafana/latest/developers/http_api/playlist/)
1316

@@ -40,11 +43,11 @@ resource "grafana_playlist" "test" {
4043
### Required
4144

4245
- `interval` (String)
43-
- `item` (Block Set, Min: 1) (see [below for nested schema](#nestedblock--item))
4446
- `name` (String) The name of the playlist.
4547

4648
### Optional
4749

50+
- `item` (Block Set) (see [below for nested schema](#nestedblock--item))
4851
- `org_id` (String) The Organization ID. If not set, the Org ID defined in the provider block will be used.
4952

5053
### Read-Only

0 commit comments

Comments
 (0)