Skip to content

Commit 68bef23

Browse files
authored
direct: Add UpdateableIDResource setting (#3326)
## Why To facilitate parallel operations where ID is known and stable and to catch logic errors where ID is changed where it is not supposed to.
1 parent bcb54fb commit 68bef23

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

bundle/terranova/apply.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ func (d *Deployer) Update(ctx context.Context, resource tnresources.IResource, o
258258
return fmt.Errorf("saving state id=%s: %w", oldID, err)
259259
}
260260

261+
if oldID != newID && !tnresources.UpdateableIDResource[d.group] {
262+
return fmt.Errorf("internal error, unexpected change of ID from %#v to %#v", oldID, newID)
263+
}
264+
261265
err = resource.WaitAfterUpdate(ctx)
262266
if err != nil {
263267
return fmt.Errorf("waiting after updating id=%s: %w", newID, err)

bundle/terranova/tnresources/resource.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ var deletableResources = map[string]DeleteResourceFN{
5050
_sql_warehouses: DeleteSqlWarehouse,
5151
}
5252

53+
// UpdateableIDResource configures whether the resource is allowed to change ID in Update operation. Default is false.
54+
// If ID changes during Update and it is not allowed, deployment of that resource will fail with internal error.
55+
// This allows to make assumptions about references stability (${resources.jobs.foo.id}) when we see that
56+
// operation is going to be "update" & ID is guarantee not to change.
57+
var UpdateableIDResource = map[string]bool{
58+
_schemas: true,
59+
_volumes: true,
60+
}
61+
5362
type IResource interface {
5463
Config() any
5564

@@ -58,6 +67,7 @@ type IResource interface {
5867

5968
// Update the resource. Returns id of the resource.
6069
// Usually returns the same id as oldId but can also return a different one (e.g. schemas and volumes when certain fields are changed)
70+
// Note, UpdateableIDResource[group] must be true for this group if ID can be changed. Otherwise function must return the same ID.
6171
DoUpdate(ctx context.Context, oldID string) (string, error)
6272

6373
WaitAfterCreate(ctx context.Context) error

0 commit comments

Comments
 (0)