-
Notifications
You must be signed in to change notification settings - Fork 221
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
Draft pulumi-cdk 1.0 blog #13434
base: master
Are you sure you want to change the base?
Draft pulumi-cdk 1.0 blog #13434
Conversation
```typescript | ||
import * as pulumicdk from '@pulumi/cdk'; | ||
import * as aws from '@pulumi/aws'; | ||
|
||
const app = new pulumicdk.App('app', (scope: pulumicdk.App): pulumicdk.AppOutputs => { | ||
const stack = new pulumicdk.Stack('example-stack'); | ||
// use getAmiOutput to lookup the AMI instead of ec2.LookupMachineImage | ||
const ami = aws.ec2.getAmiOutput({ | ||
owners: ['amazon'], | ||
mostRecent: true, | ||
filters: [ | ||
{ | ||
name: 'name', | ||
values: ['al2023-ami-2023.*.*.*.*-arm64'], | ||
}, | ||
], | ||
}); | ||
|
||
const region = aws.config.requireRegion(); | ||
const machineImage = ec2.MachineImage.genericLinux({ | ||
[region]: pulumicdk.asString(ami.imageId), | ||
}); | ||
|
||
const instance = new ec2.Instance(this, 'Instance', { | ||
vpc, | ||
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T4G, ec2.InstanceSize.MICRO), | ||
machineImage, | ||
}); | ||
|
||
// Return the public IP of the instance | ||
this.publicIp = this.asOutput(ec2Instance.publicIp); | ||
}); | ||
|
||
// Pulumi's abstraction to create a CloudFront distribution | ||
const distribution = new aws.cloudfront.Distribution("my-cdn-distribution", { | ||
enabled: true, | ||
origins: [{ | ||
originId: ec2Instance.urn, | ||
domainName: ec2PublicIp.apply(ip => `${app.publicIp}.compute-1.amazonaws.com`), // Constructed domain name | ||
customOriginConfig: { | ||
originProtocolPolicy: "http-only", | ||
httpPort: 80, | ||
httpsPort: 80, | ||
originSslProtocols: ["TLSv1.2"], | ||
}, | ||
}], | ||
defaultCacheBehavior: { | ||
targetOriginId: ec2Instance.urn, | ||
viewerProtocolPolicy: "allow-all", | ||
allowedMethods: ["GET", "HEAD", "OPTIONS"], | ||
cachedMethods: ["GET", "HEAD"], | ||
// Define cache behavior settings... | ||
}, | ||
// Additional settings like price class, custom error responses, etc. | ||
// ... | ||
viewerCertificate: { | ||
cloudfrontDefaultCertificate: true, | ||
}, | ||
}); |
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.
@corymhall I would appreciate your sanity check on this I smashed some examples together based on our conversation Friday about the most compelling features from a CDK users perspective, but it probably needs some fixes.
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 a cool one here would be to replace CloudFront
with CloudFlare to highlight the cross cloud ability.
I started working on an example of that, but I don't know if it would be deployable without an existing CloudFlare domain which I'm not sure we have.
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 had intended to use Cloudflare, but was moving quickly and asked the AI the wrong question. We do have an example creating a record on cloudflare so I think we could test with that account+domain: pulumi-cloudflare/examples/record/ts/index.ts at master · pulumi/pulumi-cloudflare
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 created a draft PR with an example. I can't get it to work though so there must be something wrong with the integration (maybe the domain is not public)
```typescript | ||
import * as pulumicdk from '@pulumi/cdk'; | ||
import * as aws from '@pulumi/aws'; | ||
|
||
const app = new pulumicdk.App('app', (scope: pulumicdk.App): pulumicdk.AppOutputs => { | ||
const stack = new pulumicdk.Stack('example-stack'); | ||
// use getAmiOutput to lookup the AMI instead of ec2.LookupMachineImage | ||
const ami = aws.ec2.getAmiOutput({ | ||
owners: ['amazon'], | ||
mostRecent: true, | ||
filters: [ | ||
{ | ||
name: 'name', | ||
values: ['al2023-ami-2023.*.*.*.*-arm64'], | ||
}, | ||
], | ||
}); | ||
|
||
const region = aws.config.requireRegion(); | ||
const machineImage = ec2.MachineImage.genericLinux({ | ||
[region]: pulumicdk.asString(ami.imageId), | ||
}); | ||
|
||
const instance = new ec2.Instance(this, 'Instance', { | ||
vpc, | ||
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T4G, ec2.InstanceSize.MICRO), | ||
machineImage, | ||
}); | ||
|
||
// Return the public IP of the instance | ||
this.publicIp = this.asOutput(ec2Instance.publicIp); | ||
}); | ||
|
||
// Pulumi's abstraction to create a CloudFront distribution | ||
const distribution = new aws.cloudfront.Distribution("my-cdn-distribution", { | ||
enabled: true, | ||
origins: [{ | ||
originId: ec2Instance.urn, | ||
domainName: ec2PublicIp.apply(ip => `${app.publicIp}.compute-1.amazonaws.com`), // Constructed domain name | ||
customOriginConfig: { | ||
originProtocolPolicy: "http-only", | ||
httpPort: 80, | ||
httpsPort: 80, | ||
originSslProtocols: ["TLSv1.2"], | ||
}, | ||
}], | ||
defaultCacheBehavior: { | ||
targetOriginId: ec2Instance.urn, | ||
viewerProtocolPolicy: "allow-all", | ||
allowedMethods: ["GET", "HEAD", "OPTIONS"], | ||
cachedMethods: ["GET", "HEAD"], | ||
// Define cache behavior settings... | ||
}, | ||
// Additional settings like price class, custom error responses, etc. | ||
// ... | ||
viewerCertificate: { | ||
cloudfrontDefaultCertificate: true, | ||
}, | ||
}); |
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 a cool one here would be to replace CloudFront
with CloudFlare to highlight the cross cloud ability.
I started working on an example of that, but I don't know if it would be deployable without an existing CloudFlare domain which I'm not sure we have.
|
||
Currently AWS CDK on Pulumi is supported only for TypeScript users, but we're eager to bring the benefits of the CDK ecosystem to all Pulumi languages in the future. In the meantime, AWS CDK on Pulumi can be used within Component Packages implemented in TypeScript, and exposed to any Pulumi language. | ||
|
||
We're also exploring options for importing state from CDK applications that are already deployed with CloudFormation to enable seamless migration for existing CDK users. Please let us know if this is something you would be interested in in testing with us. |
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 was talking with @t0yv0 and thought it might be cool to publish the tool as experimental alpha so at least we can point users somewhere.
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 would support that. based on who was interested in CDK support, I imagine this migration tool is going to be in high demand
Co-authored-by: Cory Hall <[email protected]>
Co-authored-by: Cory Hall <[email protected]>
Co-authored-by: Eric Rudder <[email protected]>
Your site preview for commit b407d55 is ready! 🎉 http://www-testing-pulumi-docs-origin-pr-13434-b407d552.s3-website.us-west-2.amazonaws.com. |
Announcement blog for Pulumi CDK version 1.0
There are a few TODOs:
Resolves: pulumi/pulumi-cdk#249