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

Cannot pass props to root #26

Open
volkanunsal opened this issue Feb 24, 2021 · 3 comments
Open

Cannot pass props to root #26

volkanunsal opened this issue Feb 24, 2021 · 3 comments

Comments

@volkanunsal
Copy link

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

@fogfish
Copy link
Owner

fogfish commented Feb 24, 2021

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)

@volkanunsal
Copy link
Author

volkanunsal commented Feb 24, 2021

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.

@fogfish
Copy link
Owner

fogfish commented Feb 25, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants