@@ -24,6 +24,12 @@ const DeploymentIdOseq = 2
24
24
const DeploymentIdOwner = 3
25
25
const DeploymentIdProvider = 4
26
26
27
+ var ErrDeploymentGone = errors .New ("deployment is gone" )
28
+
29
+ func isDeploymentNotFound (err error ) bool {
30
+ return err != nil && strings .Contains (err .Error (), "not found" ) || strings .Contains (err .Error (), "404" )
31
+ }
32
+
27
33
func resourceDeployment () * schema.Resource {
28
34
return & schema.Resource {
29
35
CreateContext : resourceDeploymentCreate ,
@@ -357,6 +363,11 @@ func resourceDeploymentRead(ctx context.Context, d *schema.ResourceData, m inter
357
363
358
364
deployment , err := akash .GetDeployment (deploymentId [DeploymentIdDseq ], deploymentId [DeploymentIdOwner ])
359
365
if err != nil {
366
+ if isDeploymentNotFound (err ) {
367
+ tflog .Warn (ctx , "Deployment not found - marking for recreation" )
368
+ d .SetId ("" )
369
+ return nil
370
+ }
360
371
return diag .FromErr (err )
361
372
}
362
373
@@ -385,6 +396,11 @@ func resourceDeploymentRead(ctx context.Context, d *schema.ResourceData, m inter
385
396
Oseq : deploymentId [DeploymentIdOseq ],
386
397
}, deploymentId [DeploymentIdProvider ])
387
398
if err != nil {
399
+ if isDeploymentNotFound (err ) {
400
+ tflog .Warn (ctx , "Deployment not found - marking for recreation" )
401
+ d .SetId ("" )
402
+ return nil
403
+ }
388
404
return diag .FromErr (err )
389
405
}
390
406
@@ -457,6 +473,15 @@ func resourceDeploymentUpdate(ctx context.Context, d *schema.ResourceData, m int
457
473
provider := deploymentId [DeploymentIdProvider ]
458
474
459
475
if d .HasChange ("sdl" ) {
476
+ // First verify deployment still exists
477
+ _ , err := akash .GetDeployment (deploymentId [DeploymentIdDseq ], deploymentId [DeploymentIdOwner ])
478
+ if err != nil {
479
+ if isDeploymentNotFound (err ) {
480
+ return diag .FromErr (fmt .Errorf ("%w: cannot update a deployment that was externally closed" , ErrDeploymentGone ))
481
+ }
482
+ return diag .FromErr (err )
483
+ }
484
+
460
485
manifestLocation , err := CreateTemporaryFile (ctx , d .Get ("sdl" ).(string ))
461
486
462
487
// Update the deployment
@@ -491,7 +516,10 @@ func resourceDeploymentDelete(ctx context.Context, d *schema.ResourceData, m int
491
516
492
517
err := akash .DeleteDeployment (deploymentId [DeploymentIdDseq ], deploymentId [DeploymentIdOwner ])
493
518
if err != nil {
494
- return diag .FromErr (err )
519
+ if ! isDeploymentNotFound (err ) {
520
+ return diag .FromErr (err )
521
+ }
522
+ tflog .Warn (ctx , "Deployment was already gone" )
495
523
}
496
524
497
525
// d.SetId("") is automatically called assuming delete returns no errors, but
0 commit comments