aws-cdk-pure
aws-cdk-pure copied to clipboard
Cannot pass props to `root`
I need to pass env
to the root stack, but I can't because pure.root
doesn't take props as an argument.
Thank for raising the issue! Indeed, this is current limitation. In order to overcome this limitation you can use
const app = new cdk.App()
const config = {
env: {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
}
}
const stack = new cdk.Stack(app, 'mystack', { ...config })
pure.join(stack, ...)
What is the right evolution of root
? It requires a consideration, e.g. a new parameter would not make usage of pure.root
easier than new cdk.Stack
.
export function root<T>(scope: App, fn: IaaC<T>, name?: string, props?: cdk.StackProps): App {
fn(new Stack(scope, name || fn.name), props)
return scope
}
Atm I am considering the following construct, however it would introduce incompatible change.
// root is an App
const app = pure.root()
// Stack is just any other construct
const MyStack = (): cdk.StackProps => ...
const stack = pure.iaac(MyStack)
pure.join(app, stack)
The second solution seems simpler. But why do we need root
at all? Isn't it possible to do this:
const app = new cdk.App();
const config = { env };
pure.join(app, cloud.stack(() => config, 'MyApp').effect(MyStack));
So root
doesn't seem to provide much benefit except for initializing the Stack
for you, and that's not too difficult.
Edit: maybe I'm oversimplifying things. Getting the types to work out is probably difficult.
Exactly! The root
is not needed at all. I do have same opinion. I think, I just deprecate it.