@@ -63,52 +63,55 @@ func (m *dataGatewayMapper) AfterRemoteOperation(ctx context.Context, changes *m
6363
6464 // Check if workspace was created and details were set
6565 workspaceID , found , _ = config .Content .GetNested ("parameters.db.workspaceId" )
66- if found && workspaceID != nil && workspaceID != "" {
67- // Update the configuration in remote with workspace details
68- // If this update fails, the workspace exists but the config doesn't reference it.
69- // This creates an inconsistent state, so we return the error to prevent silent failures.
70- api := m .KeboolaProjectAPI ()
71- changedFields := model .NewChangedFields ()
72- changedFields .Add ("configuration" )
73- apiObject , apiChangedFields := config .ToAPIObject ("Workspace created and configuration updated" , changedFields )
74- _ , err := api .UpdateRequest (apiObject , apiChangedFields ).Send (ctx )
75- if err != nil {
76- // Return error instead of logging and continuing.
77- // The workspace has been created and should be used, but the config update failed.
78- // This error must be propagated to prevent inconsistent state.
79- errs .Append (errors .Errorf (`cannot update configuration "%s" with workspace details: %w` , config .Name , err ))
80- continue
66+ if ! found || workspaceID == nil || workspaceID == "" {
67+ continue
68+ }
69+
70+ // Update the configuration in remote with workspace details
71+ // If this update fails, the workspace exists but the config doesn't reference it.
72+ // This creates an inconsistent state, so we return the error to prevent silent failures.
73+ api := m .KeboolaProjectAPI ()
74+ changedFields := model .NewChangedFields ()
75+ changedFields .Add ("configuration" )
76+ apiObject , apiChangedFields := config .ToAPIObject ("Workspace created and configuration updated" , changedFields )
77+ _ , err := api .UpdateRequest (apiObject , apiChangedFields ).Send (ctx )
78+ if err != nil {
79+ // Return error instead of logging and continuing.
80+ // The workspace has been created and should be used, but the config update failed.
81+ // This error must be propagated to prevent inconsistent state.
82+ errs .Append (errors .Errorf (`cannot update configuration "%s" with workspace details: %w` , config .Name , err ))
83+ continue
84+ }
85+ m .logger .Debugf (ctx , `Updated configuration "%s" with workspace details` , config .Name )
86+
87+ // Update remote state with the updated config
88+ configState .SetRemoteState (config )
89+
90+ // Sync workspace details to local state if it exists
91+ if configState .Local == nil {
92+ continue
93+ }
94+ if err := configState .Local .Content .SetNested ("parameters.db.workspaceId" , workspaceID ); err != nil {
95+ m .logger .Warnf (ctx , `Failed to sync workspaceId to local state for config "%s": %s` , config .Name , err .Error ())
96+ }
97+ normalizeWorkspaceID (configState .Local )
98+ // Also sync other workspace details
99+ if host , found , _ := config .Content .GetNested ("parameters.db.host" ); found {
100+ if err := configState .Local .Content .SetNested ("parameters.db.host" , host ); err != nil {
101+ m .logger .Warnf (ctx , `Failed to sync host to local state for config "%s": %s` , config .Name , err .Error ())
102+ }
103+ }
104+ if user , found , _ := config .Content .GetNested ("parameters.db.user" ); found {
105+ if err := configState .Local .Content .SetNested ("parameters.db.user" , user ); err != nil {
106+ m .logger .Warnf (ctx , `Failed to sync user to local state for config "%s": %s` , config .Name , err .Error ())
81107 }
82- m .logger .Debugf (ctx , `Updated configuration "%s" with workspace details` , config .Name )
83-
84- // Update remote state with the updated config
85- configState .SetRemoteState (config )
86-
87- // Sync workspace details to local state if it exists
88- if configState .Local != nil {
89- if err := configState .Local .Content .SetNested ("parameters.db.workspaceId" , workspaceID ); err != nil {
90- m .logger .Warnf (ctx , `Failed to sync workspaceId to local state for config "%s": %s` , config .Name , err .Error ())
91- }
92- normalizeWorkspaceID (configState .Local )
93- // Also sync other workspace details
94- if host , found , _ := config .Content .GetNested ("parameters.db.host" ); found {
95- if err := configState .Local .Content .SetNested ("parameters.db.host" , host ); err != nil {
96- m .logger .Warnf (ctx , `Failed to sync host to local state for config "%s": %s` , config .Name , err .Error ())
97- }
98- }
99- if user , found , _ := config .Content .GetNested ("parameters.db.user" ); found {
100- if err := configState .Local .Content .SetNested ("parameters.db.user" , user ); err != nil {
101- m .logger .Warnf (ctx , `Failed to sync user to local state for config "%s": %s` , config .Name , err .Error ())
102- }
103- }
104- if database , found , _ := config .Content .GetNested ("parameters.db.database" ); found {
105- if err := configState .Local .Content .SetNested ("parameters.db.database" , database ); err != nil {
106- m .logger .Warnf (ctx , `Failed to sync database to local state for config "%s": %s` , config .Name , err .Error ())
107- }
108- }
109- scheduleLocalSave (configState )
108+ }
109+ if database , found , _ := config .Content .GetNested ("parameters.db.database" ); found {
110+ if err := configState .Local .Content .SetNested ("parameters.db.database" , database ); err != nil {
111+ m .logger .Warnf (ctx , `Failed to sync database to local state for config "%s": %s` , config .Name , err .Error ())
110112 }
111113 }
114+ scheduleLocalSave (configState )
112115 }
113116
114117 // Process loaded configs - backfill workspace details
0 commit comments