Skip to content

Commit 12d79e1

Browse files
authored
Delete task resources when creation fails (#350)
* Delete task resources when creation fails * Add human–friendly error messages
1 parent ddf38b7 commit 12d79e1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

iterative/resource_task.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package iterative
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"strings"
78
"time"
@@ -145,7 +146,12 @@ func resourceTaskCreate(ctx context.Context, d *schema.ResourceData, m interface
145146
}
146147

147148
if err := task.Create(ctx); err != nil {
148-
return diagnostic(diags, err, diag.Error)
149+
diags = diagnostic(diags, err, diag.Error)
150+
if err := task.Delete(ctx); err == nil {
151+
diags = diagnostic(diags, errors.New("deleted all the remaining resources"), diag.Warning)
152+
} else {
153+
diags = diagnostic(diags, err, diag.Error)
154+
}
149155
}
150156

151157
d.SetId(task.GetIdentifier(ctx).Long())

0 commit comments

Comments
 (0)