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

chore: add example of looking up availability zones #248

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

corymhall
Copy link
Contributor

If you provide an explicit environment to the stack (there are a lot of
reasons to do this) then you have to enable lookups in order for the
stack to lookup the availability zones.

It would be nice if you could just use Pulumi functions to lookup the
AZs and provide that, but the values have to be strings (can't be
promises/outputs). An easy workaround for this is to use the getAzs
intrinsic to defer the lookup and allow the intrinsic to be converted to
a Pulumi function.

I am adding an example of how to do this. The reason we don't want to do
this by default is that the number of availability zones is not
something that should every change without the user knowing about it.
CDK handles that by having the lookup store the value in the
cdk.context.json file so the lookup is never re-run.

@corymhall
Copy link
Contributor Author

corymhall commented Nov 22, 2024

This change is part of the following stack:

Change managed by git-spice.

// Here I have specified that I want 3 availability zones. This uses Intrinsics, which
// behind the scenes are backed by Pulumi functions (e.g. aws_native.getAzs()).
// This allows us to get around the limitation of not being able to use Output values here.
get availabilityZones(): string[] {
Copy link
Contributor

@flostadler flostadler Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we could achieve CDKs behavior by building a small resource that takes an input property, but then just returns the value from state indefinitely (unless recreated).

Overkill for now, but maybe something for the future if we see this being annoying for users.

Base automatically changed from corymhall/stack-provider to main November 25, 2024 16:31
@corymhall corymhall force-pushed the corymhall/azs-example branch 2 times, most recently from 5230b0d to 6c3c7b8 Compare November 25, 2024 17:23
If you provide an explicit environment to the stack (there are a lot of
reasons to do this) then you have to enable lookups in order for the
stack to lookup the availability zones.

It would be nice if you could just use Pulumi functions to lookup the
AZs and provide that, but the values have to be strings (can't be
promises/outputs). An easy workaround for this is to use the `getAzs`
intrinsic to defer the lookup and allow the intrinsic to be converted to
a Pulumi function.

I am adding an example of how to do this. The reason we don't want to do
this by default is that the number of availability zones is not
something that should every change without the user knowing about it.
CDK handles that by having the lookup store the value in the
`cdk.context.json` file so the lookup is never re-run.
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

Successfully merging this pull request may close these issues.

2 participants