sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.12k stars 136 forks source link

Feature Request: Call sst commands from JavaScript code as anonymous stacks with $config({}) as input #301

Open vinnichase opened 2 months ago

vinnichase commented 2 months ago

Switching our infrastructure completely to SST Ion and custom Pulumi components we came across some sweet ideas how to leverage the exceptional API of SST Ion.

We need to provision test users in the cloud in order to run our API tests. It would be very nice if I could create an anonymous stack in my test file and deploy and remove the stack after the API test ran.

Example:

let config: Config;
let user: User;

beforeEach(async () => {
    user = {username: 'random', password: 'random'};
    config = $config({
        app(input) {
            return {...};
        },
        async run() {
            new cognito.User('testuser', { UserName: user.username, Password: user.password });
        },
    });
    sst.deploy(config);
});

it('does stuff', () => {
   await expect(api.doStuff(user)).to.haveDoneStuff();
});

afterEach(async () => {
    sst.remove(config);
});

This is a very raw suggestion and not well thought through. Happy to discuss implications.