Skip to content

Commit c008f5e

Browse files
use state config object in sst.config.ts
1 parent 6535fca commit c008f5e

File tree

6 files changed

+55
-11
lines changed

6 files changed

+55
-11
lines changed

cmd/sst/main.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -837,14 +837,6 @@ var root = &cli.Command{
837837
Long: "Only run it for the given component.",
838838
},
839839
},
840-
{
841-
Name: "purge",
842-
Type: "bool",
843-
Description: cli.Description{
844-
Short: "Fully remove the stage state",
845-
Long: "Remove state file and passphrase associated with the stage. Warning: This is irreversible, the state encryption key and all state versions will be unrecoverable.",
846-
},
847-
},
848840
},
849841
Run: CmdRemove,
850842
},

cmd/sst/remove.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ func CmdRemove(c *cli.Cli) error {
4747
err = p.Run(c.Context, &project.StackInput{
4848
Command: "remove",
4949
Target: target,
50-
Purge: c.Bool("purge"),
5150
ServerPort: s.Port,
5251
Verbose: c.Bool("verbose"),
5352
})

pkg/project/project.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import (
2727
"github.com/sst/sst/v3/pkg/runtime/worker"
2828
)
2929

30+
type AppState struct {
31+
PurgeOnRemove bool `json:"purgeOnRemove"`
32+
}
33+
3034
type App struct {
3135
Name string `json:"name"`
3236
Stage string `json:"stage"`
@@ -36,6 +40,7 @@ type App struct {
3640
Version string `json:"version"`
3741
Protect bool `json:"protect"`
3842
Watch []string `json:"watch"`
43+
State *AppState `json:"state"`
3944
// Deprecated: Backend is now Home
4045
Backend string `json:"backend"`
4146
// Deprecated: RemovalPolicy is now Removal

pkg/project/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ loop:
675675

676676
if input.Command == "remove" && len(complete.Resources) == 0 {
677677
provider.Cleanup(p.home, p.app.Name, p.app.Stage)
678-
if input.Purge {
678+
if p.app.State != nil && p.app.State.PurgeOnRemove {
679679
provider.Purge(p.home, p.app.Name, p.app.Stage)
680680
}
681681
}

pkg/project/stack.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ type StackInput struct {
2323
Dev bool
2424
Verbose bool
2525
Continue bool
26-
Purge bool
2726
SkipHash string
2827
PolicyPath string
2928
}

platform/src/config.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,55 @@ export interface App {
286286
* The paths are relative to the project root.
287287
*/
288288
watch?: string[];
289+
290+
/**
291+
* Configure how your app's state is managed.
292+
*
293+
* The state keeps track of all your resources, secrets, and the encryption key. By default,
294+
* this data is preserved via versioning even after `sst remove` so you can recover it if needed.
295+
*
296+
* @example
297+
*
298+
* For example, to fully remove the state file and encryption key:
299+
*
300+
* ```ts
301+
* {
302+
* state: {
303+
* purgeOnRemove: input.stage !== "production"
304+
* }
305+
* }
306+
* ```
307+
*/
308+
state?: {
309+
/**
310+
* If set to `true`, running `sst remove` will fully remove all state associated
311+
* with the stage once all resources have been successfully removed.
312+
*
313+
* This removes the state files and the encryption passphrase.
314+
*
315+
* :::caution
316+
* This is irreversible. The state encryption key and all state versions will be
317+
* unrecoverable.
318+
* :::
319+
*
320+
* :::tip
321+
* Only enable this for ephemeral or development stages.
322+
* :::
323+
*
324+
* @default false
325+
*
326+
* @example
327+
*
328+
* ```ts
329+
* {
330+
* state: {
331+
* purgeOnRemove: true
332+
* }
333+
* }
334+
* ```
335+
*/
336+
purgeOnRemove?: boolean;
337+
};
289338
}
290339

291340
export interface AppInput {

0 commit comments

Comments
 (0)