Skip to content

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

@Drodevbar

Description

@Drodevbar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions