@@ -5,15 +5,12 @@ package provider
55import (
66 "context"
77 "fmt"
8- speakeasy_stringplanmodifier "github.com/epilot-dev/terraform-provider-epilot-dashboard/internal/planmodifiers/stringplanmodifier"
98 "github.com/epilot-dev/terraform-provider-epilot-dashboard/internal/sdk"
109 "github.com/epilot-dev/terraform-provider-epilot-dashboard/internal/sdk/models/operations"
1110 "github.com/epilot-dev/terraform-provider-epilot-dashboard/internal/validators"
1211 "github.com/hashicorp/terraform-plugin-framework/path"
1312 "github.com/hashicorp/terraform-plugin-framework/resource"
1413 "github.com/hashicorp/terraform-plugin-framework/resource/schema"
15- "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
16- "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1714 "github.com/hashicorp/terraform-plugin-framework/schema/validator"
1815 "github.com/hashicorp/terraform-plugin-framework/types"
1916 "github.com/hashicorp/terraform-plugin-framework/types/basetypes"
@@ -48,32 +45,19 @@ func (r *DashboardResource) Schema(ctx context.Context, req resource.SchemaReque
4845 MarkdownDescription : "Dashboard Resource" ,
4946 Attributes : map [string ]schema.Attribute {
5047 "id" : schema.StringAttribute {
51- Computed : true ,
52- Optional : true ,
53- PlanModifiers : []planmodifier.String {
54- stringplanmodifier .RequiresReplaceIfConfigured (),
55- speakeasy_stringplanmodifier .SuppressDiff (speakeasy_stringplanmodifier .ExplicitSuppress ),
56- },
57- Description : `Unique identifier for dashboard. Requires replacement if changed.` ,
48+ Computed : true ,
49+ Optional : true ,
50+ Description : `Unique identifier for dashboard` ,
5851 },
5952 "tiles" : schema.StringAttribute {
60- Required : true ,
61- PlanModifiers : []planmodifier.String {
62- stringplanmodifier .RequiresReplaceIfConfigured (),
63- speakeasy_stringplanmodifier .SuppressDiff (speakeasy_stringplanmodifier .ExplicitSuppress ),
64- },
65- Description : `Requires replacement if changed.; Parsed as JSON.` ,
53+ Required : true ,
54+ Description : `Parsed as JSON.` ,
6655 Validators : []validator.String {
6756 validators .IsValidJSON (),
6857 },
6958 },
7059 "title" : schema.StringAttribute {
7160 Required : true ,
72- PlanModifiers : []planmodifier.String {
73- stringplanmodifier .RequiresReplaceIfConfigured (),
74- speakeasy_stringplanmodifier .SuppressDiff (speakeasy_stringplanmodifier .ExplicitSuppress ),
75- },
76- Description : `Requires replacement if changed.` ,
7761 },
7862 },
7963 }
@@ -213,7 +197,36 @@ func (r *DashboardResource) Update(ctx context.Context, req resource.UpdateReque
213197 return
214198 }
215199
216- // Not Implemented; all attributes marked as RequiresReplace
200+ dashboard := data .ToSharedDashboard ()
201+ var id string
202+ id = data .ID .ValueString ()
203+
204+ request := operations.PutDashboardRequest {
205+ Dashboard : dashboard ,
206+ ID : id ,
207+ }
208+ res , err := r .client .Dashboards .PutDashboard (ctx , request )
209+ if err != nil {
210+ resp .Diagnostics .AddError ("failure to invoke API" , err .Error ())
211+ if res != nil && res .RawResponse != nil {
212+ resp .Diagnostics .AddError ("unexpected http request/response" , debugResponse (res .RawResponse ))
213+ }
214+ return
215+ }
216+ if res == nil {
217+ resp .Diagnostics .AddError ("unexpected response from API" , fmt .Sprintf ("%v" , res ))
218+ return
219+ }
220+ if res .StatusCode != 200 {
221+ resp .Diagnostics .AddError (fmt .Sprintf ("unexpected response from API. Got an unexpected response code %v" , res .StatusCode ), debugResponse (res .RawResponse ))
222+ return
223+ }
224+ if ! (res .Dashboard != nil ) {
225+ resp .Diagnostics .AddError ("unexpected response from API. Got an unexpected response body" , debugResponse (res .RawResponse ))
226+ return
227+ }
228+ data .RefreshFromSharedDashboard (res .Dashboard )
229+ refreshPlan (ctx , plan , & data , resp .Diagnostics )
217230
218231 // Save updated data into Terraform state
219232 resp .Diagnostics .Append (resp .State .Set (ctx , & data )... )
0 commit comments