@@ -24,7 +24,11 @@ func resourceScalewayContainer() *schema.Resource {
24
24
StateContext : schema .ImportStatePassthroughContext ,
25
25
},
26
26
Timeouts : & schema.ResourceTimeout {
27
- Default : schema .DefaultTimeout (defaultContainerNamespaceTimeout ),
27
+ Create : schema .DefaultTimeout (defaultContainerTimeout ),
28
+ Read : schema .DefaultTimeout (defaultContainerTimeout ),
29
+ Update : schema .DefaultTimeout (defaultContainerTimeout ),
30
+ Delete : schema .DefaultTimeout (defaultContainerTimeout ),
31
+ Default : schema .DefaultTimeout (defaultContainerTimeout ),
28
32
},
29
33
SchemaVersion : 0 ,
30
34
Schema : map [string ]* schema.Schema {
@@ -167,14 +171,9 @@ func resourceScalewayContainerCreate(ctx context.Context, d *schema.ResourceData
167
171
if region .String () == "" {
168
172
region = scw .RegionFrPar
169
173
}
170
- namespaceID := d .Get ("namespace_id" )
174
+ namespaceID := expandID ( d .Get ("namespace_id" ).( string ) )
171
175
// verify name space state
172
- _ , err = api .WaitForNamespace (& container.WaitForNamespaceRequest {
173
- NamespaceID : expandID (namespaceID ),
174
- Region : region ,
175
- Timeout : scw .TimeDurationPtr (defaultRegistryNamespaceTimeout ),
176
- RetryInterval : DefaultWaitRetryInterval ,
177
- }, scw .WithContext (ctx ))
176
+ _ , err = waitForContainerNamespace (ctx , api , region , namespaceID , d .Timeout (schema .TimeoutCreate ))
178
177
if err != nil {
179
178
return diag .Errorf ("unexpected namespace error: %s" , err )
180
179
}
@@ -192,10 +191,7 @@ func resourceScalewayContainerCreate(ctx context.Context, d *schema.ResourceData
192
191
// check if container should be deployed
193
192
shouldDeploy := d .Get ("deploy" )
194
193
if * expandBoolPtr (shouldDeploy ) {
195
- _ , err := api .WaitForContainer (& container.WaitForContainerRequest {
196
- ContainerID : res .ID ,
197
- Region : region ,
198
- }, scw .WithContext (ctx ))
194
+ _ , err = waitForContainer (ctx , api , res .ID , region , d .Timeout (schema .TimeoutCreate ))
199
195
if err != nil {
200
196
return diag .Errorf ("unexpected waiting container error: %s" , err )
201
197
}
@@ -209,6 +205,11 @@ func resourceScalewayContainerCreate(ctx context.Context, d *schema.ResourceData
209
205
if err != nil {
210
206
return diag .FromErr (err )
211
207
}
208
+
209
+ _ , err = waitForContainer (ctx , api , res .ID , region , d .Timeout (schema .TimeoutCreate ))
210
+ if err != nil {
211
+ return diag .Errorf ("unexpected waiting container error: %s" , err )
212
+ }
212
213
}
213
214
214
215
d .SetId (newRegionalIDString (region , res .ID ))
@@ -222,11 +223,12 @@ func resourceScalewayContainerRead(ctx context.Context, d *schema.ResourceData,
222
223
return diag .FromErr (err )
223
224
}
224
225
225
- co , err := api .WaitForContainer (& container.WaitForContainerRequest {
226
- ContainerID : containerID ,
227
- Region : region ,
228
- }, scw .WithContext (ctx ))
226
+ co , err := waitForContainer (ctx , api , containerID , region , d .Timeout (schema .TimeoutCreate ))
229
227
if err != nil {
228
+ if is404Error (err ) {
229
+ d .SetId ("" )
230
+ return nil
231
+ }
230
232
return diag .Errorf ("unexpected waiting container error: %s" , err )
231
233
}
232
234
@@ -262,52 +264,17 @@ func resourceScalewayContainerUpdate(ctx context.Context, d *schema.ResourceData
262
264
263
265
namespaceID := d .Get ("namespace_id" )
264
266
// verify name space state
265
- _ , err = api .WaitForNamespace (& container.WaitForNamespaceRequest {
266
- NamespaceID : expandID (namespaceID ),
267
- Region : region ,
268
- }, scw .WithContext (ctx ))
267
+ _ , err = waitForContainerNamespace (ctx , api , region , expandID (namespaceID ), d .Timeout (schema .TimeoutUpdate ))
269
268
if err != nil {
270
269
return diag .Errorf ("unexpected namespace error: %s" , err )
271
270
}
272
271
273
272
// check for container state
274
- _ , err = api .WaitForContainer (& container.WaitForContainerRequest {
275
- ContainerID : containerID ,
276
- Region : region ,
277
- }, scw .WithContext (ctx ))
273
+ _ , err = waitForContainer (ctx , api , containerID , region , d .Timeout (schema .TimeoutUpdate ))
278
274
if err != nil {
279
275
return diag .Errorf ("unexpected waiting container error: %s" , err )
280
276
}
281
277
282
- // Warning or Errors can be collected as warnings
283
- var diags diag.Diagnostics
284
-
285
- // check triggers associated
286
- triggers , err := api .ListCrons (& container.ListCronsRequest {
287
- Region : region ,
288
- ContainerID : containerID ,
289
- }, scw .WithContext (ctx ))
290
- if err != nil {
291
- return diag .FromErr (err )
292
- }
293
-
294
- // wait for triggers state
295
- for _ , c := range triggers .Crons {
296
- _ , err := api .WaitForCron (& container.WaitForCronRequest {
297
- CronID : c .ID ,
298
- Region : region ,
299
- Timeout : scw .TimeDurationPtr (defaultContainerNamespaceTimeout ),
300
- RetryInterval : DefaultWaitRetryInterval ,
301
- }, scw .WithContext (ctx ))
302
- if err != nil {
303
- diags = append (diags , diag.Diagnostic {
304
- Severity : diag .Warning ,
305
- Summary : "Warning waiting cron job" ,
306
- Detail : err .Error (),
307
- })
308
- }
309
- }
310
-
311
278
// update container
312
279
req := & container.UpdateContainerRequest {
313
280
Region : region ,
@@ -368,12 +335,17 @@ func resourceScalewayContainerUpdate(ctx context.Context, d *schema.ResourceData
368
335
req .Redeploy = expandBoolPtr (d .Get ("deploy" ))
369
336
}
370
337
371
- _ , err = api .UpdateContainer (req , scw .WithContext (ctx ))
338
+ con , err : = api .UpdateContainer (req , scw .WithContext (ctx ))
372
339
if err != nil {
373
340
return diag .FromErr (err )
374
341
}
375
342
376
- return append (diags , resourceScalewayContainerRead (ctx , d , meta )... )
343
+ _ , err = waitForContainer (ctx , api , con .ID , region , d .Timeout (schema .TimeoutUpdate ))
344
+ if err != nil {
345
+ return diag .FromErr (err )
346
+ }
347
+
348
+ return resourceScalewayContainerRead (ctx , d , meta )
377
349
}
378
350
379
351
func resourceScalewayContainerDelete (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
@@ -383,12 +355,9 @@ func resourceScalewayContainerDelete(ctx context.Context, d *schema.ResourceData
383
355
}
384
356
385
357
// check for container state
386
- _ , err = api .WaitForContainer (& container.WaitForContainerRequest {
387
- ContainerID : containerID ,
388
- Region : region ,
389
- }, scw .WithContext (ctx ))
358
+ _ , err = waitForContainer (ctx , api , containerID , region , d .Timeout (schema .TimeoutUpdate ))
390
359
if err != nil {
391
- return diag .Errorf ( "unexpected waiting container error: %s" , err )
360
+ return diag .FromErr ( err )
392
361
}
393
362
394
363
// delete container
0 commit comments