-
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
Add experimental flag for enabling CDK lookups #235
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: pulumi-lookups-enabled | ||
runtime: nodejs | ||
description: A minimal TypeScript Pulumi program |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import * as aws from '@pulumi/aws'; | ||
import * as pulumi from '@pulumi/pulumi'; | ||
import * as pulumicdk from '@pulumi/cdk'; | ||
import * as ec2 from 'aws-cdk-lib/aws-ec2'; | ||
import { | ||
aws_elasticloadbalancingv2, | ||
aws_elasticloadbalancingv2_targets, | ||
aws_route53, | ||
aws_route53_targets, | ||
CfnOutput, | ||
} from 'aws-cdk-lib'; | ||
|
||
const config = new pulumi.Config(); | ||
const zoneName = config.require('zoneName'); | ||
const accountId = config.require('accountId'); | ||
const region = aws.config.requireRegion(); | ||
|
||
export class Ec2CdkStack extends pulumicdk.Stack { | ||
constructor(app: pulumicdk.App, id: string) { | ||
super(app, id, { | ||
props: { | ||
env: { region, account: accountId }, | ||
}, | ||
}); | ||
|
||
// Create new VPC with 2 Subnets | ||
const vpc = new ec2.Vpc(this, 'VPC', { | ||
natGateways: 0, | ||
subnetConfiguration: [ | ||
{ | ||
cidrMask: 24, | ||
name: 'asterisk', | ||
subnetType: ec2.SubnetType.PUBLIC, | ||
}, | ||
], | ||
}); | ||
|
||
const machineImage = new ec2.LookupMachineImage({ | ||
name: 'al2023-ami-2023.*.*.*.*-arm64', | ||
owners: ['amazon'], | ||
}); | ||
|
||
const instance = new ec2.Instance(this, 'Instance', { | ||
vpc, | ||
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T4G, ec2.InstanceSize.MICRO), | ||
machineImage, | ||
}); | ||
|
||
const lb = new aws_elasticloadbalancingv2.ApplicationLoadBalancer(this, 'lb', { | ||
vpc, | ||
}); | ||
|
||
const listener = lb.addListener('http', { | ||
protocol: aws_elasticloadbalancingv2.ApplicationProtocol.HTTP, | ||
}); | ||
|
||
listener.addTargets('instance', { | ||
protocol: aws_elasticloadbalancingv2.ApplicationProtocol.HTTP, | ||
targets: [new aws_elasticloadbalancingv2_targets.InstanceTarget(instance)], | ||
}); | ||
|
||
const hostedZone = aws_route53.HostedZone.fromLookup(this, 'hosted-zone', { | ||
domainName: zoneName, | ||
}); | ||
|
||
new aws_route53.AaaaRecord(this, 'record', { | ||
zone: hostedZone, | ||
target: aws_route53.RecordTarget.fromAlias(new aws_route53_targets.LoadBalancerTarget(lb)), | ||
}); | ||
|
||
new CfnOutput(this, 'instanceId', { value: instance.instanceId }); | ||
new CfnOutput(this, 'imageId', { value: machineImage.getImage(this).imageId }); | ||
} | ||
} | ||
|
||
const app = new pulumicdk.App('app', (scope: pulumicdk.App) => { | ||
new Ec2CdkStack(scope, 'teststack'); | ||
}); | ||
|
||
export const imageId = app.outputs['imageId']; | ||
export const instanceId = app.outputs['instanceId']; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"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", | ||
"aws-cdk-lib": "2.156.0", | ||
"constructs": "10.3.0" | ||
} | ||
} |
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" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,16 +148,19 @@ export class App | |
const cli = AwsCdkCli.fromCloudAssemblyDirectoryProducer(this); | ||
this.appProps = props.args?.props; | ||
this.appOptions = props.args; | ||
const lookupsEnabled = process.env.PULUMI_CDK_EXPERIMENTAL_LOOKUPS === 'true'; | ||
const lookups = lookupsEnabled && pulumi.runtime.isDryRun(); | ||
try { | ||
// TODO: support lookups https://github.com/pulumi/pulumi-cdk/issues/184 | ||
await cli.synth({ quiet: true, lookups: false }); | ||
await cli.synth({ quiet: true, lookups }); | ||
} catch (e: any) { | ||
if (typeof e.message === 'string' && e.message.includes('Context lookups have been disabled')) { | ||
const message = e.message as string; | ||
const messageParts = message.split('Context lookups have been disabled. '); | ||
const missingParts = messageParts[1].split('Missing context keys: '); | ||
throw new Error( | ||
'Context lookups have been disabled. Make sure all necessary context is already in "cdk.context.json". \n' + | ||
'Context lookups have been disabled. Make sure all necessary context is already in "cdk.context.json". ' + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would this look like for an app with multiple stacks (or multiple apps) in one repo? Does "cdk.context.json" contain the context for all of them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, thanks! |
||
'Or set "PULUMI_CDK_EXPERIMENTAL_LOOKUPS" to true. \n' + | ||
'Missing context keys: ' + | ||
missingParts[1], | ||
); | ||
|
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 think that's fine assuming we document that folks cannot add pulumi resources in their stacks
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 just pushed a commit here that documents how this would work. Pretty much all apps will have pulumi resources due to the asset stuff.
#234