Skip to content

Commit dfc36b9

Browse files
authored
internal: rename PrepareConfig to PrepareState, ConfigType to StateType (#3573)
## Changes Pure refactoring, no functional changes. ## Why Follow to #3531 (comment) We already use STATE to refer to this schema in #3555 Config is ambiguous, we have already bundle config (called input config in terranova). With this rename we have - input config -- what's in databricks.yml - state - what's persisted, what is sent to backend via create/update - remote state - what we get from backend via get requests
1 parent 4f82e08 commit dfc36b9

File tree

14 files changed

+94
-94
lines changed

14 files changed

+94
-94
lines changed

bundle/terranova/apply.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ func (d *DeploymentUnit) Destroy(ctx context.Context, db *tnstate.TerranovaState
3333
}
3434

3535
func (d *DeploymentUnit) Deploy(ctx context.Context, db *tnstate.TerranovaState, inputConfig any, actionType deployplan.ActionType) error {
36-
// Note, config may be different between plan and deploy due to resolved $resource references
37-
config, err := d.Adapter.PrepareConfig(inputConfig)
36+
// Note, newState may be different between plan and deploy due to resolved $resource references
37+
newState, err := d.Adapter.PrepareState(inputConfig)
3838
if err != nil {
3939
return fmt.Errorf("reading config: %w", err)
4040
}
4141

4242
if actionType == deployplan.ActionTypeCreate {
43-
return d.Create(ctx, db, config)
43+
return d.Create(ctx, db, newState)
4444
}
4545

4646
entry, hasEntry := db.GetResourceEntry(d.Group, d.Key)
@@ -55,18 +55,18 @@ func (d *DeploymentUnit) Deploy(ctx context.Context, db *tnstate.TerranovaState,
5555

5656
switch actionType {
5757
case deployplan.ActionTypeRecreate:
58-
return d.Recreate(ctx, db, oldID, config)
58+
return d.Recreate(ctx, db, oldID, newState)
5959
case deployplan.ActionTypeUpdate:
60-
return d.Update(ctx, db, oldID, config)
60+
return d.Update(ctx, db, oldID, newState)
6161
case deployplan.ActionTypeUpdateWithID:
62-
return d.UpdateWithID(ctx, db, oldID, config)
62+
return d.UpdateWithID(ctx, db, oldID, newState)
6363
default:
6464
return fmt.Errorf("internal error: unexpected actionType: %#v", actionType)
6565
}
6666
}
6767

68-
func (d *DeploymentUnit) Create(ctx context.Context, db *tnstate.TerranovaState, config any) error {
69-
newID, remoteState, err := d.Adapter.DoCreate(ctx, config)
68+
func (d *DeploymentUnit) Create(ctx context.Context, db *tnstate.TerranovaState, newState any) error {
69+
newID, remoteState, err := d.Adapter.DoCreate(ctx, newState)
7070
if err != nil {
7171
// No need to prefix error, there is no ambiguity (only one operation - DoCreate) and no additional context (like id)
7272
return err
@@ -79,12 +79,12 @@ func (d *DeploymentUnit) Create(ctx context.Context, db *tnstate.TerranovaState,
7979
return err
8080
}
8181

82-
err = db.SaveState(d.Group, d.Key, newID, config)
82+
err = db.SaveState(d.Group, d.Key, newID, newState)
8383
if err != nil {
8484
return fmt.Errorf("saving state after creating id=%s: %w", newID, err)
8585
}
8686

87-
waitRemoteState, err := d.Adapter.WaitAfterCreate(ctx, config)
87+
waitRemoteState, err := d.Adapter.WaitAfterCreate(ctx, newState)
8888
if err != nil {
8989
return fmt.Errorf("waiting after creating id=%s: %w", newID, err)
9090
}
@@ -97,7 +97,7 @@ func (d *DeploymentUnit) Create(ctx context.Context, db *tnstate.TerranovaState,
9797
return nil
9898
}
9999

100-
func (d *DeploymentUnit) Recreate(ctx context.Context, db *tnstate.TerranovaState, oldID string, config any) error {
100+
func (d *DeploymentUnit) Recreate(ctx context.Context, db *tnstate.TerranovaState, oldID string, newState any) error {
101101
err := d.Adapter.DoDelete(ctx, oldID)
102102
if err != nil {
103103
return fmt.Errorf("deleting old id=%s: %w", oldID, err)
@@ -108,11 +108,11 @@ func (d *DeploymentUnit) Recreate(ctx context.Context, db *tnstate.TerranovaStat
108108
return fmt.Errorf("deleting state: %w", err)
109109
}
110110

111-
return d.Create(ctx, db, config)
111+
return d.Create(ctx, db, newState)
112112
}
113113

114-
func (d *DeploymentUnit) Update(ctx context.Context, db *tnstate.TerranovaState, id string, config any) error {
115-
remoteState, err := d.Adapter.DoUpdate(ctx, id, config)
114+
func (d *DeploymentUnit) Update(ctx context.Context, db *tnstate.TerranovaState, id string, newState any) error {
115+
remoteState, err := d.Adapter.DoUpdate(ctx, id, newState)
116116
if err != nil {
117117
return fmt.Errorf("updating id=%s: %w", id, err)
118118
}
@@ -122,12 +122,12 @@ func (d *DeploymentUnit) Update(ctx context.Context, db *tnstate.TerranovaState,
122122
return err
123123
}
124124

125-
err = db.SaveState(d.Group, d.Key, id, config)
125+
err = db.SaveState(d.Group, d.Key, id, newState)
126126
if err != nil {
127127
return fmt.Errorf("saving state id=%s: %w", id, err)
128128
}
129129

130-
waitRemoteState, err := d.Adapter.WaitAfterUpdate(ctx, config)
130+
waitRemoteState, err := d.Adapter.WaitAfterUpdate(ctx, newState)
131131
if err != nil {
132132
return fmt.Errorf("waiting after updating id=%s: %w", id, err)
133133
}
@@ -141,8 +141,8 @@ func (d *DeploymentUnit) Update(ctx context.Context, db *tnstate.TerranovaState,
141141
return nil
142142
}
143143

144-
func (d *DeploymentUnit) UpdateWithID(ctx context.Context, db *tnstate.TerranovaState, oldID string, config any) error {
145-
newID, remoteState, err := d.Adapter.DoUpdateWithID(ctx, oldID, config)
144+
func (d *DeploymentUnit) UpdateWithID(ctx context.Context, db *tnstate.TerranovaState, oldID string, newState any) error {
145+
newID, remoteState, err := d.Adapter.DoUpdateWithID(ctx, oldID, newState)
146146
if err != nil {
147147
return fmt.Errorf("updating id=%s: %w", oldID, err)
148148
}
@@ -158,12 +158,12 @@ func (d *DeploymentUnit) UpdateWithID(ctx context.Context, db *tnstate.Terranova
158158
return err
159159
}
160160

161-
err = db.SaveState(d.Group, d.Key, newID, config)
161+
err = db.SaveState(d.Group, d.Key, newID, newState)
162162
if err != nil {
163163
return fmt.Errorf("saving state id=%s: %w", oldID, err)
164164
}
165165

166-
waitRemoteState, err := d.Adapter.WaitAfterUpdate(ctx, config)
166+
waitRemoteState, err := d.Adapter.WaitAfterUpdate(ctx, newState)
167167
if err != nil {
168168
return fmt.Errorf("waiting after updating id=%s: %w", newID, err)
169169
}

bundle/terranova/plan.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ func (d *DeploymentUnit) plan(ctx context.Context, client *databricks.WorkspaceC
3535
return "", errors.New("invalid state: empty id")
3636
}
3737

38-
config, err := d.Adapter.PrepareConfig(inputConfig)
38+
newState, err := d.Adapter.PrepareState(inputConfig)
3939
if err != nil {
4040
return "", fmt.Errorf("reading config: %w", err)
4141
}
4242

43-
savedState, err := typeConvert(d.Adapter.ConfigType(), entry.State)
43+
savedState, err := typeConvert(d.Adapter.StateType(), entry.State)
4444
if err != nil {
4545
return "", fmt.Errorf("interpreting state: %w", err)
4646
}
@@ -51,7 +51,7 @@ func (d *DeploymentUnit) plan(ctx context.Context, client *databricks.WorkspaceC
5151
// for integers: compare 0 with actual object ID. As long as real object IDs are never 0 we're good.
5252
// Once we add non-id fields or add per-field details to "bundle plan", we must read dynamic data and deal with references as first class citizen.
5353
// This means distinguishing between 0 that are actually object ids and 0 that are there because typed struct integer cannot contain ${...} string.
54-
return calcDiff(d.Adapter, savedState, config)
54+
return calcDiff(d.Adapter, savedState, newState)
5555
}
5656

5757
func (d *DeploymentUnit) refreshRemoteState(ctx context.Context, id string) error {

0 commit comments

Comments
 (0)