Skip to content

Commit

Permalink
feat(core): overrideLogicalId: override IDs of CFN elements (#1670)
Browse files Browse the repository at this point in the history
Allow users to explicitly override the logical ID of a CloudFormation
element (such as "Cfn" resources) by invoking `overrideLogicalId`
on the resource object.

For example:

    const bucket = new s3.CfnBucket(this, 'MyBucket');
    bucket.overrideLogicalId('YourBucket');

The resulting template will use `YourBucket` as the logical ID.

NOTE: the `logicalId` property will now return a stringified token
instead of a concrete value.

Fixes #1594
  • Loading branch information
Elad Ben-Israel authored Feb 6, 2019
1 parent 8da9115 commit 823a1e8
Show file tree
Hide file tree
Showing 48 changed files with 255 additions and 152 deletions.
6 changes: 3 additions & 3 deletions packages/@aws-cdk/app-delivery/test/integ.cicd.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@
]
},
"DependsOn": [
"CodePipelineRoleB3A660B4",
"CodePipelineRoleDefaultPolicy8D520A8D"
"CodePipelineRoleDefaultPolicy8D520A8D",
"CodePipelineRoleB3A660B4"
]
},
"DeployStackChangeSetRole4923A126": {
Expand All @@ -261,4 +261,4 @@
}
}
}
}
}
29 changes: 27 additions & 2 deletions packages/@aws-cdk/assets/test/test.asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export = {
// the correct information
const entry = asset.node.metadata.find(m => m.type === 'aws:cdk:asset');
test.ok(entry, 'found metadata entry');
test.deepEqual(entry!.data, {

// console.error(JSON.stringify(stack.node.resolve(entry!.data)));

test.deepEqual(stack.node.resolve(entry!.data), {
path: dirPath,
id: 'MyAsset',
packaging: 'zip',
Expand All @@ -34,13 +37,35 @@ export = {
test.done();
},

'verify that the app resolves tokens in metadata'(test: Test) {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'my-stack');
const dirPath = path.resolve(__dirname, 'sample-asset-directory');

new ZipDirectoryAsset(stack, 'MyAsset', {
path: dirPath
});

const synth = app.synthesizeStack(stack.name);

test.deepEqual(synth.metadata['/my-stack/MyAsset'][0].data, {
path: dirPath,
id: "mystackMyAssetD6B1B593",
packaging: "zip",
s3BucketParameter: "MyAssetS3Bucket68C9B344",
s3KeyParameter: "MyAssetS3VersionKey68E1A45D"
});

test.done();
},

'"file" assets'(test: Test) {
const stack = new cdk.Stack();
const filePath = path.join(__dirname, 'file-asset.txt');
const asset = new FileAsset(stack, 'MyAsset', { path: filePath });
const entry = asset.node.metadata.find(m => m.type === 'aws:cdk:asset');
test.ok(entry, 'found metadata entry');
test.deepEqual(entry!.data, {
test.deepEqual(stack.node.resolve(entry!.data), {
path: filePath,
packaging: 'file',
id: 'MyAsset',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,12 @@
},
"DependsOn": [
"booksapiANYF4F0CDEB",
"booksapibooks97D84727",
"booksapibooksbookidDELETE214F4059",
"booksapibooksbookidGETCCE21986",
"booksapibooksbookid5264BCA2",
"booksapibooksGETA776447A",
"booksapibooksPOSTF6C6559D",
"booksapibooksbookid5264BCA2",
"booksapibooksbookidDELETE214F4059",
"booksapibooksbookidGETCCE21986"
"booksapibooks97D84727"
]
},
"booksapiDeploymentStageprod55D8E03E": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
"Description": "Automatically created by the RestApi construct"
},
"DependsOn": [
"myapiv113487378",
"myapiv1appliances507FEFF4",
"myapiv1appliancesGET8FE872EC",
"myapiv1books1D4BE6C1",
"myapiv1appliances507FEFF4",
"myapiv1booksGETC6B996D0",
"myapiv1booksPOST53E2832E",
"myapiv1toysA55FCBC4",
"myapiv1books1D4BE6C1",
"myapiv113487378",
"myapiv1toysGET7348114D",
"myapiv1toysPOST55128058",
"myapiv1toysPUT59AFBBC2"
"myapiv1toysPUT59AFBBC2",
"myapiv1toysA55FCBC4"
],
"DeletionPolicy": "Retain"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-apigateway/test/test.restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,12 @@ export = {
// THEN
expect(stack).to(haveResource('My::Resource', {
DependsOn: [
"myapiDeploymentB7EF8EB75c091a668064a3f3a1f6d68a3fb22cf9",
"myapi162F20B8",
"myapiAccountC3A4750C",
"myapiCloudWatchRoleEB425128",
"myapiDeploymentB7EF8EB75c091a668064a3f3a1f6d68a3fb22cf9",
"myapiDeploymentStageprod329F21FF",
"myapiGET9B7CD29E"
"myapiGET9B7CD29E",
"myapi162F20B8"
]
}, ResourcePart.CompleteDefinition));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export = {
// Lifecycle Hook has a dependency on the policy object
expect(stack).to(haveResource('AWS::AutoScaling::LifecycleHook', {
DependsOn: [
"ASGLifecycleHookTransitionRoleDefaultPolicy2E50C7DB",
"ASGLifecycleHookTransitionRole3AAA6BB7",
"ASGLifecycleHookTransitionRoleDefaultPolicy2E50C7DB"
]
}, ResourcePart.CompleteDefinition));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@
"Timeout": 300
},
"DependsOn": [
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17",
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C"
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C",
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17"
]
},
"MyProjectRole9BBE5233": {
Expand Down Expand Up @@ -416,4 +416,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@
"Runtime": "nodejs8.10"
},
"DependsOn": [
"PreHookServiceRoleC724B9BA",
"PreHookServiceRoleDefaultPolicy65358F76"
"PreHookServiceRoleDefaultPolicy65358F76",
"PreHookServiceRoleC724B9BA"
]
},
"PostHookServiceRoleE8A6AAC2": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@
]
},
"DependsOn": [
"PipelineRoleD68726F7",
"PipelineRoleDefaultPolicyC7A05455"
"PipelineRoleDefaultPolicyC7A05455",
"PipelineRoleD68726F7"
]
},
"PipelineDeployPrepareChangesRoleD28C853C": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@
]
},
"DependsOn": [
"PipelineRoleD68726F7",
"PipelineRoleDefaultPolicyC7A05455"
"PipelineRoleDefaultPolicyC7A05455",
"PipelineRoleD68726F7"
]
},
"PipelineEventsRole46BEEA7C": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@
}
},
"DependsOn": [
"PipelineRoleD68726F7",
"PipelineRoleDefaultPolicyC7A05455"
"PipelineRoleDefaultPolicyC7A05455",
"PipelineRoleD68726F7"
]
},
"PipelineBucketB967BD35": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@
]
},
"DependsOn": [
"MyPipelineRoleC0D47CA4",
"MyPipelineRoleDefaultPolicy34F09EFA"
"MyPipelineRoleDefaultPolicy34F09EFA",
"MyPipelineRoleC0D47CA4"
]
},
"CFNDeployRole68D5E8D3": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@
}
},
"DependsOn": [
"MyPipelineRoleC0D47CA4",
"MyPipelineRoleDefaultPolicy34F09EFA"
"MyPipelineRoleDefaultPolicy34F09EFA",
"MyPipelineRoleC0D47CA4"
]
},
"ActionRole60B0EDF7": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@
]
},
"DependsOn": [
"PipelineRoleD68726F7",
"PipelineRoleDefaultPolicyC7A05455"
"PipelineRoleDefaultPolicyC7A05455",
"PipelineRoleD68726F7"
]
},
"PipelineBucketB967BD35": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@
]
},
"DependsOn": [
"PipelineRoleD68726F7",
"PipelineRoleDefaultPolicyC7A05455"
"PipelineRoleDefaultPolicyC7A05455",
"PipelineRoleD68726F7"
]
},
"PipelineEventsRole46BEEA7C": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@
]
},
"DependsOn": [
"PipelineRoleD68726F7",
"PipelineRoleDefaultPolicyC7A05455"
"PipelineRoleDefaultPolicyC7A05455",
"PipelineRoleD68726F7"
]
},
"MyBuildProjectRole6B7E2258": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@
]
},
"DependsOn": [
"PipelineRoleD68726F7",
"PipelineRoleDefaultPolicyC7A05455"
"PipelineRoleDefaultPolicyC7A05455",
"PipelineRoleD68726F7"
]
},
"PipelineEventsRole46BEEA7C": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@
]
},
"DependsOn": [
"PipelineRoleD68726F7",
"PipelineRoleDefaultPolicyC7A05455"
"PipelineRoleDefaultPolicyC7A05455",
"PipelineRoleD68726F7"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@
}
},
"DependsOn": [
"MyPipelineRoleC0D47CA4",
"MyPipelineRoleDefaultPolicy34F09EFA"
"MyPipelineRoleDefaultPolicy34F09EFA",
"MyPipelineRoleC0D47CA4"
]
},
"MyPipelineEventsRoleFAB99F32": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@
]
},
"DependsOn": [
"MyPipelineRoleC0D47CA4",
"MyPipelineRoleDefaultPolicy34F09EFA"
"MyPipelineRoleDefaultPolicy34F09EFA",
"MyPipelineRoleC0D47CA4"
]
},
"MyPipelineOnPipelineStateChangeA017E4B1": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@
]
},
"DependsOn": [
"PipelineRoleD68726F7",
"PipelineRoleDefaultPolicyC7A05455"
"PipelineRoleDefaultPolicyC7A05455",
"PipelineRoleD68726F7"
]
},
"JenkinsProviderJenkinsBuildProviderResourceD9231CAC": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@
}
},
"DependsOn": [
"PipelineRoleD68726F7",
"PipelineRoleDefaultPolicyC7A05455"
"PipelineRoleDefaultPolicyC7A05455",
"PipelineRoleD68726F7"
]
},
"ManualApprovalTopicResource300641E2": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@
}
},
"DependsOn": [
"PipelineRoleD68726F7",
"PipelineRoleDefaultPolicyC7A05455"
"PipelineRoleDefaultPolicyC7A05455",
"PipelineRoleD68726F7"
]
},
"PipelineBucketB967BD35": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@
}
},
"DependsOn": [
"EcsClusterDefaultAutoScalingGroupInstanceRole3C026863",
"EcsClusterDefaultAutoScalingGroupInstanceRoleDefaultPolicy04DC6C80"
"EcsClusterDefaultAutoScalingGroupInstanceRoleDefaultPolicy04DC6C80",
"EcsClusterDefaultAutoScalingGroupInstanceRole3C026863"
]
},
"EcsClusterDefaultAutoScalingGroupASGC1A785DB": {
Expand Down Expand Up @@ -461,8 +461,8 @@
"Timeout": 310
},
"DependsOn": [
"EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRole94543EDA",
"EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRoleDefaultPolicyA45BF396"
"EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRoleDefaultPolicyA45BF396",
"EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRole94543EDA"
]
},
"EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionTopicE6B1EBA6": {
Expand Down Expand Up @@ -538,8 +538,8 @@
}
},
"DependsOn": [
"EcsClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleA38EC83B",
"EcsClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleDefaultPolicy75002F88"
"EcsClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleDefaultPolicy75002F88",
"EcsClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleA38EC83B"
]
},
"TaskDefTaskRole1EDB4A67": {
Expand Down Expand Up @@ -1031,8 +1031,8 @@
"Timeout": 300
},
"DependsOn": [
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17",
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C"
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C",
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17"
]
},
"TaskLoggingLogGroupC7E938D4": {
Expand Down
Loading

0 comments on commit 823a1e8

Please sign in to comment.