@@ -10,12 +10,14 @@ import (
1010 "github.com/grafana/grafana-openapi-client-go/client/playlists"
1111 "github.com/grafana/grafana-openapi-client-go/models"
1212 "github.com/grafana/terraform-provider-grafana/v4/internal/common"
13+ "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
1314 "github.com/hashicorp/terraform-plugin-framework/attr"
1415 "github.com/hashicorp/terraform-plugin-framework/diag"
1516 "github.com/hashicorp/terraform-plugin-framework/resource"
1617 "github.com/hashicorp/terraform-plugin-framework/resource/schema"
1718 "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1819 "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
20+ "github.com/hashicorp/terraform-plugin-framework/schema/validator"
1921 "github.com/hashicorp/terraform-plugin-framework/types"
2022)
2123
@@ -117,9 +119,28 @@ func (r *playlistResource) Schema(ctx context.Context, req resource.SchemaReques
117119 "interval" : schema.StringAttribute {
118120 Required : true ,
119121 },
120- "item" : schema.SetAttribute {
121- Required : true ,
122- ElementType : types.ObjectType {AttrTypes : playlistItemAttrTypes },
122+ },
123+ Blocks : map [string ]schema.Block {
124+ "item" : schema.SetNestedBlock {
125+ Validators : []validator.Set {
126+ setvalidator .SizeAtLeast (1 ),
127+ },
128+ NestedObject : schema.NestedBlockObject {
129+ Attributes : map [string ]schema.Attribute {
130+ "id" : schema.StringAttribute {
131+ Computed : true ,
132+ },
133+ "order" : schema.Int64Attribute {
134+ Required : true ,
135+ },
136+ "type" : schema.StringAttribute {
137+ Optional : true ,
138+ },
139+ "value" : schema.StringAttribute {
140+ Optional : true ,
141+ },
142+ },
143+ },
123144 },
124145 },
125146 }
@@ -376,8 +397,12 @@ func flattenPlaylistItemsToSet(ctx context.Context, items []*models.PlaylistItem
376397 if order == 0 {
377398 order = int64 (i + 1 )
378399 }
400+ idAttr := types .StringNull ()
401+ if item .ID != 0 {
402+ idAttr = types .StringValue (strconv .FormatInt (item .ID , 10 ))
403+ }
379404 obj , objDiags := types .ObjectValue (playlistItemAttrTypes , map [string ]attr.Value {
380- "id" : types . StringNull () ,
405+ "id" : idAttr ,
381406 "order" : types .Int64Value (order ),
382407 "type" : types .StringValue (item .Type ),
383408 "value" : types .StringValue (item .Value ),
0 commit comments