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

fix(cfn-include): correctly handle the 'AWS::CloudFormation::CustomResource' resource type #10415

Merged
merged 2 commits into from
Sep 21, 2020

Conversation

skinny85
Copy link
Contributor

The resource type 'AWS::CloudFormation::CustomResource' corresponds to the class CfnCustomResource.
However, that class is automatically generated, and quite useless; it only supports one property, ServiceToken.
It does not support passing in an arbitrary collection of properties,
like custom resources in CloudFormation do.
As a result, cfn-include would "lose" all properties of resources of type 'AWS::CloudFormation::CustomResource'
other than ServiceToken.
Fix the problem by handling this resource type with the CfnResource class,
that does support an arbitrary collection of properties.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…source' resource type

The resource type 'AWS::CloudFormation::CustomResource' corresponds to the class CfnCustomResource.
However, that class is automatically generated, and quite useless; it only supports one property, ServiceToken.
It does not support passing in an arbitrary collection of properties,
like custom resources in CloudFormation do.
As a result, cfn-include would "lose" all properties of resources of type 'AWS::CloudFormation::CustomResource'
other than ServiceToken.
Fix the problem by handling this resource type with the CfnResource class,
that does support an arbitrary collection of properties.
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Sep 17, 2020
@skinny85 skinny85 self-assigned this Sep 17, 2020
Comment on lines +600 to +601
// The AWS::CloudFormation::CustomResource type corresponds to the CfnCustomResource class.
// Unfortunately, it's quite useless; it only has a single property, ServiceToken.
Copy link
Contributor

Choose a reason for hiding this comment

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

So one option is what you've done here -- mapping a custom resource to a CfnResource. Would the other be to fix the "useless" CfnCustomResource class? Could we add extensions to that class via the cfnspec additions? If so, it seems like that would solve this issue for more than just this one use case.

Copy link

@DV8FromTheWorld DV8FromTheWorld Sep 18, 2020

Choose a reason for hiding this comment

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

One advantage of this escape hatch to CfnResource is that AWS::CloudFormation::CustomResource is handled the same as Custom::MyCoolResource instead of one being CfnResource and the other being CfnCustomResource.

Indeed it might be better to elaborate the CfnCustomResource interface, but I definitely think it is important to make sure that the 2 Type namings for Custom Resources result in the same construct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, CfnCustomResource is auto-generated, so there's not much we can do there 😕. There's simply not a concept of "accept an arbitrary collection of properties" in the CloudFormation resource specification, and so it can't really be translated to our generated L1s.

We can try to hack something on top of the resource specification (we've done that before, for example in #10316), but I'm not sure it's worth it in this case - like @DV8FromTheWorld said, it's actually more consistent in some sense to always return custom resources, regardless of the resource type they use, as instances of the CfnResource class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You know, maybe I spoke too soon. I see that the resource specification for AWS::CloudFormation::Resource contains an "AdditionalProperties": true field:

    "AWS::CloudFormation::CustomResource": {
      "AdditionalProperties": true,
      "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html",
      "Properties": {
        "ServiceToken": {
          "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html#cfn-customresource-servicetoken",
          "PrimitiveType": "String",
          "Required": true,
          "UpdateType": "Immutable"
        }
      }
    },

Not sure if it's possible to express that easily in TypeScript, but I can investigate.

Let me know what you think @njlynch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the deeper investigation. I think the context I was missing was that we return the other custom resource types as CfnResource as well. For the sake of consistency, I think we can stick with this approach.

@mergify
Copy link
Contributor

mergify bot commented Sep 21, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 2bdde85
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Sep 21, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 1a5a024 into aws:master Sep 21, 2020
@skinny85 skinny85 deleted the fix/cfn-include-custom-cfn-resource branch September 28, 2020 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants