Skip to content

Feat: Remove state and encryption key on sst remove#6593

Open
jamesgibbons92 wants to merge 4 commits intoanomalyco:devfrom
jamesgibbons92:5617
Open

Feat: Remove state and encryption key on sst remove#6593
jamesgibbons92 wants to merge 4 commits intoanomalyco:devfrom
jamesgibbons92:5617

Conversation

@jamesgibbons92
Copy link
Copy Markdown
Collaborator

@jamesgibbons92 jamesgibbons92 commented Mar 16, 2026

Closes #5617

This PR adds a state config prop purgeOnRemove to the sst config.
When true, the state file, encryption key and secrets related to the stage are deleted from s3 and ssm.
This replicates the same behaviour as pulumi destroy --remove and cleans up unused passphrases and objects in s3.
This is default false to maintain backwards compatibility.

  app(input) {
    return {
      name: "sst-debug-test",
      removal: input?.stage === "production" ? "retain" : "remove",
      home: "aws",
      providers: {
        aws: {
          region: "eu-west-1",
        },
      },
      state: {
        purgeOnRemove: true,
      },
    };
  },

@vimtor
Copy link
Copy Markdown
Collaborator

vimtor commented Mar 16, 2026

@jamesgibbons92 is this related to #6097?

i like the --purge flag approach a lot better

@jamesgibbons92
Copy link
Copy Markdown
Collaborator Author

@vimtor Yeh similar, as part of this PR I am also remove the app/stage.json state file.

@jamesgibbons92
Copy link
Copy Markdown
Collaborator Author

jamesgibbons92 commented Mar 16, 2026

There is 1 minor issue I need to look into this PR still, if you run sst remove --purge it correctly removes everything (state files, ssm parameter).
However if I run sst remove again, I get "Stage not found" which is correct and expected - however this command is creating an SSM passphrase for the stage, even though we aren't deploying a new stage. There seems to be a getOrSet type method being called which is always initialising the passphrase if it doesn't exist, probably in the boostrap process. Need to check if we can change this so it only creates the passphrase if we're deploying a new stack.

@vimtor
Copy link
Copy Markdown
Collaborator

vimtor commented Apr 2, 2026

related to #6669 (comment) and #6576 (comment)

do you think it could make sense to expose this as a config like this:

export default $config({
  app(input) {
    return {
      name: "my-sst-app",
      home: "aws",
      state: {
        retention: 30,
        compress: true,
        purgeable: true // or a better name 
      }
    };
  },
});

@jamesgibbons92
Copy link
Copy Markdown
Collaborator Author

makes sense if were exposing more configuration options for the state management this way, I was going to implement it this way initially but opted for arg as it was easier at the time. happy to update this when that state config handling lands

@jamesgibbons92 jamesgibbons92 force-pushed the 5617 branch 2 times, most recently from b5d65df to c008f5e Compare April 8, 2026 21:43
@jamesgibbons92
Copy link
Copy Markdown
Collaborator Author

@vimtor I added the config for this, it was fairly straightforward.

one thing this PR does not do is clean up the object versions, maybe this would be covered by #6669 ?

@jamesgibbons92 jamesgibbons92 marked this pull request as ready for review April 8, 2026 22:32
Fixes the issue where secret is attempted to be set before a stage is
deployed and initialised the passphrase
@jamesgibbons92
Copy link
Copy Markdown
Collaborator Author

@vimtor just wondering actually, should we put this config in the home prop, kinda makes more sense as this is related to where the state is stored. it would be a union type so you could have either

   home: "aws"

or

  home: {
    "provider": "aws",
    "purgeOnRemove": true
  }

@vimtor
Copy link
Copy Markdown
Collaborator

vimtor commented Apr 9, 2026

i'm thinking maybe we do this:

state: {
  store: "aws",
  purgeOnRemove: false,
  // etc...
}

and deprecate home in the next major

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Expiry/Deletion of sst/passphrase/* Parameters on Stack Removal

2 participants