-
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 support for CDK Custom Resources #190
Conversation
8768959
to
3b3a40a
Compare
3b3a40a
to
e6b7f14
Compare
@@ -203,13 +211,33 @@ export class GraphBuilder { | |||
if (resource.Type === 'AWS::EC2::VPC') { | |||
this.vpcNodes[node.logicalId] = { vpcNode: node, vpcCidrBlockNode: undefined }; | |||
} | |||
} else if (node.construct.constructInfo?.fqn === 'aws-cdk-lib.CfnResource') { |
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.
Previously we were missing resources that were not in the tree.
I noticed this because CDK CustomResources label the CfnCustomResource
with the id Default
. This is a special ID that causes those resources to be ignored in the tree.
We need #186 to validate all resources of the template get mapped.
@@ -116,7 +116,19 @@ export function mapToCfnResource( | |||
const mName = moduleName(typeName).toLowerCase(); | |||
const pType = pulumiTypeName(typeName); | |||
const awsModule = aws as any; | |||
return new awsModule[mName][pType](logicalId, props, options); | |||
|
|||
// Workaround until TODO[pulumi/pulumi-aws-native#1816] is resolved. |
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.
Without this none of the CDK CustomResources I tried deploy successfully. They are all nested too deep for the 64 char limits of Lambda Functions and IAM roles
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.
🚀
assert.NotEmpty(t, url) | ||
|
||
// Validate that the index.html file is deployed | ||
integration.AssertHTTPResultWithRetry(t, url, nil, 60*time.Second, func(body string) bool { |
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.
This is really nice.
stackId: stack.node.id, | ||
bucketName: stagingBucket, | ||
bucketKeyPrefix: `${synth.getDeployTimePrefix()}pulumi/custom-resources/${stackId}/${logicalId}`, | ||
serviceToken: rawProps.ServiceToken, |
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.
Do we need to check that ServiceToken is not undefined?
// WHEN | ||
mapToCustomResource(logicalId, cfnType, cfnProps, {}, stack); | ||
// THEN | ||
expect(aws.cloudformation.CustomResourceEmulator).toHaveBeenCalledWith(logicalId, { |
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.
Hmm ok I see.
This PR has been shipped in release v1.0.0. |
This PR adds support for CloudFormation Custom Resource to pulumi-cdk. It implements does so by using the
CustomResourceEmulator
resource from aws-native.For the first implementation we decided to limit the scope to Lambda backed Custom Resources, because the SNS variants are not widely used.
I'd recommend reviewing in this order:
src/graph.ts
andsrc/converters/app-converter.ts
. The changes in these files ensure that Custom Resources get correctly parsed and other resources can reference their attributes with theGetAtt
intrinsicsrc/cfn-resource-mappings.ts
: This constructs theCustomResourceEmulator
based on the CDK inputs while re-using the staging bucket to store the CustomResource responses.Noteworthy:
I added a temporary workaround for shortening the resource names until pulumi/pulumi-aws-native#1816 is resolved. It can be toggled on by setting the
PULUMI_CDK_EXPERIMENTAL_MAX_NAME_LENGTH
env variable. Without this none of the CustomResources worked because they have deeply nested Lambdas and IAM roles. Those resources have a max name limit of 64.Closes #109
Closes #60