Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Auto-Deploy PR] Seed tries to delete 2 dependant SST stacks defined in the same sst.config.ts simultaneously #37

Open
Drodevbar opened this issue Mar 23, 2023 · 1 comment

Comments

@Drodevbar
Copy link

Drodevbar commented Mar 23, 2023

Steps to reproduce

Create SLS app with 2 stacks. For example:

stack 1

export function Stack1({ stack }: StackContext) {
  const dynamoDbTable = new Table(stack, "SomeDynamoDbTable", {
    fields: {
      pk: "string",
      sk: "string"
    },
    primaryIndex: { partitionKey: "pk", sortKey: "sk" },
  });

  return {
    dynamoDbTable,
  }
}

stack 2 (dependant on stack1)

export function Stack2({ stack }: StackContext) {
  const { dynamoDbTable } = use(Stack1);

  const myFx = new Function(stack, "MyFx", {
    handler: "packages/functions/src/s3/my-fx.handler",
    environment: {
      DDB_TABLE_NAME: dynamoDbTable,
    },
  });
}

Import the stacks together in sst.config.ts

export default {
  config(_input) {
    return {
      name: process.env.SST_APP_NAME!,
      region: process.env.AWS_LAMBDAS_REGION!,
    };
  },
  stacks(app) {
    if (app.stage !== "prod") {
      app.setDefaultRemovalPolicy(RemovalPolicy.DESTROY);
    }

    const stackNamePrefix = `${app.name}-${app.stage}`;

    app.stack(Stack1, { stackName: `${stackNamePrefix}-Stack1` });
    app.stack(Stack2, { stackName: `${stackNamePrefix}-Stack2` });
  }
} satisfies SSTConfig;

Now setup Seed to deploy the SLS stacks on every PR, like below:

Screenshot 2023-03-23 at 17 52 52

Current behaviour

  1. Stack is created correctly when PR is created, Seed correctly handles deploying first Stack1, next Stack2.
  2. When PR is closed, only Stack2 is deleted, Stack1 is not because of the below error (for some reason Seed wants to delete them 2 simultaneously, rather than one by one)

(on the below screenshot SfStack is Stack2 from our example above (dependant), while MyStack is Stack1 from the example)

Screenshot 2023-03-23 at 17 38 33 4

Expected behaviour

  1. When PR is closed, Seed deletes dependant stacks one by one, not all of them at once

Stack

  1. Seed is instructed to use node in version 16.14.2 - there is nothing more in seed.yml other than that n 16.14.2 in before_compile stage
  2. SST version: 2.1.26

I know that there is a possibility to configure deploy phases, however, when I have 2 stacks defined as above in one sst.config.ts, I see that there is no way to distinguish these 2 as separate stacks in Seed. Is there a way to do it like that or if I want to use seed and keep the dependencies between stacks, I should have a separate service as a different SST project (with its own custom directory in my monorepo and sst.config.ts) to make it work like that?

PS1: I am aware that this issue is submitted in seed-run/homepage repository, however, I couldn't find better place to submit this issue.
PS2: When deleting the stacks via SST (npx sst remove), this problem doesn't occur, i.e. SST honours the dependencies between stacks properly.

@Drodevbar Drodevbar changed the title Seed has troubles with deleting dependant SST stacks [Auto-Deploy PR] Seed tries to delete 2 dependant SST stacks simultaneously Mar 23, 2023
@Drodevbar Drodevbar changed the title [Auto-Deploy PR] Seed tries to delete 2 dependant SST stacks simultaneously [Auto-Deploy PR] Seed tries to delete 2 dependant SST stacks defined in the same sst.config.ts simultaneously Mar 24, 2023
@jayair
Copy link
Collaborator

jayair commented Mar 24, 2023

Can you message us on Discord #seed? https://sst.dev/discord

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

No branches or pull requests

2 participants