@@ -33,14 +33,14 @@ func (d *DeploymentUnit) Destroy(ctx context.Context, db *tnstate.TerranovaState
3333}
3434
3535func (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 }
0 commit comments