@@ -4,12 +4,14 @@ Copyright © 2025 ALESSIO TONIOLO
44package cmd
55
66import (
7+ "context"
78 "fmt"
89 "log"
910 "net/http"
1011 "strings"
1112
1213 "github.com/atoniolo76/gotoni/pkg/remote"
14+ "github.com/atoniolo76/gotoni/pkg/spicedb"
1315
1416 "github.com/spf13/cobra"
1517)
@@ -130,13 +132,24 @@ Use --all to terminate every running resource for the selected provider.`,
130132 resolvedNames = append (resolvedNames , displayName )
131133 }
132134
135+ ctx := context .Background ()
136+ for _ , id := range instanceIDs {
137+ if err := spicedb .Check (ctx , "resource" , id , "delete" ); err != nil {
138+ log .Fatalf ("Permission denied for %s: %v" , id , err )
139+ }
140+ }
141+
133142 fmt .Printf ("Terminating %s(s): %s\n " , resType , strings .Join (resolvedNames , ", " ))
134143
135144 resp , err := cloudProvider .TerminateInstance (httpClient , apiToken , instanceIDs )
136145 if err != nil {
137146 log .Fatalf ("Error terminating %s(s): %v" , resType , err )
138147 }
139148
149+ for _ , id := range instanceIDs {
150+ spicedb .DeleteResource (ctx , id )
151+ }
152+
140153 // Lambda manages state via API, but we still clean up any leftover config refs
141154 if provider == "lambda" {
142155 for _ , id := range instanceIDs {
0 commit comments