Skip to content

Commit 515868b

Browse files
author
Elad Ben-Israel
authored
refactor: name "toCloudFormation" internal (renamed to "_toCloudFormation") (#2047)
The method `toCloudFormation` is not supposed to be directly called by users. Mark it as `@internal` and rename to `_toCloudFormation`. Fixes #2044 Related #2016 BREAKING CHANGE: “toCloudFormation” is now internal and should not be called directly. Instead use “app.synthesizeStack”
1 parent 6a671f2 commit 515868b

36 files changed

+128
-124
lines changed

packages/@aws-cdk/assert/lib/expect.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function expect(stack: api.SynthesizedStack | cdk.Stack, skipValidation =
2020

2121
sstack = {
2222
name: stack.name,
23-
template: stack.toCloudFormation(),
23+
template: stack._toCloudFormation(),
2424
metadata: collectStackMetadata(stack.node),
2525
environment: {
2626
name: 'test',
@@ -36,7 +36,7 @@ export function expect(stack: api.SynthesizedStack | cdk.Stack, skipValidation =
3636
}
3737

3838
function isStackClassInstance(x: api.SynthesizedStack | cdk.Stack): x is cdk.Stack {
39-
return 'toCloudFormation' in x;
39+
return '_toCloudFormation' in x;
4040
}
4141

4242
function collectStackMetadata(root: cdk.ConstructNode): api.StackMetadata {

packages/@aws-cdk/assets-docker/test/test.image-asset.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export = {
1818
});
1919

2020
// THEN
21-
const template = stack.toCloudFormation();
21+
const template = stack._toCloudFormation();
2222

2323
test.deepEqual(template.Parameters.ImageImageName5E684353, {
2424
Type: 'String',

packages/@aws-cdk/assets/test/test.asset.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export = {
3030
});
3131

3232
// verify that now the template contains parameters for this asset
33-
const template = stack.toCloudFormation();
33+
const template = stack._toCloudFormation();
3434
test.equal(template.Parameters.MyAssetS3Bucket68C9B344.Type, 'String');
3535
test.equal(template.Parameters.MyAssetS3VersionKey68E1A45D.Type, 'String');
3636

@@ -74,7 +74,7 @@ export = {
7474
});
7575

7676
// verify that now the template contains parameters for this asset
77-
const template = stack.toCloudFormation();
77+
const template = stack._toCloudFormation();
7878
test.equal(template.Parameters.MyAssetS3Bucket68C9B344.Type, 'String');
7979
test.equal(template.Parameters.MyAssetS3VersionKey68E1A45D.Type, 'String');
8080

packages/@aws-cdk/aws-apigateway/test/test.deployment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export = {
153153

154154
function synthesize() {
155155
stack.node.prepareTree();
156-
return stack.toCloudFormation();
156+
return stack._toCloudFormation();
157157
}
158158
},
159159

packages/@aws-cdk/aws-apigateway/test/test.restapi.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export = {
344344

345345
// THEN
346346
stack.node.prepareTree();
347-
test.deepEqual(stack.toCloudFormation().Outputs.MyRestApiRestApiIdB93C5C2D, {
347+
test.deepEqual(stack._toCloudFormation().Outputs.MyRestApiRestApiIdB93C5C2D, {
348348
Value: { Ref: 'MyRestApi2D1F47A9' },
349349
Export: { Name: 'MyRestApiRestApiIdB93C5C2D' }
350350
});

packages/@aws-cdk/aws-applicationautoscaling/test/test.step-scaling-policy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function setupStepScaling(intervals: appscaling.ScalingInterval[]) {
129129
scalingSteps: intervals
130130
});
131131

132-
return new ScalingStackTemplate(stack.toCloudFormation());
132+
return new ScalingStackTemplate(stack._toCloudFormation());
133133
}
134134

135135
class ScalingStackTemplate {

packages/@aws-cdk/aws-cloudtrail/test/test.cloudtrail.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export = {
6666
expect(stack).to(haveResource("AWS::S3::Bucket"));
6767
expect(stack).to(haveResource("AWS::S3::BucketPolicy", ExpectedBucketPolicyProperties));
6868
expect(stack).to(not(haveResource("AWS::Logs::LogGroup")));
69-
const trail: any = stack.toCloudFormation().Resources.MyAmazingCloudTrail54516E8D;
69+
const trail: any = stack._toCloudFormation().Resources.MyAmazingCloudTrail54516E8D;
7070
test.deepEqual(trail.DependsOn, ['MyAmazingCloudTrailS3Policy39C120B0']);
7171
test.done();
7272
},
@@ -97,7 +97,7 @@ export = {
9797
PolicyName: logsRolePolicyName,
9898
Roles: [{ Ref: 'MyAmazingCloudTrailLogsRoleF2CCF977' }],
9999
}));
100-
const trail: any = stack.toCloudFormation().Resources.MyAmazingCloudTrail54516E8D;
100+
const trail: any = stack._toCloudFormation().Resources.MyAmazingCloudTrail54516E8D;
101101
test.deepEqual(trail.DependsOn, [logsRolePolicyName, logsRoleName, 'MyAmazingCloudTrailS3Policy39C120B0']);
102102
test.done();
103103
},
@@ -116,7 +116,7 @@ export = {
116116
expect(stack).to(haveResource("AWS::Logs::LogGroup", {
117117
RetentionInDays: 7
118118
}));
119-
const trail: any = stack.toCloudFormation().Resources.MyAmazingCloudTrail54516E8D;
119+
const trail: any = stack._toCloudFormation().Resources.MyAmazingCloudTrail54516E8D;
120120
test.deepEqual(trail.DependsOn, [logsRolePolicyName, logsRoleName, 'MyAmazingCloudTrailS3Policy39C120B0']);
121121
test.done();
122122
},
@@ -134,7 +134,7 @@ export = {
134134
expect(stack).to(not(haveResource("AWS::Logs::LogGroup")));
135135
expect(stack).to(not(haveResource("AWS::IAM::Role")));
136136

137-
const trail: any = stack.toCloudFormation().Resources.MyAmazingCloudTrail54516E8D;
137+
const trail: any = stack._toCloudFormation().Resources.MyAmazingCloudTrail54516E8D;
138138
test.equals(trail.Properties.EventSelectors.length, 1);
139139
const selector = trail.Properties.EventSelectors[0];
140140
test.equals(selector.ReadWriteType, null, "Expected selector read write type to be undefined");
@@ -160,7 +160,7 @@ export = {
160160
expect(stack).to(not(haveResource("AWS::Logs::LogGroup")));
161161
expect(stack).to(not(haveResource("AWS::IAM::Role")));
162162

163-
const trail: any = stack.toCloudFormation().Resources.MyAmazingCloudTrail54516E8D;
163+
const trail: any = stack._toCloudFormation().Resources.MyAmazingCloudTrail54516E8D;
164164
test.equals(trail.Properties.EventSelectors.length, 1);
165165
const selector = trail.Properties.EventSelectors[0];
166166
test.equals(selector.ReadWriteType, "ReadOnly", "Expected selector read write type to be Read");
@@ -179,7 +179,7 @@ export = {
179179

180180
new CloudTrail(stack, 'MyAmazingCloudTrail', { managementEvents: ReadWriteType.WriteOnly });
181181

182-
const trail: any = stack.toCloudFormation().Resources.MyAmazingCloudTrail54516E8D;
182+
const trail: any = stack._toCloudFormation().Resources.MyAmazingCloudTrail54516E8D;
183183
test.equals(trail.Properties.EventSelectors.length, 1);
184184
const selector = trail.Properties.EventSelectors[0];
185185
test.equals(selector.ReadWriteType, "WriteOnly", "Expected selector read write type to be All");

packages/@aws-cdk/aws-codedeploy/test/server/test.deployment-group.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export = {
355355
});
356356

357357
test.throws(() => {
358-
stack.toCloudFormation();
358+
stack._toCloudFormation();
359359
}, /deploymentInAlarm/);
360360

361361
test.done();

packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export = {
4545
],
4646
});
4747

48-
test.notDeepEqual(stack.toCloudFormation(), {});
48+
test.notDeepEqual(stack._toCloudFormation(), {});
4949
test.deepEqual([], pipeline.node.validateTree());
5050
test.done();
5151
},

packages/@aws-cdk/aws-iam/test/test.role.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ export = {
8787
assumedBy: new ServicePrincipal('sns.amazonaws.com')
8888
});
8989

90-
test.ok(!('MyRoleDefaultPolicyA36BE1DD' in stack.toCloudFormation().Resources), 'initially created without a policy');
90+
test.ok(!('MyRoleDefaultPolicyA36BE1DD' in stack._toCloudFormation().Resources), 'initially created without a policy');
9191

9292
role.addToPolicy(new PolicyStatement().addResource('myresource').addAction('myaction'));
93-
test.ok(stack.toCloudFormation().Resources.MyRoleDefaultPolicyA36BE1DD, 'policy resource created');
93+
test.ok(stack._toCloudFormation().Resources.MyRoleDefaultPolicyA36BE1DD, 'policy resource created');
9494

9595
expect(stack).toMatch({ Resources:
9696
{ MyRoleF48FFE04:

packages/@aws-cdk/aws-s3/test/test.bucket.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ export = {
444444
test.deepEqual(bucket.bucketArn, bucketArn);
445445
test.deepEqual(bucket.node.resolve(bucket.bucketName), 'my-bucket');
446446

447-
test.deepEqual(stack.toCloudFormation(), {}, 'the ref is not a real resource');
447+
test.deepEqual(stack._toCloudFormation(), {}, 'the ref is not a real resource');
448448
test.done();
449449
},
450450

@@ -925,7 +925,7 @@ export = {
925925
bucket.grantWrite(writer);
926926
bucket.grantDelete(deleter);
927927

928-
const resources = stack.toCloudFormation().Resources;
928+
const resources = stack._toCloudFormation().Resources;
929929
const actions = (id: string) => resources[id].Properties.PolicyDocument.Statement[0].Action;
930930

931931
test.deepEqual(actions('WriterDefaultPolicyDC585BCE'), [ 's3:DeleteObject*', 's3:PutObject*', 's3:Abort*' ]);

packages/@aws-cdk/aws-s3/test/test.notifications.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export = {
307307
bucket.onObjectCreated(dest);
308308

309309
stack.node.prepareTree();
310-
test.deepEqual(stack.toCloudFormation().Resources.BucketNotifications8F2E257D, {
310+
test.deepEqual(stack._toCloudFormation().Resources.BucketNotifications8F2E257D, {
311311
Type: 'Custom::S3BucketNotifications',
312312
Properties: {
313313
ServiceToken: { 'Fn::GetAtt': [ 'BucketNotificationsHandler050a0587b7544547bf325f094a3db8347ECC3691', 'Arn' ] },

packages/@aws-cdk/aws-sqs/test/test.sqs.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export = {
107107
test.deepEqual(stack.node.resolve(imports.queueUrl), { 'Fn::ImportValue': 'QueueQueueUrlC30FF916' });
108108

109109
// the exporting stack has Outputs for QueueARN and QueueURL
110-
const outputs = stack.toCloudFormation().Outputs;
110+
const outputs = stack._toCloudFormation().Outputs;
111111
test.deepEqual(outputs.QueueQueueArn8CF496D5, { Value: { 'Fn::GetAtt': [ 'Queue4A7E3555', 'Arn' ] }, Export: { Name: 'QueueQueueArn8CF496D5' } });
112112
test.deepEqual(outputs.QueueQueueUrlC30FF916, { Value: { Ref: 'Queue4A7E3555' }, Export: { Name: 'QueueQueueUrlC30FF916' } });
113113

@@ -252,7 +252,7 @@ export = {
252252
keyArn: { 'Fn::ImportValue': 'QueueWithCustomKeyKeyArn537F6E42' }
253253
});
254254

255-
test.deepEqual(stack.toCloudFormation().Outputs, {
255+
test.deepEqual(stack._toCloudFormation().Outputs, {
256256
"QueueWithCustomKeyQueueArnD326BB9B": {
257257
"Value": {
258258
"Fn::GetAtt": [
@@ -300,7 +300,7 @@ export = {
300300
keyArn: { 'Fn::ImportValue': 'QueueWithManagedKeyKeyArn9C42A85D' }
301301
});
302302

303-
test.deepEqual(stack.toCloudFormation().Outputs, {
303+
test.deepEqual(stack._toCloudFormation().Outputs, {
304304
"QueueWithManagedKeyQueueArn8798A14E": {
305305
"Value": {
306306
"Fn::GetAtt": [
@@ -406,7 +406,7 @@ export = {
406406

407407
// make sure the queue policy is added as a dependency to the bucket
408408
// notifications resource so it will be created first.
409-
test.deepEqual(stack.toCloudFormation().Resources.BucketNotifications8F2E257D.DependsOn, [ 'QueuePolicy25439813' ]);
409+
test.deepEqual(stack._toCloudFormation().Resources.BucketNotifications8F2E257D.DependsOn, [ 'QueuePolicy25439813' ]);
410410

411411
test.done();
412412
},

packages/@aws-cdk/cdk/lib/cfn-condition.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class CfnCondition extends CfnRefElement implements ICfnConditionExpressi
2525
this.expression = props && props.expression;
2626
}
2727

28-
public toCloudFormation(): object {
28+
public _toCloudFormation(): object {
2929
if (!this.expression) {
3030
return { };
3131
}

packages/@aws-cdk/cdk/lib/cfn-element.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export abstract class CfnElement extends Construct {
1717
* @returns The construct as a stack element or undefined if it is not a stack element.
1818
*/
1919
public static isCfnElement(construct: IConstruct): construct is CfnElement {
20-
return ('logicalId' in construct && 'toCloudFormation' in construct);
20+
return ('logicalId' in construct && '_toCloudFormation' in construct);
2121
}
2222

2323
/**
@@ -100,8 +100,10 @@ export abstract class CfnElement extends Construct {
100100
* }
101101
* }
102102
* }
103+
*
104+
* @internal
103105
*/
104-
public abstract toCloudFormation(): object;
106+
public abstract _toCloudFormation(): object;
105107

106108
/**
107109
* Automatically detect references in this CfnElement
@@ -117,7 +119,7 @@ export abstract class CfnElement extends Construct {
117119
// This does make the assumption that the error will not be rectified,
118120
// but the error will be thrown later on anyway. If the error doesn't
119121
// get thrown down the line, we may miss references.
120-
this.node.recordReference(...findTokens(this, () => this.toCloudFormation()));
122+
this.node.recordReference(...findTokens(this, () => this._toCloudFormation()));
121123
} catch (e) {
122124
if (e.type !== 'CfnSynthesisError') { throw e; }
123125
}

packages/@aws-cdk/cdk/lib/cfn-mapping.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class CfnMapping extends CfnRefElement {
4343
return Fn.findInMap(this.logicalId, key1, key2);
4444
}
4545

46-
public toCloudFormation(): object {
46+
public _toCloudFormation(): object {
4747
return {
4848
Mappings: {
4949
[this.logicalId]: this.mapping

packages/@aws-cdk/cdk/lib/cfn-output.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class CfnOutput extends CfnElement {
111111
return fn().importValue(this.obtainExportName());
112112
}
113113

114-
public toCloudFormation(): object {
114+
public _toCloudFormation(): object {
115115
return {
116116
Outputs: {
117117
[this.logicalId]: {

packages/@aws-cdk/cdk/lib/cfn-parameter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class CfnParameter extends CfnRefElement {
104104
this.stringListValue = this.value.toList();
105105
}
106106

107-
public toCloudFormation(): object {
107+
public _toCloudFormation(): object {
108108
return {
109109
Parameters: {
110110
[this.logicalId]: {

packages/@aws-cdk/cdk/lib/cfn-resource.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export class CfnResource extends CfnRefElement {
206206
/**
207207
* Emits CloudFormation for this resource.
208208
*/
209-
public toCloudFormation(): object {
209+
public _toCloudFormation(): object {
210210
try {
211211
// merge property overrides onto properties and then render (and validate).
212212
const tags = CfnResource.isTaggable(this) ? this.tags.renderTags() : undefined;

packages/@aws-cdk/cdk/lib/cfn-rule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class CfnRule extends CfnRefElement {
9292
});
9393
}
9494

95-
public toCloudFormation(): object {
95+
public _toCloudFormation(): object {
9696
return {
9797
Rules: {
9898
[this.logicalId]: {

packages/@aws-cdk/cdk/lib/include.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class Include extends CfnElement {
3131
this.template = props.template;
3232
}
3333

34-
public toCloudFormation() {
34+
public _toCloudFormation() {
3535
return this.template;
3636
}
3737
}

packages/@aws-cdk/cdk/lib/stack.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ export class Stack extends Construct {
143143

144144
/**
145145
* Returns the CloudFormation template for this stack by traversing
146-
* the tree and invoking toCloudFormation() on all Entity objects.
146+
* the tree and invoking _toCloudFormation() on all Entity objects.
147+
*
148+
* @internal
147149
*/
148-
public toCloudFormation() {
150+
public _toCloudFormation() {
149151
// before we begin synthesis, we shall lock this stack, so children cannot be added
150152
this.node.lock();
151153

@@ -158,7 +160,7 @@ export class Stack extends Construct {
158160
};
159161

160162
const elements = cfnElements(this);
161-
const fragments = elements.map(e => this.node.resolve(e.toCloudFormation()));
163+
const fragments = elements.map(e => this.node.resolve(e._toCloudFormation()));
162164

163165
// merge in all CloudFormation fragments collected from the tree
164166
for (const fragment of fragments) {
@@ -446,7 +448,7 @@ export class Stack extends Construct {
446448
const template = `${this.node.id}.template.json`;
447449

448450
// write the CloudFormation template as a JSON file
449-
session.store.writeJson(template, this.toCloudFormation());
451+
session.store.writeJson(template, this._toCloudFormation());
450452

451453
const artifact: cxapi.Artifact = {
452454
type: cxapi.ArtifactType.AwsCloudFormationStack,

packages/@aws-cdk/cdk/test/test.arn.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export = {
219219
new CfnOutput(stack2, 'SomeValue', { value: arn });
220220

221221
// THEN
222-
test.deepEqual(stack2.node.resolve(stack2.toCloudFormation()), {
222+
test.deepEqual(stack2.node.resolve(stack2._toCloudFormation()), {
223223
Outputs: {
224224
SomeValue: {
225225
Value: {

packages/@aws-cdk/cdk/test/test.condition.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export = {
1616
});
1717

1818
// THEN
19-
test.deepEqual(stack.toCloudFormation(), {
19+
test.deepEqual(stack._toCloudFormation(), {
2020
Parameters: { Param1: { Type: 'String' } },
2121
Conditions: {
2222
Condition1: { 'Fn::Equals': [ 'a', 'b' ] },
@@ -45,7 +45,7 @@ export = {
4545

4646
// THEN
4747
test.ok(cdk.unresolved(propValue));
48-
test.deepEqual(stack.toCloudFormation(), {
48+
test.deepEqual(stack._toCloudFormation(), {
4949
Resources: {
5050
MyResource: {
5151
Type: 'AWS::Foo::Bar',

packages/@aws-cdk/cdk/test/test.include.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export = {
77

88
new Include(stack, 'T1', { template: clone(template) });
99

10-
test.deepEqual(stack.toCloudFormation(), {
10+
test.deepEqual(stack._toCloudFormation(), {
1111
Parameters: { MyParam: { Type: 'String', Default: 'Hello' } },
1212
Resources: {
1313
MyResource1: { Type: 'ResourceType1', Properties: { P1: 1, P2: 2 } },
@@ -24,7 +24,7 @@ export = {
2424
new CfnOutput(stack, 'MyOutput', { description: 'Out!', disableExport: true });
2525
new CfnParameter(stack, 'MyParam2', { type: 'Integer' });
2626

27-
test.deepEqual(stack.toCloudFormation(), {
27+
test.deepEqual(stack._toCloudFormation(), {
2828
Parameters: {
2929
MyParam: { Type: 'String', Default: 'Hello' },
3030
MyParam2: { Type: 'Integer' } },
@@ -46,7 +46,7 @@ export = {
4646
new CfnOutput(stack, 'MyOutput', { description: 'Out!' });
4747
new CfnParameter(stack, 'MyParam', { type: 'Integer' }); // duplicate!
4848

49-
test.throws(() => stack.toCloudFormation());
49+
test.throws(() => stack._toCloudFormation());
5050
test.done();
5151
},
5252
};

0 commit comments

Comments
 (0)