Skip to content

Commit 3923d84

Browse files
committed
direct: save state before wait in postgres and dashboard resources
All six resources with a gap between resource creation and a subsequent long-running wait now call engine.SaveState immediately after the create API returns, using waiter.Name() (available before Wait()) for the postgres resources and createResp.DashboardId for the dashboard. This ensures an interrupted deployment leaves a tracked resource rather than an orphan the next plan must rediscover from remote state. Co-authored-by: Denis Bilenko
1 parent 7d50128 commit 3923d84

6 files changed

Lines changed: 12 additions & 6 deletions

File tree

bundle/direct/dresources/dashboard.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func responseToState(createOrUpdateResp *dashboards.Dashboard, publishResp *dash
264264
}
265265
}
266266

267-
func (r *ResourceDashboard) DoCreate(ctx context.Context, _ *Engine, config *DashboardState) (string, *DashboardState, error) {
267+
func (r *ResourceDashboard) DoCreate(ctx context.Context, engine *Engine, config *DashboardState) (string, *DashboardState, error) {
268268
dashboard, err := prepareDashboardRequest(config)
269269
if err != nil {
270270
return "", nil, err
@@ -299,6 +299,7 @@ func (r *ResourceDashboard) DoCreate(ctx context.Context, _ *Engine, config *Das
299299

300300
// Persist the etag in state.
301301
config.Etag = createResp.Etag
302+
engine.SaveState(ctx, createResp.DashboardId, config)
302303

303304
var publishResp *dashboards.PublishedDashboard
304305
// Note, today config.Published is always true (we do not have this field in input config).

bundle/direct/dresources/postgres_branch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (r *ResourcePostgresBranch) DoRead(ctx context.Context, id string) (*Postgr
102102
return makePostgresBranchRemote(branch), nil
103103
}
104104

105-
func (r *ResourcePostgresBranch) DoCreate(ctx context.Context, _ *Engine, config *PostgresBranchState) (string, *PostgresBranchRemote, error) {
105+
func (r *ResourcePostgresBranch) DoCreate(ctx context.Context, engine *Engine, config *PostgresBranchState) (string, *PostgresBranchRemote, error) {
106106
waiter, err := r.client.Postgres.CreateBranch(ctx, postgres.CreateBranchRequest{
107107
BranchId: config.BranchId,
108108
Parent: config.Parent,
@@ -124,6 +124,7 @@ func (r *ResourcePostgresBranch) DoCreate(ctx context.Context, _ *Engine, config
124124
if err != nil {
125125
return "", nil, err
126126
}
127+
engine.SaveState(ctx, waiter.Name(), config)
127128

128129
// Wait for the branch to be ready (long-running operation)
129130
result, err := waiter.Wait(ctx)

bundle/direct/dresources/postgres_catalog.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (r *ResourcePostgresCatalog) DoRead(ctx context.Context, id string) (*Postg
9595
return makePostgresCatalogRemote(catalog), nil
9696
}
9797

98-
func (r *ResourcePostgresCatalog) DoCreate(ctx context.Context, _ *Engine, config *PostgresCatalogState) (string, *PostgresCatalogRemote, error) {
98+
func (r *ResourcePostgresCatalog) DoCreate(ctx context.Context, engine *Engine, config *PostgresCatalogState) (string, *PostgresCatalogRemote, error) {
9999
waiter, err := r.client.Postgres.CreateCatalog(ctx, postgres.CreateCatalogRequest{
100100
CatalogId: config.CatalogId,
101101
Catalog: postgres.Catalog{
@@ -113,6 +113,7 @@ func (r *ResourcePostgresCatalog) DoCreate(ctx context.Context, _ *Engine, confi
113113
if err != nil {
114114
return "", nil, err
115115
}
116+
engine.SaveState(ctx, waiter.Name(), config)
116117

117118
result, err := waiter.Wait(ctx)
118119
if err != nil {

bundle/direct/dresources/postgres_endpoint.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (r *ResourcePostgresEndpoint) waitForReconciliation(ctx context.Context, na
141141
}
142142
}
143143

144-
func (r *ResourcePostgresEndpoint) DoCreate(ctx context.Context, _ *Engine, config *PostgresEndpointState) (string, *PostgresEndpointRemote, error) {
144+
func (r *ResourcePostgresEndpoint) DoCreate(ctx context.Context, engine *Engine, config *PostgresEndpointState) (string, *PostgresEndpointRemote, error) {
145145
waiter, err := r.client.Postgres.CreateEndpoint(ctx, postgres.CreateEndpointRequest{
146146
EndpointId: config.EndpointId,
147147
Parent: config.Parent,
@@ -163,6 +163,7 @@ func (r *ResourcePostgresEndpoint) DoCreate(ctx context.Context, _ *Engine, conf
163163
if err != nil {
164164
return "", nil, err
165165
}
166+
engine.SaveState(ctx, waiter.Name(), config)
166167

167168
// Wait for the operation to complete
168169
result, err := waiter.Wait(ctx)

bundle/direct/dresources/postgres_project.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (r *ResourcePostgresProject) DoRead(ctx context.Context, id string) (*Postg
9898
return makePostgresProjectRemote(project), nil
9999
}
100100

101-
func (r *ResourcePostgresProject) DoCreate(ctx context.Context, _ *Engine, config *PostgresProjectState) (string, *PostgresProjectRemote, error) {
101+
func (r *ResourcePostgresProject) DoCreate(ctx context.Context, engine *Engine, config *PostgresProjectState) (string, *PostgresProjectRemote, error) {
102102
waiter, err := r.client.Postgres.CreateProject(ctx, postgres.CreateProjectRequest{
103103
ProjectId: config.ProjectId,
104104
Project: postgres.Project{
@@ -119,6 +119,7 @@ func (r *ResourcePostgresProject) DoCreate(ctx context.Context, _ *Engine, confi
119119
if err != nil {
120120
return "", nil, err
121121
}
122+
engine.SaveState(ctx, waiter.Name(), config)
122123

123124
// Wait for the project to be ready (long-running operation)
124125
result, err := waiter.Wait(ctx)

bundle/direct/dresources/postgres_synced_table.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (r *ResourcePostgresSyncedTable) DoRead(ctx context.Context, id string) (*P
9292
return makePostgresSyncedTableRemote(syncedTable), nil
9393
}
9494

95-
func (r *ResourcePostgresSyncedTable) DoCreate(ctx context.Context, _ *Engine, config *PostgresSyncedTableState) (string, *PostgresSyncedTableRemote, error) {
95+
func (r *ResourcePostgresSyncedTable) DoCreate(ctx context.Context, engine *Engine, config *PostgresSyncedTableState) (string, *PostgresSyncedTableRemote, error) {
9696
waiter, err := r.client.Postgres.CreateSyncedTable(ctx, postgres.CreateSyncedTableRequest{
9797
SyncedTableId: config.SyncedTableId,
9898
SyncedTable: postgres.SyncedTable{
@@ -109,6 +109,7 @@ func (r *ResourcePostgresSyncedTable) DoCreate(ctx context.Context, _ *Engine, c
109109
if err != nil {
110110
return "", nil, err
111111
}
112+
engine.SaveState(ctx, waiter.Name(), config)
112113

113114
result, err := waiter.Wait(ctx)
114115
if err != nil {

0 commit comments

Comments
 (0)