@@ -123,7 +123,31 @@ func (r *ResourceSqlWarehouse) DoCreate(ctx context.Context, _ *Engine, config *
123123 if err != nil {
124124 return "" , nil , err
125125 }
126- return waiter .Id , nil , nil
126+ id := waiter .Id
127+
128+ if config .Lifecycle == nil || config .Lifecycle .Started == nil {
129+ return id , nil , nil
130+ }
131+
132+ // Always wait for RUNNING first: warehouses start asynchronously.
133+ _ , err = r .client .Warehouses .WaitGetWarehouseRunning (ctx , id , 20 * time .Minute , nil )
134+ if err != nil {
135+ return "" , nil , err
136+ }
137+
138+ if ! * config .Lifecycle .Started {
139+ // started=false: stop the warehouse after it reaches RUNNING.
140+ stopWaiter , err := r .client .Warehouses .Stop (ctx , sql.StopRequest {Id : id })
141+ if err != nil {
142+ return "" , nil , err
143+ }
144+ _ , err = stopWaiter .Get ()
145+ if err != nil {
146+ return "" , nil , err
147+ }
148+ }
149+
150+ return id , nil , nil
127151}
128152
129153// hasWarehouseChanges reports whether the plan entry contains any Update changes
@@ -170,59 +194,25 @@ func (r *ResourceSqlWarehouse) DoUpdate(ctx context.Context, _ *Engine, id strin
170194 desiredStarted := * config .Lifecycle .Started
171195 alreadyRunning := remoteWarehouseIsRunning (entry )
172196 if desiredStarted && ! alreadyRunning {
173- // lifecycle.started=true: fire Start; WaitAfterUpdate polls for RUNNING.
174197 _ , err := r .client .Warehouses .Start (ctx , sql.StartRequest {Id : id })
175- return nil , err
198+ if err != nil {
199+ return nil , err
200+ }
176201 } else if ! desiredStarted && alreadyRunning {
177- // lifecycle.started=false: fire Stop; WaitAfterUpdate polls for STOPPED.
178202 _ , err := r .client .Warehouses .Stop (ctx , sql.StopRequest {Id : id })
179- return nil , err
180- }
181-
182- return nil , nil
183- }
184-
185- // WaitAfterUpdate waits for the warehouse to reach the desired lifecycle state after DoUpdate.
186- func (r * ResourceSqlWarehouse ) WaitAfterUpdate (ctx context.Context , id string , config * SqlWarehouseState ) (* SqlWarehouseRemote , error ) {
187- if config .Lifecycle == nil || config .Lifecycle .Started == nil {
188- return nil , nil
203+ if err != nil {
204+ return nil , err
205+ }
189206 }
190207
191- if * config . Lifecycle . Started {
208+ if desiredStarted {
192209 _ , err := r .client .Warehouses .WaitGetWarehouseRunning (ctx , id , 20 * time .Minute , nil )
193210 return nil , err
194211 }
195-
196212 _ , err := r .client .Warehouses .WaitGetWarehouseStopped (ctx , id , 20 * time .Minute , nil )
197213 return nil , err
198214}
199215
200- // WaitAfterCreate waits for the warehouse to be ready, then stops it if lifecycle.started=false.
201- // Warehouses are created in a starting state; WaitGetWarehouseRunning waits for them to be RUNNING.
202- func (r * ResourceSqlWarehouse ) WaitAfterCreate (ctx context.Context , id string , config * SqlWarehouseState ) (* SqlWarehouseRemote , error ) {
203- if config .Lifecycle == nil || config .Lifecycle .Started == nil {
204- return nil , nil
205- }
206-
207- // Always wait for RUNNING first: warehouses start asynchronously.
208- _ , err := r .client .Warehouses .WaitGetWarehouseRunning (ctx , id , 20 * time .Minute , nil )
209- if err != nil {
210- return nil , err
211- }
212-
213- if ! * config .Lifecycle .Started {
214- // started=false: stop the warehouse after it reaches RUNNING.
215- stopWaiter , err := r .client .Warehouses .Stop (ctx , sql.StopRequest {Id : id })
216- if err != nil {
217- return nil , err
218- }
219- _ , err = stopWaiter .Get ()
220- return nil , err
221- }
222-
223- return nil , nil
224- }
225-
226216func (r * ResourceSqlWarehouse ) DoDelete (ctx context.Context , oldID string , _ * SqlWarehouseState ) error {
227217 return r .client .Warehouses .DeleteById (ctx , oldID )
228218}
0 commit comments