@@ -43,14 +43,29 @@ func (r *MaintenanceWindowResource) Update(ctx context.Context, req resource.Upd
4343 return
4444 }
4545
46- viewID , spaceID := planMaintenanceWindow .getMaintenanceWindowIDAndSpaceID ()
47- maintenanceWindow , diags : = kibana_oapi .UpdateMaintenanceWindow (ctx , client , spaceID , viewID , body )
46+ maintenanceWindowID , spaceID := planMaintenanceWindow .getMaintenanceWindowIDAndSpaceID ()
47+ diags = kibana_oapi .UpdateMaintenanceWindow (ctx , client , spaceID , maintenanceWindowID , body )
4848 resp .Diagnostics .Append (diags ... )
4949 if resp .Diagnostics .HasError () {
5050 return
5151 }
5252
53- diags = planMaintenanceWindow .fromAPIUpdateResponse (ctx , maintenanceWindow )
53+ /*
54+ * In create/update paths we typically follow the write operation with a read, and then set the state from the read.
55+ * We want to avoid a dirty plan immediately after an apply.
56+ */
57+ readMaintenanceWindowResponse , diags := kibana_oapi .GetMaintenanceWindow (ctx , client , spaceID , maintenanceWindowID )
58+ resp .Diagnostics .Append (diags ... )
59+ if resp .Diagnostics .HasError () {
60+ return
61+ }
62+
63+ if readMaintenanceWindowResponse == nil {
64+ resp .State .RemoveResource (ctx )
65+ return
66+ }
67+
68+ diags = planMaintenanceWindow .fromAPIReadResponse (ctx , readMaintenanceWindowResponse )
5469 resp .Diagnostics .Append (diags ... )
5570 if resp .Diagnostics .HasError () {
5671 return
0 commit comments