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

creationPolicy type does not support Tokens #1453

Closed
mipearson opened this issue Dec 30, 2018 · 6 comments
Closed

creationPolicy type does not support Tokens #1453

mipearson opened this issue Dec 30, 2018 · 6 comments

Comments

@mipearson
Copy link

Trying to convert the following to CDK-flavoured L2 constructs:

    CreationPolicy:
      ResourceSignal:
        Timeout: !Ref InstanceCreationTimeout
        Count: !Ref MinSize

However, the CDK types do not seem to support using anything other than a number. The following fails typescript compilation:

    autoscaler.options.creationPolicy = {
      resourceSignal: {
        timeout: new cdk.Token(instanceCreationTimeout.ref),
        count: new cdk.Token(minSize.ref)
      }
    };

The resourceSignal type only accepts number and undefined for count, meaning I can't "cheat" and use a stringified nor a raw token.

Note that this is using CDK in its context as a "way to write cloudformation templates" rather than the entire app, so parameters / outputs / conditionals are being used.

@eladb
Copy link
Contributor

eladb commented Dec 30, 2018

@mipearson See #1455 - that's probably a better way to support this. The reason we are trying to avoid union types in the APIs is because they can hardly be translated well to other programming languages.

@mipearson
Copy link
Author

I don't follow - there's lots of bits in the code/types where the type is <string | Token>, can the same not apply here?

Or does that string/Token union type get magically translated to something Java/C# compatible by jsii?

@mipearson
Copy link
Author

(background: I've written a tool to convert a JSON CFN stack to CDK CFN primitives. It nearly works, except for this edge case. Goal is to make it easier for people to convert existing stacks to CDK as they can take the working CDK output and tidy it up / turn it into constructs)

@eladb
Copy link
Contributor

eladb commented Dec 31, 2018

@mipearson only our lower level CFN resources/props use tokens for property types that use primitive values, and those are going away soon as well since now we have a way to represent those tokens using native types (string/string[] and hopefully number soon).

@mipearson
Copy link
Author

mipearson commented Dec 31, 2018

Excellent. I was actually going to close this - I worked out I can work around it by using .resolve() rather than .ref, as that's cast as any. It's cheating, but it silences the compile warnings.

@mipearson
Copy link
Author

I want to point out here that what I was trying to do was based on a lack of understanding of how CDK works, as this issues is referenced as a use case from another.

These values are no longer references in my stack: they're available at compile / synth time.

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

No branches or pull requests

2 participants