-
Notifications
You must be signed in to change notification settings - Fork 5
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
corymhall
wants to merge
2
commits into
main
Choose a base branch
from
corymhall/azs-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: pulumi-aws-cdk-lookups-azs | ||
runtime: nodejs | ||
description: lookup azs example for CDK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as pulumicdk from '@pulumi/cdk'; | ||
import * as pulumi from '@pulumi/pulumi'; | ||
import * as ec2 from 'aws-cdk-lib/aws-ec2'; | ||
import { Fn } from 'aws-cdk-lib'; | ||
import { Output } from '@pulumi/pulumi'; | ||
|
||
const config = new pulumi.Config(); | ||
const prefix = config.get('prefix') ?? pulumi.getStack(); | ||
class LookupAzsStack extends pulumicdk.Stack { | ||
public readonly azs: Output<string[]>; | ||
constructor(app: pulumicdk.App, id: string) { | ||
super(app, id, { | ||
props: { env: app.env }, | ||
}); | ||
|
||
const vpc = new ec2.Vpc(this, 'MyVpc', { maxAzs: 3 }); | ||
this.azs = this.asOutput(vpc.availabilityZones); | ||
} | ||
|
||
// You can override the availabilityZones property to perform a lookup. | ||
// 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[] { | ||
return [Fn.select(0, Fn.getAzs()), Fn.select(1, Fn.getAzs()), Fn.select(2, Fn.getAzs())]; | ||
} | ||
} | ||
|
||
class MyApp extends pulumicdk.App { | ||
constructor() { | ||
super('app', (scope: pulumicdk.App): pulumicdk.AppOutputs => { | ||
const stack = new LookupAzsStack(scope, `${prefix}-azs`); | ||
return { | ||
azs: stack.azs, | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
const app = new MyApp(); | ||
export const azs = app.outputs['azs']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "pulumi-aws-cdk", | ||
"devDependencies": { | ||
"@types/node": "^10.0.0" | ||
}, | ||
"dependencies": { | ||
"@pulumi/aws": "^6.0.0", | ||
"@pulumi/aws-native": "^1.9.0", | ||
"@pulumi/cdk": "^0.5.0", | ||
"@pulumi/docker-build": "^0.0.7", | ||
"@pulumi/pulumi": "^3.0.0", | ||
"@types/express": "^5.0.0", | ||
"aws-cdk-lib": "2.156.0", | ||
"constructs": "10.3.0", | ||
"esbuild": "^0.24.0", | ||
"express": "^4.21.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.