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

[cdk] Allow users to easily consume Pulumi Outputs and Resources within a CDK context without the use of apply #3

Closed
pgavlin opened this issue Apr 11, 2022 · 0 comments · Fixed by #4
Labels
kind/enhancement Improvements or new features resolution/fixed This issue was fixed

Comments

@pgavlin
Copy link
Member

pgavlin commented Apr 11, 2022

In order to provide an easy-to-use experience for the CDK bridge, we need to allow users to easily consume Pulumi Outputs and Resources from within a CDK context without wrapping entire CDK fragments in an apply. I believe that we can do this by authoring an implementation of IResolvable that resolves outputs to some CFN-compatible representation and presenting a user-facing API that allows for the conversion of Outputs to string-encoded CDK tokens. For example, we could offer a method pulumi-cdk.toString(o: Output): string that assigns the output a unique ID, records the mapping in some internal table, creates an appropriate IResolvable, and returns the result of token.asString. The IResolvable could then resolve the encoded token to something like { “Pulumi::Output”: } in the CFN template, which would allow us to map back to the output value itself when interpreting the CFN. I believe that a similar solution would work for resources.

@pgavlin pgavlin added the kind/enhancement Improvements or new features label Apr 11, 2022
@pgavlin pgavlin transferred this issue from another repository Apr 15, 2022
pgavlin added a commit that referenced this issue Apr 15, 2022
Add three adapters that allow pulumi.Output values to be used as inputs
to CDK resources:

- asString, which converts an Output to a string
- asNumber, which converts an Output to a number
- asList, which converts an Output to a string[]

Internally, this works by assigning each Output a unique numerical
identifier and creating an intrinsic Token with the value
`{ Ref: { PulumiOutput: <output id> } }`. The use of `Ref` is required
by the CFN validator, which otherwise errors if e.g. a value like
`{ "Pulumi::Output": <output id> }` is passed where a string is
expected.

There is likely more work to be done in the CFN -> Pulumi translator to
handle outputs embedded in strings, function calls, etc.

These changes also implement support for `DependsOn` in order to ensure
that the appsvc test passes reliably.

Fixes #3.
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements or new features resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants