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

feat: add support for the 'Version' resource attribute #10376

Merged
merged 2 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,12 @@ export class CfnInclude extends core.CfnElement {

// fail early for resource attributes we don't support yet
const knownAttributes = [
'Type', 'Properties', 'Condition', 'DependsOn', 'Metadata',
'Type', 'Properties', 'Condition', 'DependsOn', 'Metadata', 'Version',
'CreationPolicy', 'UpdatePolicy', 'DeletionPolicy', 'UpdateReplacePolicy',
];
for (const attribute of Object.keys(resourceAttributes)) {
if (!knownAttributes.includes(attribute)) {
throw new Error(`The ${attribute} resource attribute is not supported by cloudformation-include yet. ` +
throw new Error(`The '${attribute}' resource attribute is not supported by cloudformation-include yet. ` +
'Either remove it from the template, or use the CdkInclude class from the core package instead.');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('CDK Include', () => {
test('throws a validation exception when encountering an unrecognized resource attribute', () => {
expect(() => {
includeTestTemplate(stack, 'non-existent-resource-attribute.json');
}).toThrow(/The NonExistentResourceAttribute resource attribute is not supported by cloudformation-include yet/);
}).toThrow(/The 'NonExistentResourceAttribute' resource attribute is not supported by cloudformation-include yet/);
});

test("throws a validation exception when encountering a Ref-erence to a template element that doesn't exist", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"CustomBucket": {
"Type": "AWS::MyService::Custom",
"Condition": "AlwaysFalseCond",
"Version": "1.0",
"Metadata": {
"Object1": "Value1",
"Object2": "Value2"
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/core/lib/cfn-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export class CfnParser {
cfnOptions.updatePolicy = this.parseUpdatePolicy(resourceAttributes.UpdatePolicy);
cfnOptions.deletionPolicy = this.parseDeletionPolicy(resourceAttributes.DeletionPolicy);
cfnOptions.updateReplacePolicy = this.parseDeletionPolicy(resourceAttributes.UpdateReplacePolicy);
cfnOptions.version = this.parseValue(resourceAttributes.Version);
cfnOptions.metadata = this.parseValue(resourceAttributes.Metadata);

// handle Condition
Expand Down
9 changes: 9 additions & 0 deletions packages/@aws-cdk/core/lib/cfn-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export class CfnResource extends CfnRefElement {
UpdatePolicy: capitalizePropertyNames(this, this.cfnOptions.updatePolicy),
UpdateReplacePolicy: capitalizePropertyNames(this, this.cfnOptions.updateReplacePolicy),
DeletionPolicy: capitalizePropertyNames(this, this.cfnOptions.deletionPolicy),
Version: this.cfnOptions.version,
Metadata: ignoreEmpty(this.cfnOptions.metadata),
Condition: this.cfnOptions.condition && this.cfnOptions.condition.logicalId,
}, props => {
Expand Down Expand Up @@ -429,6 +430,14 @@ export interface ICfnResourceOptions {
*/
updateReplacePolicy?: CfnDeletionPolicy;

/**
* The version of this resource.
* Used only for custom CloudFormation resources.
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html
*/
version?: string;

/**
* Metadata associated with the CloudFormation resource. This is not the same as the construct metadata which can be added
* using construct.addMetadata(), but would not appear in the CloudFormation template automatically.
Expand Down