aws-cdk-pure icon indicating copy to clipboard operation
aws-cdk-pure copied to clipboard

Cannot pass props to `root`

Open volkanunsal opened this issue 4 years ago • 3 comments

I need to pass env to the root stack, but I can't because pure.root doesn't take props as an argument.

volkanunsal avatar Feb 24 '21 00:02 volkanunsal

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)

fogfish avatar Feb 24 '21 10:02 fogfish

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.

volkanunsal avatar Feb 24 '21 12:02 volkanunsal

Exactly! The root is not needed at all. I do have same opinion. I think, I just deprecate it.

fogfish avatar Feb 25 '21 11:02 fogfish